FastCdr.h 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756
  1. // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef _FASTCDR_FASTCDR_H_
  15. #define _FASTCDR_FASTCDR_H_
  16. #include "fastcdr_dll.h"
  17. #include "FastBuffer.h"
  18. #include "exceptions/NotEnoughMemoryException.h"
  19. #include <stdint.h>
  20. #include <string>
  21. #include <vector>
  22. #if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__
  23. #include <malloc.h>
  24. #else
  25. #include <stdlib.h>
  26. #endif
  27. #if HAVE_CXX0X
  28. #include <array>
  29. #endif
  30. namespace eprosima
  31. {
  32. namespace fastcdr
  33. {
  34. /*!
  35. * @brief This class offers an interface to serialize/deserialize some basic types using a modified CDR protocol inside a eprosima::FastBuffer.
  36. * This modified CDR protocol provides a serialization mechanism much faster than common CDR protocol, because it doesn't use alignment.
  37. * @ingroup FASTCDRAPIREFERENCE
  38. */
  39. class Cdr_DllAPI FastCdr
  40. {
  41. public:
  42. /*!
  43. * @brief This class stores the current state of a CDR serialization.
  44. */
  45. class Cdr_DllAPI state
  46. {
  47. friend class FastCdr;
  48. public:
  49. /*!
  50. * @brief Default constructor.
  51. */
  52. state(const FastCdr &fastcdr);
  53. /*!
  54. * @brief Copy constructor.
  55. */
  56. state(const state&);
  57. private:
  58. state& operator=(const state&) = delete;
  59. //! @brief The position in the buffer when the state was created.
  60. const FastBuffer::iterator m_currentPosition;
  61. };
  62. /*!
  63. * @brief This constructor creates a eprosima::fastcdr::FastCdr object that can serialize/deserialize
  64. * the assigned buffer.
  65. *
  66. * @param cdrBuffer A reference to the buffer that contains (or will contain) the CDR representation.
  67. */
  68. FastCdr(FastBuffer &cdrBuffer);
  69. /*!
  70. * @brief This function skips a number of bytes in the CDR stream buffer.
  71. * @param numBytes The number of bytes that will be jumped.
  72. * @return True is returned when the jump operation works successfully. Otherwise, false is returned.
  73. */
  74. bool jump(size_t numBytes);
  75. /*!
  76. * @brief This function resets the current position in the buffer to the begining.
  77. */
  78. void reset();
  79. /*!
  80. * @brief This function returns the current position in the CDR stream.
  81. * @return Pointer to the current position in the buffer.
  82. */
  83. char* getCurrentPosition();
  84. /*!
  85. * @brief This function returns the length of the serialized data inside the stream.
  86. * @return The length of the serialized data.
  87. */
  88. inline size_t getSerializedDataLength() const { return m_currentPosition - m_cdrBuffer.begin();}
  89. /*!
  90. * @brief This function returns the current state of the CDR stream.
  91. * @return The current state of the buffer.
  92. */
  93. FastCdr::state getState();
  94. /*!
  95. * @brief This function sets a previous state of the CDR stream;
  96. * @param state Previous state that will be set again.
  97. */
  98. void setState(FastCdr::state &state);
  99. /*!
  100. * @brief This operator serializes an octet.
  101. * @param octet_t The value of the octet that will be serialized in the buffer.
  102. * @return Reference to the eprosima::fastcdr::FastCdr object.
  103. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  104. */
  105. inline FastCdr& operator<<(const uint8_t octet_t){return serialize(octet_t);}
  106. /*!
  107. * @brief This operator serializes a character.
  108. * @param char_t The value of the character that will be serialized in the buffer.
  109. * @return Reference to the eprosima::fastcdr::FastCdr object.
  110. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  111. */
  112. inline FastCdr& operator<<(const char char_t){return serialize(char_t);}
  113. /*!
  114. * @brief This operator serializes a int8_t.
  115. * @param int8 The value of the int8_t that will be serialized in the buffer.
  116. * @return Reference to the eprosima::fastcdr::FastCdr object.
  117. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  118. */
  119. inline FastCdr& operator<<(const int8_t int8){return serialize(int8);}
  120. /*!
  121. * @brief This operator serializes an unsigned short.
  122. * @param ushort_t The value of the unsigned short that will be serialized in the buffer.
  123. * @return Reference to the eprosima::fastcdr::FastCdr object.
  124. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  125. */
  126. inline FastCdr& operator<<(const uint16_t ushort_t){return serialize(ushort_t);}
  127. /*!
  128. * @brief This operator serializes a short.
  129. * @param short_t The value of the short that will be serialized in the buffer.
  130. * @return Reference to the eprosima::fastcdr::FastCdr object.
  131. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  132. */
  133. inline FastCdr& operator<<(const int16_t short_t){return serialize(short_t);}
  134. /*!
  135. * @brief This operator serializes an unsigned long.
  136. * @param ulong_t The value of the unsigned long that will be serialized in the buffer.
  137. * @return Reference to the eprosima::fastcdr::FastCdr object.
  138. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  139. */
  140. inline FastCdr& operator<<(const uint32_t ulong_t){return serialize(ulong_t);}
  141. /*!
  142. * @brief This operator serializes a long.
  143. * @param long_t The value of the long that will be serialized in the buffer.
  144. * @return Reference to the eprosima::fastcdr::FastCdr object.
  145. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  146. */
  147. inline FastCdr& operator<<(const int32_t long_t){return serialize(long_t);}
  148. /*!
  149. * @brief This operator serializes a wide-char.
  150. * @param wchar The value of the wide-char that will be serialized in the buffer.
  151. * @return Reference to the eprosima::fastcdr::FastCdr object.
  152. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  153. */
  154. inline FastCdr& operator<<(const wchar_t wchar){return serialize(wchar);}
  155. /*!
  156. * @brief This operator serializes an unsigned long long.
  157. * @param ulonglong_t The value of the unsigned long long that will be serialized in the buffer.
  158. * @return Reference to the eprosima::fastcdr::FastCdr object.
  159. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  160. */
  161. inline FastCdr& operator<<(const uint64_t ulonglong_t){return serialize(ulonglong_t);}
  162. /*!
  163. * @brief This operator serializes a long long.
  164. * @param longlong_t The value of the long long that will be serialized in the buffer.
  165. * @return Reference to the eprosima::fastcdr::FastCdr object.
  166. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  167. */
  168. inline FastCdr& operator<<(const int64_t longlong_t){return serialize(longlong_t);}
  169. /*!
  170. * @brief This operator serializes a float.
  171. * @param float_t The value of the float that will be serialized in the buffer.
  172. * @return Reference to the eprosima::fastcdr::FastCdr object.
  173. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  174. */
  175. inline FastCdr& operator<<(const float float_t){return serialize(float_t);}
  176. /*!
  177. * @brief This operator serializes a ldouble.
  178. * @param double_t The value of the double that will be serialized in the buffer.
  179. * @return Reference to the eprosima::fastcdr::FastCdr object.
  180. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  181. */
  182. inline FastCdr& operator<<(const double double_t){return serialize(double_t);}
  183. /*!
  184. * @brief This operator serializes a long double.
  185. * @param ldouble_t The value of the long double that will be serialized in the buffer.
  186. * @return Reference to the eprosima::fastcdr::FastCdr object.
  187. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  188. */
  189. inline FastCdr& operator<<(const long double ldouble_t){return serialize(ldouble_t);}
  190. /*!
  191. * @brief This operator serializes a boolean.
  192. * @param bool_t The value of the boolean that will be serialized in the buffer.
  193. * @return Reference to the eprosima::fastcdr::FastCdr object.
  194. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  195. */
  196. inline FastCdr& operator<<(const bool bool_t){return serialize(bool_t);}
  197. /*!
  198. * @brief This operator serializes a null-terminated string.
  199. * @param string_t The value of the string that will be serialized in the buffer.
  200. * @return Reference to the eprosima::fastcdr::FastCdr object.
  201. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  202. */
  203. inline FastCdr& operator<<(const char *string_t){return serialize(string_t);}
  204. /*!
  205. * @brief This operator serializes a null-terminated wide-string.
  206. * @param string_t The value of the wide-string that will be serialized in the buffer.
  207. * @return Reference to the eprosima::fastcdr::FastCdr object.
  208. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  209. */
  210. inline FastCdr& operator<<(const wchar_t *string_t){return serialize(string_t);}
  211. /*!
  212. * @brief This operator serializes a string.
  213. * @param string_t The string that will be serialized in the buffer.
  214. * @return Reference to the eprosima::fastcdr::FastCdr object.
  215. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  216. */
  217. inline FastCdr& operator<<(const std::string &string_t){return serialize(string_t);}
  218. /*!
  219. * @brief This operator serializes a wstring.
  220. * @param string_t The wstring that will be serialized in the buffer.
  221. * @return Reference to the eprosima::fastcdr::FastCdr object.
  222. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  223. */
  224. inline FastCdr& operator<<(const std::wstring &string_t){return serialize(string_t);}
  225. #if HAVE_CXX0X
  226. /*!
  227. * @brief This operator template is used to serialize arrays.
  228. * @param array_t The array that will be serialized in the buffer.
  229. * @return Reference to the eprosima::fastcdr::FastCdr object.
  230. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  231. */
  232. template<class _T, size_t _Size>
  233. inline FastCdr& operator<<(const std::array<_T, _Size> &array_t){return serialize<_T, _Size>(array_t);}
  234. #endif
  235. /*!
  236. * @brief This operator template is used to serialize sequences.
  237. * @param vector_t The sequence that will be serialized in the buffer.
  238. * @return Reference to the eprosima::fastcdr::FastCdr object.
  239. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  240. */
  241. template<class _T>
  242. inline FastCdr& operator<<(const std::vector<_T> &vector_t){return serialize<_T>(vector_t);}
  243. /*!
  244. * @brief This operator template is used to serialize non-basic types.
  245. * @param type_t The object that will be serialized in the buffer.
  246. * @return Reference to the eprosima::fastcdr::FastCdr object.
  247. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  248. */
  249. template<class _T>
  250. inline FastCdr& operator<<(const _T &type_t)
  251. {
  252. type_t.serialize(*this);
  253. return *this;
  254. }
  255. /*!
  256. * @brief This operator deserializes an octet.
  257. * @param octet_t The variable that will store the octet read from the buffer.
  258. * @return Reference to the eprosima::fastcdr::FastCdr object.
  259. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  260. */
  261. inline FastCdr& operator>>(uint8_t &octet_t){return deserialize(octet_t);}
  262. /*!
  263. * @brief This operator deserializes a character.
  264. * @param char_t The variable that will store the character read from the buffer.
  265. * @return Reference to the eprosima::fastcdr::FastCdr object.
  266. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  267. */
  268. inline FastCdr& operator>>(char &char_t){return deserialize(char_t);}
  269. /*!
  270. * @brief This operator deserializes an int8_t.
  271. * @param int8 The variable that will store the int8_t read from the buffer.
  272. * @return Reference to the eprosima::fastcdr::FastCdr object.
  273. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  274. */
  275. inline FastCdr& operator>>(int8_t &int8){return deserialize(int8);}
  276. /*!
  277. * @brief This operator deserializes an unsigned short.
  278. * @param ushort_t The variable that will store the unsigned short read from the buffer.
  279. * @return Reference to the eprosima::fastcdr::FastCdr object.
  280. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  281. */
  282. inline FastCdr& operator>>(uint16_t &ushort_t){return deserialize(ushort_t);}
  283. /*!
  284. * @brief This operator deserializes a short.
  285. * @param short_t The variable that will store the short read from the buffer.
  286. * @return Reference to the eprosima::fastcdr::FastCdr object.
  287. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  288. */
  289. inline FastCdr& operator>>(int16_t &short_t){return deserialize(short_t);}
  290. /*!
  291. * @brief This operator deserializes an unsigned long.
  292. * @param ulong_t The variable that will store the unsigned long read from the buffer.
  293. * @return Reference to the eprosima::fastcdr::FastCdr object.
  294. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  295. */
  296. inline FastCdr& operator>>(uint32_t &ulong_t){return deserialize(ulong_t);}
  297. /*!
  298. * @brief This operator deserializes a long.
  299. * @param long_t The variable that will store the long read from the buffer.
  300. * @return Reference to the eprosima::fastcdr::FastCdr object.
  301. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  302. */
  303. inline FastCdr& operator>>(int32_t &long_t){return deserialize(long_t);}
  304. /*!
  305. * @brief This operator deserializes a wide-char.
  306. * @param wchar The variable that will store the wide-char read from the buffer.
  307. * @return Reference to the eprosima::fastcdr::FastCdr object.
  308. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  309. */
  310. inline FastCdr& operator>>(wchar_t &wchar){return deserialize(wchar);}
  311. /*!
  312. * @brief This operator deserializes an unsigned long long.
  313. * @param ulonglong_t The variable that will store the unsigned long long read from the buffer.
  314. * @return Reference to the eprosima::fastcdr::FastCdr object.
  315. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  316. */
  317. inline FastCdr& operator>>(uint64_t &ulonglong_t){return deserialize(ulonglong_t);}
  318. /*!
  319. * @brief This operator deserializes a long long.
  320. * @param longlong_t The variable that will store the long long read from the buffer.
  321. * @return Reference to the eprosima::fastcdr::FastCdr object.
  322. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  323. */
  324. inline FastCdr& operator>>(int64_t &longlong_t){return deserialize(longlong_t);}
  325. /*!
  326. * @brief This operator deserializes a float.
  327. * @param float_t The variable that will store the float read from the buffer.
  328. * @return Reference to the eprosima::fastcdr::FastCdr object.
  329. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  330. */
  331. inline FastCdr& operator>>(float &float_t){return deserialize(float_t);}
  332. /*!
  333. * @brief This operator deserializes a double.
  334. * @param double_t The variable that will store the double read from the buffer.
  335. * @return Reference to the eprosima::fastcdr::FastCdr object.
  336. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  337. */
  338. inline FastCdr& operator>>(double &double_t){return deserialize(double_t);}
  339. /*!
  340. * @brief This operator deserializes a long double.
  341. * @param ldouble_t The variable that will store the long double read from the buffer.
  342. * @return Reference to the eprosima::fastcdr::FastCdr object.
  343. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  344. */
  345. inline FastCdr& operator>>(long double &ldouble_t){return deserialize(ldouble_t);}
  346. /*!
  347. * @brief This operator deserializes a boolean.
  348. * @param bool_t The variable that will store the boolean read from the buffer.
  349. * @return Reference to the eprosima::fastcdr::FastCdr object.
  350. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  351. * @exception exception::BadParamException This exception is thrown when trying to deserialize in an invalid value.
  352. */
  353. inline FastCdr& operator>>(bool &bool_t){return deserialize(bool_t);}
  354. /*!
  355. * @brief This operator deserializes a null-terminated c-string.
  356. * @param string_t The variable that will store the c-string read from the buffer.
  357. * Please note that a newly allocated string will be returned.
  358. * The caller should free the returned pointer when appropiate.
  359. * @return Reference to the eprosima::fastcdr::FastCdr object.
  360. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
  361. * @exception exception::BadParamException This exception is thrown when trying to deserialize an invalid value.
  362. */
  363. inline FastCdr& operator>>(char *&string_t){return deserialize(string_t);}
  364. /*!
  365. * @brief This operator deserializes a string.
  366. * @param string_t The variable that will store the string read from the buffer.
  367. * @return Reference to the eprosima::fastcdr::FastCdr object.
  368. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  369. */
  370. inline FastCdr& operator>>(std::string &string_t){return deserialize(string_t);}
  371. /*!
  372. * @brief This operator deserializes a wstring.
  373. * @param string_t The variable that will store the wstring read from the buffer.
  374. * @return Reference to the eprosima::fastcdr::FastCdr object.
  375. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  376. */
  377. inline FastCdr& operator>>(std::wstring &string_t){return deserialize(string_t);}
  378. #if HAVE_CXX0X
  379. /*!
  380. * @brief This operator template is used to deserialize arrays.
  381. * @param array_t The variable that will store the array read from the buffer.
  382. * @return Reference to the eprosima::fastcdr::FastCdr object.
  383. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  384. */
  385. template<class _T, size_t _Size>
  386. inline FastCdr& operator>>(std::array<_T, _Size> &array_t){return deserialize<_T, _Size>(array_t);}
  387. #endif
  388. /*!
  389. * @brief This operator template is used to deserialize sequences.
  390. * @param vector_t The variable that will store the sequence read from the buffer.
  391. * @return Reference to the eprosima::fastcdr::FastCdr object.
  392. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  393. */
  394. template<class _T>
  395. inline FastCdr& operator>>(std::vector<_T> &vector_t){return deserialize<_T>(vector_t);}
  396. /*!
  397. * @brief This operator template is used to deserialize non-basic types.
  398. * @param type_t The variable that will store the object read from the buffer.
  399. * @return Reference to the eprosima::fastcdr::FastCdr object.
  400. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  401. */
  402. template<class _T>
  403. inline FastCdr& operator>>(_T &type_t)
  404. {
  405. type_t.deserialize(*this);
  406. return *this;
  407. }
  408. /*!
  409. * @brief This function serializes an octet.
  410. * @param octet_t The value of the octet that will be serialized in the buffer.
  411. * @return Reference to the eprosima::fastcdr::FastCdr object.
  412. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  413. */
  414. inline
  415. FastCdr& serialize(const uint8_t octet_t)
  416. {
  417. return serialize(static_cast<char>(octet_t));
  418. }
  419. /*!
  420. * @brief This function serializes a character.
  421. * @param char_t The value of the character that will be serialized in the buffer.
  422. * @return Reference to the eprosima::fastcdr::FastCdr object.
  423. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  424. */
  425. inline
  426. FastCdr& serialize(const char char_t)
  427. {
  428. if(((m_lastPosition - m_currentPosition) >= sizeof(char_t)) || resize(sizeof(char_t)))
  429. {
  430. m_currentPosition++ << char_t;
  431. return *this;
  432. }
  433. throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
  434. }
  435. /*!
  436. * @brief This function serializes an int8_t.
  437. * @param int8 The value of the int8_t that will be serialized in the buffer.
  438. * @return Reference to the eprosima::fastcdr::FastCdr object.
  439. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  440. */
  441. inline
  442. FastCdr& serialize(const int8_t int8)
  443. {
  444. return serialize(static_cast<char>(int8));
  445. }
  446. /*!
  447. * @brief This function serializes an unsigned short.
  448. * @param ushort_t The value of the unsigned short that will be serialized in the buffer.
  449. * @return Reference to the eprosima::fastcdr::FastCdr object.
  450. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  451. */
  452. inline
  453. FastCdr& serialize(const uint16_t ushort_t)
  454. {
  455. return serialize(static_cast<int16_t>(ushort_t));
  456. }
  457. /*!
  458. * @brief This function serializes a short.
  459. * @param short_t The value of the short that will be serialized in the buffer.
  460. * @return Reference to the eprosima::fastcdr::FastCdr object.
  461. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  462. */
  463. inline
  464. FastCdr& serialize(const int16_t short_t)
  465. {
  466. if(((m_lastPosition - m_currentPosition) >= sizeof(short_t)) || resize(sizeof(short_t)))
  467. {
  468. m_currentPosition << short_t;
  469. m_currentPosition += sizeof(short_t);
  470. return *this;
  471. }
  472. throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
  473. }
  474. /*!
  475. * @brief This function serializes an unsigned long.
  476. * @param ulong_t The value of the unsigned long that will be serialized in the buffer.
  477. * @return Reference to the eprosima::fastcdr::FastCdr object.
  478. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  479. */
  480. inline
  481. FastCdr& serialize(const uint32_t ulong_t)
  482. {
  483. return serialize(static_cast<int32_t>(ulong_t));
  484. }
  485. /*!
  486. * @brief This function serializes a long.
  487. * @param long_t The value of the long that will be serialized in the buffer.
  488. * @return Reference to the eprosima::fastcdr::FastCdr object.
  489. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  490. */
  491. inline
  492. FastCdr& serialize(const int32_t long_t)
  493. {
  494. if(((m_lastPosition - m_currentPosition) >= sizeof(long_t)) || resize(sizeof(long_t)))
  495. {
  496. m_currentPosition << long_t;
  497. m_currentPosition += sizeof(long_t);
  498. return *this;
  499. }
  500. throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
  501. }
  502. /*!
  503. * @brief This function serializes a wide-char.
  504. * @param wchar The value of the wide-char that will be serialized in the buffer.
  505. * @return Reference to the eprosima::fastcdr::FastCdr object.
  506. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  507. */
  508. inline
  509. FastCdr& serialize(const wchar_t wchar)
  510. {
  511. return serialize(static_cast<uint32_t>(wchar));
  512. }
  513. /*!
  514. * @brief This function serializes an unsigned long long.
  515. * @param ulonglong_t The value of the unsigned long long that will be serialized in the buffer.
  516. * @return Reference to the eprosima::fastcdr::FastCdr object.
  517. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  518. */
  519. inline
  520. FastCdr& serialize(const uint64_t ulonglong_t)
  521. {
  522. return serialize(static_cast<int64_t>(ulonglong_t));
  523. }
  524. /*!
  525. * @brief This function serializes a long long.
  526. * @param longlong_t The value of the long long that will be serialized in the buffer.
  527. * @return Reference to the eprosima::fastcdr::FastCdr object.
  528. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  529. */
  530. inline
  531. FastCdr& serialize(const int64_t longlong_t)
  532. {
  533. if(((m_lastPosition - m_currentPosition) >= sizeof(longlong_t)) || resize(sizeof(longlong_t)))
  534. {
  535. m_currentPosition << longlong_t;
  536. m_currentPosition += sizeof(longlong_t);
  537. return *this;
  538. }
  539. throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
  540. }
  541. /*!
  542. * @brief This function serializes a float.
  543. * @param float_t The value of the float that will be serialized in the buffer.
  544. * @return Reference to the eprosima::fastcdr::FastCdr object.
  545. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  546. */
  547. inline
  548. FastCdr& serialize(const float float_t)
  549. {
  550. if(((m_lastPosition - m_currentPosition) >= sizeof(float_t)) || resize(sizeof(float_t)))
  551. {
  552. m_currentPosition << float_t;
  553. m_currentPosition += sizeof(float_t);
  554. return *this;
  555. }
  556. throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
  557. }
  558. /*!
  559. * @brief This function serializes a double.
  560. * @param double_t The value of the double that will be serialized in the buffer.
  561. * @return Reference to the eprosima::fastcdr::FastCdr object.
  562. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  563. */
  564. inline
  565. FastCdr& serialize(const double double_t)
  566. {
  567. if(((m_lastPosition - m_currentPosition) >= sizeof(double_t)) || resize(sizeof(double_t)))
  568. {
  569. m_currentPosition << double_t;
  570. m_currentPosition += sizeof(double_t);
  571. return *this;
  572. }
  573. throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
  574. }
  575. /*!
  576. * @brief This function serializes a long double.
  577. * @param ldouble_t The value of the long double that will be serialized in the buffer.
  578. * @return Reference to the eprosima::fastcdr::FastCdr object.
  579. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  580. */
  581. inline
  582. FastCdr& serialize(const long double ldouble_t)
  583. {
  584. if(((m_lastPosition - m_currentPosition) >= sizeof(ldouble_t)) || resize(sizeof(ldouble_t)))
  585. {
  586. m_currentPosition << ldouble_t;
  587. #if defined(_WIN32)
  588. m_currentPosition += sizeof(ldouble_t);
  589. m_currentPosition << static_cast<long double>(0);
  590. #endif
  591. m_currentPosition += sizeof(ldouble_t);
  592. return *this;
  593. }
  594. throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
  595. }
  596. /*!
  597. * @brief This function serializes a boolean.
  598. * @param bool_t The value of the boolean that will be serialized in the buffer.
  599. * @return Reference to the eprosima::fastcdr::FastCdr object.
  600. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  601. */
  602. FastCdr& serialize(const bool bool_t);
  603. /*!
  604. * @brief This function serializes a string.
  605. * @param string_t The pointer to the string that will be serialized in the buffer.
  606. * @return Reference to the eprosima::fastcdr::FastCdr object.
  607. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  608. */
  609. FastCdr& serialize(const char *string_t);
  610. /*!
  611. * @brief This function serializes a wstring.
  612. * @param string_t The pointer to the wstring that will be serialized in the buffer.
  613. * @return Reference to the eprosima::fastcdr::FastCdr object.
  614. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  615. */
  616. FastCdr& serialize(const wchar_t *string_t);
  617. /*!
  618. * @brief This function serializes a std::string.
  619. * @param string_t The string that will be serialized in the buffer.
  620. * @return Reference to the eprosima::fastcdr::FastCdr object.
  621. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  622. */
  623. inline
  624. FastCdr& serialize(const std::string &string_t) {return serialize(string_t.c_str());}
  625. /*!
  626. * @brief This function serializes a std::wstring.
  627. * @param string_t The wstring that will be serialized in the buffer.
  628. * @return Reference to the eprosima::fastcdr::FastCdr object.
  629. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  630. */
  631. inline
  632. FastCdr& serialize(const std::wstring &string_t) {return serialize(string_t.c_str());}
  633. #if HAVE_CXX0X
  634. /*!
  635. * @brief This function template serializes an array.
  636. * @param array_t The array that will be serialized in the buffer.
  637. * @return Reference to the eprosima::fastcdr::FastCdr object.
  638. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  639. */
  640. template<class _T, size_t _Size>
  641. inline FastCdr& serialize(const std::array<_T, _Size> &array_t)
  642. { return serializeArray(array_t.data(), array_t.size());}
  643. #endif
  644. #if !defined(_MSC_VER) && HAVE_CXX0X
  645. /*!
  646. * @brief This function template serializes a sequence of booleans.
  647. * @param vector_t The sequence that will be serialized in the buffer.
  648. * @return Reference to the eprosima::fastcdr::FastCdr object.
  649. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  650. */
  651. template<class _T = bool>
  652. FastCdr& serialize(const std::vector<bool> &vector_t)
  653. {
  654. return serializeBoolSequence(vector_t);
  655. }
  656. #endif
  657. /*!
  658. * @brief This function template serializes a sequence.
  659. * @param vector_t The sequence that will be serialized in the buffer.
  660. * @return Reference to the eprosima::fastcdr::FastCdr object.
  661. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  662. */
  663. template<class _T>
  664. FastCdr& serialize(const std::vector<_T> &vector_t)
  665. {
  666. state state_before_error(*this);
  667. *this << static_cast<int32_t>(vector_t.size());
  668. try
  669. {
  670. return serializeArray(vector_t.data(), vector_t.size());
  671. }
  672. catch(eprosima::fastcdr::exception::Exception &ex)
  673. {
  674. setState(state_before_error);
  675. ex.raise();
  676. }
  677. return *this;
  678. }
  679. #ifdef _MSC_VER
  680. /*!
  681. * @brief This function template serializes a sequence of booleans.
  682. * @param vector_t The sequence that will be serialized in the buffer.
  683. * @return Reference to the eprosima::fastcdr::FastCdr object.
  684. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  685. */
  686. template<>
  687. FastCdr& serialize<bool>(const std::vector<bool> &vector_t)
  688. {
  689. return serializeBoolSequence(vector_t);
  690. }
  691. #endif
  692. /*!
  693. * @brief This function template serializes a non-basic type.
  694. * @param type_t The object that will be serialized in the buffer.
  695. * @return Reference to the eprosima::fastcdr::FastCdr object.
  696. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  697. */
  698. template<class _T>
  699. inline FastCdr& serialize(const _T &type_t)
  700. {
  701. type_t.serialize(*this);
  702. return *this;
  703. }
  704. /*!
  705. * @brief This function serializes an array of octets.
  706. * @param octet_t The sequence of octets that will be serialized in the buffer.
  707. * @param numElements Number of the elements in the array.
  708. * @return Reference to the eprosima::fastcdr::FastCdr object.
  709. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  710. */
  711. inline
  712. FastCdr& serializeArray(const uint8_t *octet_t, size_t numElements)
  713. {
  714. return serializeArray(reinterpret_cast<const char*>(octet_t), numElements);
  715. }
  716. /*!
  717. * @brief This function serializes an array of characters.
  718. * @param char_t The array of characters that will be serialized in the buffer.
  719. * @param numElements Number of the elements in the array.
  720. * @return Reference to the eprosima::fastcdr::FastCdr object.
  721. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  722. */
  723. FastCdr& serializeArray(const char *char_t, size_t numElements);
  724. /*!
  725. * @brief This function serializes an array of int8_t.
  726. * @param int8 The sequence of int8_t that will be serialized in the buffer.
  727. * @param numElements Number of the elements in the array.
  728. * @return Reference to the eprosima::fastcdr::FastCdr object.
  729. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  730. */
  731. inline
  732. FastCdr& serializeArray(const int8_t *int8, size_t numElements)
  733. {
  734. return serializeArray(reinterpret_cast<const char*>(int8), numElements);
  735. }
  736. /*!
  737. * @brief This function serializes an array of unsigned shorts.
  738. * @param ushort_t The array of unsigned shorts that will be serialized in the buffer.
  739. * @param numElements Number of the elements in the array.
  740. * @return Reference to the eprosima::fastcdr::FastCdr object.
  741. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  742. */
  743. inline
  744. FastCdr& serializeArray(const uint16_t *ushort_t, size_t numElements)
  745. {
  746. return serializeArray(reinterpret_cast<const int16_t*>(ushort_t), numElements);
  747. }
  748. /*!
  749. * @brief This function serializes an array of shorts.
  750. * @param short_t The array of shorts that will be serialized in the buffer.
  751. * @param numElements Number of the elements in the array.
  752. * @return Reference to the eprosima::fastcdr::FastCdr object.
  753. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  754. */
  755. FastCdr& serializeArray(const int16_t *short_t, size_t numElements);
  756. /*!
  757. * @brief This function serializes an array of unsigned longs.
  758. * @param ulong_t The array of unsigned longs that will be serialized in the buffer.
  759. * @param numElements Number of the elements in the array.
  760. * @return Reference to the eprosima::fastcdr::FastCdr object.
  761. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  762. */
  763. inline
  764. FastCdr& serializeArray(const uint32_t *ulong_t, size_t numElements)
  765. {
  766. return serializeArray(reinterpret_cast<const int32_t*>(ulong_t), numElements);
  767. }
  768. /*!
  769. * @brief This function serializes an array of longs.
  770. * @param long_t The array of longs that will be serialized in the buffer.
  771. * @param numElements Number of the elements in the array.
  772. * @return Reference to the eprosima::fastcdr::FastCdr object.
  773. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  774. */
  775. FastCdr& serializeArray(const int32_t *long_t, size_t numElements);
  776. /*!
  777. * @brief This function serializes an array of wide-chars.
  778. * @param wchar The array of wide-chars that will be serialized in the buffer.
  779. * @param numElements Number of the elements in the array.
  780. * @return Reference to the eprosima::fastcdr::FastCdr object.
  781. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  782. */
  783. FastCdr& serializeArray(const wchar_t *wchar, size_t numElements);
  784. /*!
  785. * @brief This function serializes an array of unsigned long longs.
  786. * @param ulonglong_t The array of unsigned long longs that will be serialized in the buffer.
  787. * @param numElements Number of the elements in the array.
  788. * @return Reference to the eprosima::fastcdr::FastCdr object.
  789. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  790. */
  791. inline
  792. FastCdr& serializeArray(const uint64_t *ulonglong_t, size_t numElements)
  793. {
  794. return serializeArray(reinterpret_cast<const int64_t*>(ulonglong_t), numElements);
  795. }
  796. /*!
  797. * @brief This function serializes an array of long longs.
  798. * @param longlong_t The array of long longs that will be serialized in the buffer.
  799. * @param numElements Number of the elements in the array.
  800. * @return Reference to the eprosima::fastcdr::FastCdr object.
  801. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  802. */
  803. FastCdr& serializeArray(const int64_t *longlong_t, size_t numElements);
  804. /*!
  805. * @brief This function serializes an array of floats.
  806. * @param float_t The array of floats that will be serialized in the buffer.
  807. * @param numElements Number of the elements in the array.
  808. * @return Reference to the eprosima::fastcdr::FastCdr object.
  809. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  810. */
  811. FastCdr& serializeArray(const float *float_t, size_t numElements);
  812. /*!
  813. * @brief This function serializes an array of doubles.
  814. * @param double_t The array of doubles that will be serialized in the buffer.
  815. * @param numElements Number of the elements in the array.
  816. * @return Reference to the eprosima::fastcdr::FastCdr object.
  817. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  818. */
  819. FastCdr& serializeArray(const double *double_t, size_t numElements);
  820. /*!
  821. * @brief This function serializes an array of long doubles.
  822. * @param ldouble_t The array of long doubles that will be serialized in the buffer.
  823. * @param numElements Number of the elements in the array.
  824. * @return Reference to the eprosima::fastcdr::FastCdr object.
  825. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  826. */
  827. FastCdr& serializeArray(const long double *ldouble_t, size_t numElements);
  828. /*!
  829. * @brief This function serializes an array of booleans.
  830. * @param bool_t The array of booleans that will be serialized in the buffer.
  831. * @param numElements Number of the elements in the array.
  832. * @return Reference to the eprosima::fastcdr::FastCdr object.
  833. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  834. */
  835. FastCdr& serializeArray(const bool *bool_t, size_t numElements);
  836. /*!
  837. * @brief This function serializes an array of strings.
  838. * @param string_t The array of strings that will be serialized in the buffer.
  839. * @param numElements Number of the elements in the array.
  840. * @return Reference to the eprosima::fastcdr::FastCdr object.
  841. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  842. */
  843. inline
  844. FastCdr& serializeArray(const std::string *string_t, size_t numElements)
  845. {
  846. for(size_t count = 0; count < numElements; ++count)
  847. serialize(string_t[count].c_str());
  848. return *this;
  849. }
  850. /*!
  851. * @brief This function serializes an array of wstrings.
  852. * @param string_t The array of wstrings that will be serialized in the buffer.
  853. * @param numElements Number of the elements in the array.
  854. * @return Reference to the eprosima::fastcdr::FastCdr object.
  855. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  856. */
  857. inline
  858. FastCdr& serializeArray(const std::wstring *string_t, size_t numElements)
  859. {
  860. for(size_t count = 0; count < numElements; ++count)
  861. serialize(string_t[count].c_str());
  862. return *this;
  863. }
  864. /*!
  865. * @brief This function template serializes an array of sequences.
  866. * @param vector_t The array of sequences that will be serialized in the buffer.
  867. * @param numElements Number of the elements in the array.
  868. * @return Reference to the eprosima::fastcdr::FastCdr object.
  869. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  870. */
  871. template<class _T>
  872. FastCdr& serializeArray(const std::vector<_T> *vector_t, size_t numElements)
  873. {
  874. for(size_t count = 0; count < numElements; ++count)
  875. serialize(vector_t[count]);
  876. return *this;
  877. }
  878. /*!
  879. * @brief This function template serializes an array of non-basic type objects.
  880. * @param string_t The array of objects that will be serialized in the buffer.
  881. * @param numElements Number of the elements in the array.
  882. * @return Reference to the eprosima::fastcdr::FastCdr object.
  883. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  884. */
  885. template<class _T>
  886. FastCdr& serializeArray(const _T *type_t, size_t numElements)
  887. {
  888. for(size_t count = 0; count < numElements; ++count)
  889. type_t[count].serialize(*this);
  890. return *this;
  891. }
  892. /*!
  893. * @brief This function template serializes a raw sequence.
  894. * @param sequence_t Pointer to the sequence that will be serialized in the buffer.
  895. * @param numElements The number of elements contained in the sequence.
  896. * @return Reference to the eprosima::fastcdr::FastCdr object.
  897. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  898. */
  899. template<class _T>
  900. FastCdr& serializeSequence(const _T *sequence_t, size_t numElements)
  901. {
  902. state state_before_error(*this);
  903. serialize(static_cast<int32_t>(numElements));
  904. try
  905. {
  906. return serializeArray(sequence_t, numElements);
  907. }
  908. catch(eprosima::fastcdr::exception::Exception &ex)
  909. {
  910. setState(state_before_error);
  911. ex.raise();
  912. }
  913. return *this;
  914. }
  915. /*!
  916. * @brief This function deserializes an octet.
  917. * @param octet_t The variable that will store the octet read from the buffer.
  918. * @return Reference to the eprosima::fastcdr::FastCdr object.
  919. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  920. */
  921. inline
  922. FastCdr& deserialize(uint8_t &octet_t)
  923. {
  924. return deserialize(reinterpret_cast<char&>(octet_t));
  925. }
  926. /*!
  927. * @brief This function deserializes a character.
  928. * @param char_t The variable that will store the character read from the buffer.
  929. * @return Reference to the eprosima::fastcdr::FastCdr object.
  930. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  931. */
  932. inline
  933. FastCdr& deserialize(char &char_t)
  934. {
  935. if((m_lastPosition - m_currentPosition) >= sizeof(char_t))
  936. {
  937. m_currentPosition++ >> char_t;
  938. return *this;
  939. }
  940. throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
  941. }
  942. /*!
  943. * @brief This function deserializes an int8_t.
  944. * @param int8 The variable that will store the int8_t read from the buffer.
  945. * @return Reference to the eprosima::fastcdr::FastCdr object.
  946. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  947. */
  948. inline
  949. FastCdr& deserialize(int8_t &int8)
  950. {
  951. return deserialize(reinterpret_cast<char&>(int8));
  952. }
  953. /*!
  954. * @brief This function deserializes an unsigned short.
  955. * @param ushort_t The variable that will store the unsigned short read from the buffer.
  956. * @return Reference to the eprosima::fastcdr::FastCdr object.
  957. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  958. */
  959. inline
  960. FastCdr& deserialize(uint16_t &ushort_t)
  961. {
  962. return deserialize(reinterpret_cast<int16_t&>(ushort_t));
  963. }
  964. /*!
  965. * @brief This function deserializes a short.
  966. * @param short_t The variable that will store the short read from the buffer.
  967. * @return Reference to the eprosima::fastcdr::FastCdr object.
  968. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  969. */
  970. inline
  971. FastCdr& deserialize(int16_t &short_t)
  972. {
  973. if((m_lastPosition - m_currentPosition) >= sizeof(short_t))
  974. {
  975. m_currentPosition >> short_t;
  976. m_currentPosition += sizeof(short_t);
  977. return *this;
  978. }
  979. throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
  980. }
  981. /*!
  982. * @brief This function deserializes an unsigned long.
  983. * @param ulong_t The variable that will store the unsigned long read from the buffer.
  984. * @return Reference to the eprosima::fastcdr::FastCdr object.
  985. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  986. */
  987. inline
  988. FastCdr& deserialize(uint32_t &ulong_t)
  989. {
  990. return deserialize(reinterpret_cast<int32_t&>(ulong_t));
  991. }
  992. /*!
  993. * @brief This function deserializes a long.
  994. * @param long_t The variable that will store the long read from the buffer.
  995. * @return Reference to the eprosima::fastcdr::FastCdr object.
  996. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  997. */
  998. inline
  999. FastCdr& deserialize(int32_t &long_t)
  1000. {
  1001. if((m_lastPosition - m_currentPosition) >= sizeof(long_t))
  1002. {
  1003. m_currentPosition >> long_t;
  1004. m_currentPosition += sizeof(long_t);
  1005. return *this;
  1006. }
  1007. throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
  1008. }
  1009. /*!
  1010. * @brief This function deserializes a wide-char.
  1011. * @param wchar The variable that will store the wide-char read from the buffer.
  1012. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1013. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1014. */
  1015. inline
  1016. FastCdr& deserialize(wchar_t &wchar)
  1017. {
  1018. uint32_t ret;
  1019. deserialize(ret);
  1020. wchar = static_cast<wchar_t>(ret);
  1021. return *this;
  1022. }
  1023. /*!
  1024. * @brief This function deserializes an unsigned long long.
  1025. * @param ulonglong_t The variable that will store the unsigned long long read from the buffer.
  1026. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1027. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1028. */
  1029. inline
  1030. FastCdr& deserialize(uint64_t &ulonglong_t)
  1031. {
  1032. return deserialize(reinterpret_cast<int64_t&>(ulonglong_t));
  1033. }
  1034. /*!
  1035. * @brief This function deserializes a long long.
  1036. * @param longlong_t The variable that will store the long long read from the buffer.
  1037. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1038. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1039. */
  1040. inline
  1041. FastCdr& deserialize(int64_t &longlong_t)
  1042. {
  1043. if((m_lastPosition - m_currentPosition) >= sizeof(longlong_t))
  1044. {
  1045. m_currentPosition >> longlong_t;
  1046. m_currentPosition += sizeof(longlong_t);
  1047. return *this;
  1048. }
  1049. throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
  1050. }
  1051. /*!
  1052. * @brief This function deserializes a float.
  1053. * @param float_t The variable that will store the float read from the buffer.
  1054. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1055. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1056. */
  1057. inline
  1058. FastCdr& deserialize(float &float_t)
  1059. {
  1060. if((m_lastPosition - m_currentPosition) >= sizeof(float_t))
  1061. {
  1062. m_currentPosition >> float_t;
  1063. m_currentPosition += sizeof(float_t);
  1064. return *this;
  1065. }
  1066. throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
  1067. }
  1068. /*!
  1069. * @brief This function deserializes a double.
  1070. * @param double_t The variable that will store the double read from the buffer.
  1071. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1072. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1073. */
  1074. inline
  1075. FastCdr& deserialize(double &double_t)
  1076. {
  1077. if((m_lastPosition - m_currentPosition) >= sizeof(double_t))
  1078. {
  1079. m_currentPosition >> double_t;
  1080. m_currentPosition += sizeof(double_t);
  1081. return *this;
  1082. }
  1083. throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
  1084. }
  1085. /*!
  1086. * @brief This function deserializes a long double.
  1087. * @param ldouble_t The variable that will store the long double read from the buffer.
  1088. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1089. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1090. */
  1091. inline
  1092. FastCdr& deserialize(long double &ldouble_t)
  1093. {
  1094. if((m_lastPosition - m_currentPosition) >= sizeof(ldouble_t))
  1095. {
  1096. m_currentPosition >> ldouble_t;
  1097. m_currentPosition += sizeof(ldouble_t);
  1098. #if defined(_WIN32)
  1099. m_currentPosition += sizeof(ldouble_t);
  1100. #endif
  1101. return *this;
  1102. }
  1103. throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
  1104. }
  1105. /*!
  1106. * @brief This function deserializes a boolean.
  1107. * @param bool_t The variable that will store the boolean read from the buffer.
  1108. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1109. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1110. * @exception exception::BadParamException This exception is thrown when trying to deserialize in an invalid value.
  1111. */
  1112. FastCdr& deserialize(bool &bool_t);
  1113. /*!
  1114. * @brief This function deserializes a string.
  1115. * This function allocates memory to store the string. The user pointer will be set to point this allocated memory.
  1116. * The user will have to free this allocated memory using free()
  1117. * @param string_t The pointer that will point to the string read from the buffer.
  1118. * The user will have to free the allocated memory using free()
  1119. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1120. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1121. */
  1122. FastCdr& deserialize(char *&string_t);
  1123. /*!
  1124. * @brief This function deserializes a wide string.
  1125. * This function allocates memory to store the wide string. The user pointer will be set to point this allocated memory.
  1126. * The user will have to free this allocated memory using free()
  1127. * @param string_t The pointer that will point to the wide string read from the buffer.
  1128. * The user will have to free the allocated memory using free()
  1129. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1130. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1131. */
  1132. FastCdr& deserialize(wchar_t *&string_t);
  1133. /*!
  1134. * @brief This function deserializes a std::string.
  1135. * @param string_t The variable that will store the string read from the buffer.
  1136. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1137. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1138. */
  1139. inline
  1140. FastCdr& deserialize(std::string &string_t)
  1141. {
  1142. uint32_t length = 0;
  1143. const char *str = readString(length);
  1144. string_t = std::string(str, length);
  1145. return *this;
  1146. }
  1147. /*!
  1148. * @brief This function deserializes a std::wstring.
  1149. * @param string_t The variable that will store the wstring read from the buffer.
  1150. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1151. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1152. */
  1153. inline
  1154. FastCdr& deserialize(std::wstring &string_t)
  1155. {
  1156. uint32_t length = 0;
  1157. string_t = readWString(length);
  1158. return *this;
  1159. }
  1160. #if HAVE_CXX0X
  1161. /*!
  1162. * @brief This function template deserializes an array.
  1163. * @param array_t The variable that will store the array read from the buffer.
  1164. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1165. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1166. */
  1167. template<class _T, size_t _Size>
  1168. inline FastCdr& deserialize(std::array<_T, _Size> &array_t)
  1169. { return deserializeArray(array_t.data(), array_t.size());}
  1170. #endif
  1171. #if !defined(_MSC_VER) && HAVE_CXX0X
  1172. /*!
  1173. * @brief This function template deserializes a sequence of booleans.
  1174. * @param vector_t The variable that will store the sequence read from the buffer.
  1175. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1176. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1177. */
  1178. template<class _T = bool>
  1179. FastCdr& deserialize(std::vector<bool> &vector_t)
  1180. {
  1181. return deserializeBoolSequence(vector_t);
  1182. }
  1183. #endif
  1184. /*!
  1185. * @brief This function template deserializes a sequence.
  1186. * @param vector_t The variable that will store the sequence read from the buffer.
  1187. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1188. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1189. */
  1190. template<class _T>
  1191. FastCdr& deserialize(std::vector<_T> &vector_t)
  1192. {
  1193. uint32_t seqLength = 0;
  1194. state state_before_error(*this);
  1195. *this >> seqLength;
  1196. try
  1197. {
  1198. vector_t.resize(seqLength);
  1199. return deserializeArray(vector_t.data(), vector_t.size());
  1200. }
  1201. catch(eprosima::fastcdr::exception::Exception &ex)
  1202. {
  1203. setState(state_before_error);
  1204. ex.raise();
  1205. }
  1206. return *this;
  1207. }
  1208. #ifdef _MSC_VER
  1209. /*!
  1210. * @brief This function template deserializes a sequence of booleans.
  1211. * @param vector_t The variable that will store the sequence read from the buffer.
  1212. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1213. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1214. */
  1215. template<>
  1216. FastCdr& deserialize<bool>(std::vector<bool> &vector_t)
  1217. {
  1218. return deserializeBoolSequence(vector_t);
  1219. }
  1220. #endif
  1221. /*!
  1222. * @brief This function template deserializes a non-basic type object.
  1223. * @param type_t The variable that will store the object read from the buffer.
  1224. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1225. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1226. */
  1227. template<class _T>
  1228. inline FastCdr& deserialize(_T &type_t)
  1229. {
  1230. type_t.deserialize(*this);
  1231. return *this;
  1232. }
  1233. /*!
  1234. * @brief This function deserializes an array of octets.
  1235. * @param octet_t The variable that will store the array of octets read from the buffer.
  1236. * @param numElements Number of the elements in the array.
  1237. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1238. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1239. */
  1240. inline
  1241. FastCdr& deserializeArray(uint8_t *octet_t, size_t numElements)
  1242. {
  1243. return deserializeArray(reinterpret_cast<char*>(octet_t), numElements);
  1244. }
  1245. /*!
  1246. * @brief This function deserializes an array of characters.
  1247. * @param char_t The variable that will store the array of characters read from the buffer.
  1248. * @param numElements Number of the elements in the array.
  1249. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1250. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1251. */
  1252. FastCdr& deserializeArray(char *char_t, size_t numElements);
  1253. /*!
  1254. * @brief This function deserializes an array of int8_t.
  1255. * @param int8 The variable that will store the array of int8_t read from the buffer.
  1256. * @param numElements Number of the elements in the array.
  1257. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1258. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1259. */
  1260. inline
  1261. FastCdr& deserializeArray(int8_t *int8, size_t numElements)
  1262. {
  1263. return deserializeArray(reinterpret_cast<char*>(int8), numElements);
  1264. }
  1265. /*!
  1266. * @brief This function deserializes an array of unsigned shorts.
  1267. * @param ushort_t The variable that will store the array of unsigned shorts read from the buffer.
  1268. * @param numElements Number of the elements in the array.
  1269. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1270. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1271. */
  1272. inline
  1273. FastCdr& deserializeArray(uint16_t *ushort_t, size_t numElements)
  1274. {
  1275. return deserializeArray(reinterpret_cast<int16_t*>(ushort_t), numElements);
  1276. }
  1277. /*!
  1278. * @brief This function deserializes an array of shorts.
  1279. * @param short_t The variable that will store the array of shorts read from the buffer.
  1280. * @param numElements Number of the elements in the array.
  1281. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1282. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1283. */
  1284. FastCdr& deserializeArray(int16_t *short_t, size_t numElements);
  1285. /*!
  1286. * @brief This function deserializes an array of unsigned longs.
  1287. * @param ulong_t The variable that will store the array of unsigned longs read from the buffer.
  1288. * @param numElements Number of the elements in the array.
  1289. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1290. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1291. */
  1292. inline
  1293. FastCdr& deserializeArray(uint32_t *ulong_t, size_t numElements)
  1294. {
  1295. return deserializeArray(reinterpret_cast<int32_t*>(ulong_t), numElements);
  1296. }
  1297. /*!
  1298. * @brief This function deserializes an array of longs.
  1299. * @param long_t The variable that will store the array of longs read from the buffer.
  1300. * @param numElements Number of the elements in the array.
  1301. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1302. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1303. */
  1304. FastCdr& deserializeArray(int32_t *long_t, size_t numElements);
  1305. /*!
  1306. * @brief This function deserializes an array of wide-chars.
  1307. * @param wchar The variable that will store the array of wide-chars read from the buffer.
  1308. * @param numElements Number of the elements in the array.
  1309. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1310. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1311. */
  1312. FastCdr& deserializeArray(wchar_t *wchar, size_t numElements);
  1313. /*!
  1314. * @brief This function deserializes an array of unsigned long longs.
  1315. * @param ulonglong_t The variable that will store the array of unsigned long longs read from the buffer.
  1316. * @param numElements Number of the elements in the array.
  1317. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1318. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1319. */
  1320. inline
  1321. FastCdr& deserializeArray(uint64_t *ulonglong_t, size_t numElements)
  1322. {
  1323. return deserializeArray(reinterpret_cast<int64_t*>(ulonglong_t), numElements);
  1324. }
  1325. /*!
  1326. * @brief This function deserializes an array of long longs.
  1327. * @param longlong_t The variable that will store the array of long longs read from the buffer.
  1328. * @param numElements Number of the elements in the array.
  1329. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1330. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1331. */
  1332. FastCdr& deserializeArray(int64_t *longlong_t, size_t numElements);
  1333. /*!
  1334. * @brief This function deserializes an array of floats.
  1335. * @param float_t The variable that will store the array of floats read from the buffer.
  1336. * @param numElements Number of the elements in the array.
  1337. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1338. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1339. */
  1340. FastCdr& deserializeArray(float *float_t, size_t numElements);
  1341. /*!
  1342. * @brief This function deserializes an array of doubles.
  1343. * @param double_t The variable that will store the array of doubles read from the buffer.
  1344. * @param numElements Number of the elements in the array.
  1345. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1346. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1347. */
  1348. FastCdr& deserializeArray(double *double_t, size_t numElements);
  1349. /*!
  1350. * @brief This function deserializes an array of long doubles.
  1351. * @param ldouble_t The variable that will store the array of long doubles read from the buffer.
  1352. * @param numElements Number of the elements in the array.
  1353. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1354. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1355. */
  1356. FastCdr& deserializeArray(long double *ldouble_t, size_t numElements);
  1357. /*!
  1358. * @brief This function deserializes an array of booleans.
  1359. * @param bool_t The variable that will store the array of booleans read from the buffer.
  1360. * @param numElements Number of the elements in the array.
  1361. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1362. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1363. */
  1364. FastCdr& deserializeArray(bool *bool_t, size_t numElements);
  1365. /*!
  1366. * @brief This function deserializes an array of strings.
  1367. * @param string_t The variable that will store the array of strings read from the buffer.
  1368. * @param numElements Number of the elements in the array.
  1369. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1370. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1371. */
  1372. inline
  1373. FastCdr& deserializeArray(std::string *string_t, size_t numElements)
  1374. {
  1375. for(size_t count = 0; count < numElements; ++count)
  1376. deserialize(string_t[count]);
  1377. return *this;
  1378. }
  1379. /*!
  1380. * @brief This function deserializes an array of wide-strings.
  1381. * @param string_t The variable that will store the array of strings read from the buffer.
  1382. * @param numElements Number of the elements in the array.
  1383. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1384. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1385. */
  1386. inline
  1387. FastCdr& deserializeArray(std::wstring *string_t, size_t numElements)
  1388. {
  1389. for(size_t count = 0; count < numElements; ++count)
  1390. deserialize(string_t[count]);
  1391. return *this;
  1392. }
  1393. /*!
  1394. * @brief This function template deserializes an array of sequences.
  1395. * @param vector_t The variable that will store the array of sequences read from the buffer.
  1396. * @param numElements Number of the elements in the array.
  1397. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1398. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1399. */
  1400. template<class _T>
  1401. FastCdr& deserializeArray(std::vector<_T> *vector_t, size_t numElements)
  1402. {
  1403. for(size_t count = 0; count < numElements; ++count)
  1404. deserialize(vector_t[count]);
  1405. return *this;
  1406. }
  1407. /*!
  1408. * @brief This function template deserializes an array of non-basic type objects.
  1409. * @param type_t The variable that will store the array of objects read from the buffer.
  1410. * @param numElements Number of the elements in the array.
  1411. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1412. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1413. */
  1414. template<class _T>
  1415. FastCdr& deserializeArray(_T *type_t, size_t numElements)
  1416. {
  1417. for(size_t count = 0; count < numElements; ++count)
  1418. type_t[count].deserialize(*this);
  1419. return *this;
  1420. }
  1421. #if !defined(_MSC_VER) && HAVE_CXX0X
  1422. /*!
  1423. * @brief This function template deserializes a string sequence.
  1424. * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
  1425. * The user will have to free this allocated memory using free()
  1426. * @param sequence_t The pointer that will store the sequence read from the buffer.
  1427. * @param numElements This variable return the number of elements of the sequence.
  1428. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1429. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1430. */
  1431. template<class _T = std::string>
  1432. FastCdr& deserializeSequence(std::string *&sequence_t, size_t &numElements)
  1433. {
  1434. return deserializeStringSequence(sequence_t, numElements);
  1435. }
  1436. /*!
  1437. * @brief This function template deserializes a wide-string sequence.
  1438. * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
  1439. * The user will have to free this allocated memory using free()
  1440. * @param sequence_t The pointer that will store the sequence read from the buffer.
  1441. * @param numElements This variable return the number of elements of the sequence.
  1442. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1443. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1444. */
  1445. template<class _T = std::wstring>
  1446. FastCdr& deserializeSequence(std::wstring *&sequence_t, size_t &numElements)
  1447. {
  1448. return deserializeWStringSequence(sequence_t, numElements);
  1449. }
  1450. #endif
  1451. /*!
  1452. * @brief This function template deserializes a raw sequence.
  1453. * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
  1454. * The user will have to free this allocated memory using free()
  1455. * @param sequence_t The pointer that will store the sequence read from the buffer.
  1456. * @param numElements This variable return the number of elements of the sequence.
  1457. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1458. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1459. */
  1460. template<class _T>
  1461. FastCdr& deserializeSequence(_T *&sequence_t, size_t &numElements)
  1462. {
  1463. uint32_t seqLength = 0;
  1464. state state_before_error(*this);
  1465. deserialize(seqLength);
  1466. try
  1467. {
  1468. sequence_t = reinterpret_cast<_T*>(calloc(seqLength, sizeof(_T)));
  1469. deserializeArray(sequence_t, seqLength);
  1470. }
  1471. catch(eprosima::fastcdr::exception::Exception &ex)
  1472. {
  1473. free(sequence_t);
  1474. sequence_t = NULL;
  1475. setState(state_before_error);
  1476. ex.raise();
  1477. }
  1478. numElements = seqLength;
  1479. return *this;
  1480. }
  1481. #ifdef _MSC_VER
  1482. /*!
  1483. * @brief This function template deserializes a string sequence.
  1484. * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
  1485. * The user will have to free this allocated memory using free()
  1486. * @param sequence_t The pointer that will store the sequence read from the buffer.
  1487. * @param numElements This variable return the number of elements of the sequence.
  1488. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1489. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1490. */
  1491. template<>
  1492. FastCdr& deserializeSequence<std::string>(std::string *&sequence_t, size_t &numElements)
  1493. {
  1494. return deserializeStringSequence(sequence_t, numElements);
  1495. }
  1496. /*!
  1497. * @brief This function template deserializes a wide-string sequence.
  1498. * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
  1499. * The user will have to free this allocated memory using free()
  1500. * @param sequence_t The pointer that will store the sequence read from the buffer.
  1501. * @param numElements This variable return the number of elements of the sequence.
  1502. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1503. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1504. */
  1505. template<>
  1506. FastCdr& deserializeSequence<std::wstring>(std::wstring *&sequence_t, size_t &numElements)
  1507. {
  1508. return deserializeWStringSequence(sequence_t, numElements);
  1509. }
  1510. #endif
  1511. private:
  1512. FastCdr(const FastCdr&) = delete;
  1513. FastCdr& operator=(const FastCdr&) = delete;
  1514. FastCdr& serializeBoolSequence(const std::vector<bool> &vector_t);
  1515. FastCdr& deserializeBoolSequence(std::vector<bool> &vector_t);
  1516. FastCdr& deserializeStringSequence(std::string *&sequence_t, size_t &numElements);
  1517. FastCdr& deserializeWStringSequence(std::wstring *&sequence_t, size_t &numElements);
  1518. #if HAVE_CXX0X
  1519. /*!
  1520. * @brief This function template detects the content type of the STD container array and serializes the array.
  1521. * @param array_t The array that will be serialized in the buffer.
  1522. * @param numElements Number of the elements in the array.
  1523. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1524. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
  1525. */
  1526. template<class _T, size_t _Size>
  1527. FastCdr& serializeArray(const std::array<_T, _Size> *array_t, size_t numElements)
  1528. {
  1529. return serializeArray(array_t->data(), numElements * array_t->size());
  1530. }
  1531. /*!
  1532. * @brief This function template detects the content type of the STD container array and deserializes the array.
  1533. * @param array_t The variable that will store the array read from the buffer.
  1534. * @param numElements Number of the elements in the array.
  1535. * @return Reference to the eprosima::fastcdr::FastCdr object.
  1536. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
  1537. */
  1538. template<class _T, size_t _Size>
  1539. FastCdr& deserializeArray(std::array<_T, _Size> *array_t, size_t numElements)
  1540. {
  1541. return deserializeArray(array_t->data(), numElements * array_t->size());
  1542. }
  1543. #endif
  1544. bool resize(size_t minSizeInc);
  1545. const char* readString(uint32_t &length);
  1546. std::wstring readWString(uint32_t &length);
  1547. //! @brief Reference to the buffer that will be serialized/deserialized.
  1548. FastBuffer &m_cdrBuffer;
  1549. //! @brief The current position in the serialization/deserialization process.
  1550. FastBuffer::iterator m_currentPosition;
  1551. //! @brief The last position in the buffer;
  1552. FastBuffer::iterator m_lastPosition;
  1553. };
  1554. } //namespace fastcdr
  1555. } //namespace eprosima
  1556. #endif //_FASTCDR_FASTCDR_H_