00001 #ifndef SCT_OMNIMARSHALLING_H 00002 #define SCT_OMNIMARSHALLING_H 00003 00004 #include <list> 00005 #include <string> 00006 #include <vector> 00007 #include <ipc/core.h> 00008 #include "BugReport.h" 00009 00010 namespace Sct { 00011 00020 inline char *copyStringToCorba(const std::string & str) { 00021 char * ans = CORBA::string_dup(str.c_str()); 00022 Sct::BugReport("BUG01","OMNI_MARSHALLING", std::string("OmniMarshalling has converted [")+str+"] into ["+ans+"]"); 00023 return ans; 00024 } 00025 00026 template <typename CorbaSequence, typename ListMember> 00027 inline CorbaSequence *copyListToCorba(const std::list<ListMember> & thisList) { 00028 unsigned size=thisList.size(); 00029 CorbaSequence *result = new CorbaSequence(size); 00030 result->length(size); 00031 00032 unsigned i=0; 00033 for(typename std::list<ListMember>::const_iterator m = thisList.begin(); 00034 m!=thisList.end(); 00035 m++) { 00036 (*result)[i] = *m; 00037 ++i; 00038 } 00039 00040 return result; 00041 } 00042 00043 template <typename CorbaSequence> 00044 inline CorbaSequence *copyStringListToCorba(const std::list<std::string> & thisList) { 00045 unsigned size = thisList.size(); 00046 CorbaSequence *result = new CorbaSequence(size); 00047 result->length(size); 00048 00049 unsigned i=0; 00050 for(std::list<std::string>::const_iterator m = thisList.begin(); 00051 m!=thisList.end(); 00052 m++) { 00053 (*result)[i]=CORBA::string_dup(m->c_str()); 00054 ++i; 00055 } 00056 00057 return result; 00058 } 00059 00060 template <typename CorbaSequence, typename ListMember> 00061 inline std::list<ListMember> copyCorbaToList(const CorbaSequence * const thisSeq) { 00062 std::list<ListMember> result; 00063 00064 if (thisSeq) { 00065 for(unsigned int i=0; i<thisSeq->length(); i++) { 00066 result.push_back( ListMember((*thisSeq)[i]) ); 00067 } 00068 } 00069 return result; 00070 } 00071 00072 00073 template <typename CorbaSequence, typename List> 00074 inline List copyCorbaToStdCollection(const CorbaSequence * thisSeq) { 00075 List result; 00076 00077 if (thisSeq) { 00078 for(unsigned int i=0; i<thisSeq->length(); i++) { 00079 result.push_back((*thisSeq)[i]); 00080 } 00081 } 00082 return result; 00083 } 00084 00085 00086 template <typename CorbaSequence, typename ArrayMember> 00087 inline CorbaSequence *copyArrayToCorba(ArrayMember * const array, const unsigned long length) { 00088 CorbaSequence *result = new CorbaSequence(length); 00089 result->length(length); 00090 00091 if(array) { 00092 for(unsigned long i=0; i<length; i++) { 00093 (*result)[i]=array[i]; 00094 } 00095 } 00096 return result; 00097 } 00098 00099 template <typename CorbaSequence, typename ArrayMember> 00100 inline CorbaSequence *copyVectorToCorba(const std::vector<ArrayMember> & array) { 00101 CorbaSequence *result; 00102 unsigned size = array.size(); 00103 result = new CorbaSequence(size); 00104 result->length(size); 00105 00106 for(unsigned long i=0; i<array.size(); i++) { 00107 (*result)[i]=array[i]; 00108 } 00109 return result; 00110 } 00111 00112 template <typename CorbaMatrix, typename CorbaSequence, typename ArrayMember> 00113 inline CorbaMatrix *copyVectorVectorToCorba(const std::vector<std::vector<ArrayMember> > & matrix) { 00114 unsigned int size = matrix.size(); 00115 CorbaMatrix *result = new CorbaMatrix(size); 00116 result->length(size); 00117 00118 for(unsigned long i=0; i<size; i++) { 00119 unsigned int width=matrix[i].size(); 00120 CorbaSequence *seq = new CorbaSequence(width); 00121 seq->length(width); 00122 for(unsigned long j=0; j<width; j++) { 00123 (*seq)[j] = matrix[i][j]; 00124 } 00125 (*result)[i]=*seq; 00126 } 00127 return result; 00128 } 00129 00130 template <typename CorbaBlock, typename ArrayMember> 00131 inline ArrayMember *copyCorbaToArray(const CorbaBlock & thisSeq, ArrayMember * const array) { 00132 for(unsigned int i=0; i<thisSeq.length(); i++) { 00133 array[i] = thisSeq[i]; 00134 } 00135 return array; 00136 } 00137 00138 } 00139 00140 #endif //SCT_OMNIMARSHALLING_H