OmniMarshalling.h

00001 #ifndef SCT_OMNIMARSHALLING_H
00002 #define SCT_OMNIMARSHALLING_H
00003 
00004 #include <list>
00005 #include <set>
00006 #include <string>
00007 #include <vector>
00008 #include <ipc/core.h>
00009 #include "Sct/BugReport.h"
00010 #include "Sct/Addressing.h"
00011 #include "Sct/Addressing.hh"
00012 
00013 namespace Sct {
00014 
00023 inline Sct::Corba::UPID copyUPIDToCorba(const Sct::UPID & upid) {
00024   Sct::Corba::UPID ret;
00025   ret.partition = upid.partition();
00026   return ret;
00027 };
00028 
00029 inline Sct::Corba::UCID copyUCIDToCorba(const Sct::UCID & ucid) {
00030   Sct::Corba::UCID ret;
00031   ret.partition = ucid.partition();
00032   ret.crate = ucid.crate();
00033   return ret;
00034 };
00035 
00036 inline Sct::Corba::URID copyURIDToCorba(const Sct::URID & urid) {
00037   Sct::Corba::URID ret;
00038   ret.partition = urid.partition();
00039   ret.crate = urid.crate();
00040   ret.rod = urid.rod();
00041   return ret;
00042 };
00043 
00044 inline Sct::UPID copyCorbaToUPID(const Sct::Corba::UPID & upid) {
00045   return Sct::UPID(upid.partition);
00046 };
00047 
00048 inline Sct::UCID copyCorbaToUCID(const Sct::Corba::UCID & ucid) {
00049   return Sct::UCID(ucid.partition, ucid.crate);
00050 };
00051 
00052 inline Sct::URID copyCorbaToURID(const Sct::Corba::URID & urid) {
00053   return Sct::URID(urid.partition, urid.crate, urid.rod);
00054 };
00055 
00056 inline char *copyStringToCorba(const std::string & str) {
00057   char * ans = CORBA::string_dup(str.c_str());
00058   Sct::BugReport("BUG01","OMNI_MARSHALLING", std::string("OmniMarshalling has converted [")+str+"] into ["+ans+"]");
00059   return ans;
00060 }
00061 
00062 template <typename CorbaSequence, typename ListMember>
00063 inline CorbaSequence *copyListToCorba(const std::list<ListMember> & thisList) {
00064   unsigned size=thisList.size();
00065   CorbaSequence *result = new CorbaSequence(size);
00066   result->length(size);
00067   
00068   unsigned i=0;
00069   for(typename std::list<ListMember>::const_iterator m = thisList.begin();
00070       m!=thisList.end();
00071       m++) {
00072     (*result)[i] = *m;
00073     ++i;
00074   }
00075 
00076   return result;
00077 }
00078 
00079 template <typename CorbaSequence>
00080 inline CorbaSequence *copyStringListToCorba(const std::list<std::string> & thisList) {
00081   unsigned size = thisList.size();
00082   CorbaSequence *result = new CorbaSequence(size);
00083   result->length(size);
00084  
00085   unsigned i=0;
00086   for(std::list<std::string>::const_iterator m = thisList.begin();
00087       m!=thisList.end();
00088       m++) {
00089     (*result)[i]=CORBA::string_dup(m->c_str());
00090     ++i;
00091   }
00092 
00093   return result;
00094 }
00095 
00096 template <typename CorbaSequence>
00097 inline CorbaSequence *copyStringSetToCorba(const std::set<std::string> & thisSet) {
00098   unsigned size = thisSet.size();
00099   CorbaSequence *result = new CorbaSequence(size);
00100   result->length(size);
00101  
00102   unsigned i=0;
00103   for(std::set<std::string>::const_iterator m = thisSet.begin();
00104       m!=thisSet.end();
00105       m++) {
00106     (*result)[i]=CORBA::string_dup(m->c_str());
00107     ++i;
00108   }
00109 
00110   return result;
00111 }
00112 
00113 template <typename CorbaSequence, typename ListMember>
00114 inline std::list<ListMember> copyCorbaToList(const CorbaSequence * const thisSeq) {
00115   std::list<ListMember> result;
00116 
00117   if (thisSeq) {
00118       for(unsigned int i=0; i<thisSeq->length(); i++) {
00119       result.push_back( ListMember((*thisSeq)[i]) );
00120       }
00121   }
00122   return result;
00123 }
00124 
00125 
00126 template <typename CorbaSequence, typename List>
00127 inline List copyCorbaToStdCollection(const CorbaSequence * thisSeq) { 
00128   List result;
00129 
00130   if (thisSeq) {
00131       for(unsigned int i=0; i<thisSeq->length(); i++) {
00132           result.push_back((*thisSeq)[i]);
00133       }
00134   }
00135   return result;
00136 }
00137 
00138 
00139 template <typename CorbaSequence, typename ArrayMember>
00140 inline CorbaSequence *copyArrayToCorba(ArrayMember * const array, const unsigned long length) {
00141   CorbaSequence *result = new CorbaSequence(length);
00142   result->length(length);
00143 
00144   if(array) {
00145     for(unsigned long i=0; i<length; i++) {
00146       (*result)[i]=array[i];
00147     }
00148   }
00149   return result;
00150 }
00151  
00152 template <typename CorbaSequence, typename ArrayMember>
00153 inline CorbaSequence *copyVectorToCorba(const std::vector<ArrayMember> & array) {
00154   CorbaSequence *result;
00155   unsigned size = array.size();
00156   result = new CorbaSequence(size);
00157   result->length(size);
00158 
00159   for(unsigned long i=0; i<array.size(); i++) {
00160     (*result)[i]=array[i];
00161   }
00162   return result;
00163 }
00164 
00165 template <typename CorbaMatrix, typename CorbaSequence, typename ArrayMember>
00166 inline CorbaMatrix *copyVectorVectorToCorba(const std::vector<std::vector<ArrayMember> > & matrix) {
00167   unsigned int size = matrix.size();
00168   CorbaMatrix *result = new CorbaMatrix(size);
00169   result->length(size);
00170 
00171   for(unsigned long i=0; i<size; i++) {
00172     unsigned int width=matrix[i].size();
00173     CorbaSequence *seq = new CorbaSequence(width);
00174     seq->length(width);
00175     for(unsigned long j=0; j<width; j++) {
00176       (*seq)[j] = matrix[i][j];
00177     }
00178     (*result)[i]=*seq;
00179   }
00180   return result;
00181 }
00182 
00183 template <typename CorbaBlock, typename ArrayMember>
00184 inline ArrayMember *copyCorbaToArray(const CorbaBlock & thisSeq, ArrayMember * const array) {
00185   for(unsigned int i=0; i<thisSeq.length(); i++) {
00186     array[i] = thisSeq[i];
00187   }
00188   return array;
00189 }
00190 
00191 }
00192 
00193 #endif //SCT_OMNIMARSHALLING_H

Generated on Mon Feb 6 14:01:24 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6