IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
StlSerializationOperators.h
Go to the documentation of this file.
1 // StlSerializationOperators.h:
3 // ----------------------------
4 //
14 
15 #ifndef __IPSDKSERIALIZATION_STLSERIALIZATIONOPERATORS_H__
16 #define __IPSDKSERIALIZATION_STLSERIALIZATIONOPERATORS_H__
17 
19 #include <IPSDKSerialization/Archive/BaseIArchive.h>
20 #include <IPSDKSerialization/Archive/BaseOArchive.h>
24 #include <boost/type_traits/is_arithmetic.hpp>
25 #include <boost/type_traits/is_same.hpp>
26 #include <vector>
27 #include <list>
28 #include <set>
29 #include <map>
30 #include <deque>
31 
32 namespace ipsdk {
33 
36 
39 
40 template <class T>
41 typename boost::enable_if_c<boost::is_arithmetic<T>::value == false,
42  BaseIArchive&>::type
43 operator>> (BaseIArchive& ar, const SerializationIItem<std::vector<T> >& item)
44 {
45  // retrieve input collection
46  std::vector<T>& coll = item._value;
47 
48  // clear of input collection
49  coll.clear();
50 
51  // start a new archive section
52  IPSDK_START_ARCHIVE_SECTION(ar, item._itemName);
53 
54  // start a new archive section
55  IPSDK_START_ARCHIVE_SECTION(ar, "vector");
56 
57  // serialization of collection size
58  ipUInt32 size;
59  ar >> IPSDK_MAKE_IITEM_VALUE(size);
60  coll.resize(size);
61 
62  // serialization of collection data
63  typename std::vector<T>::iterator iter = coll.begin();
64  while (iter != coll.end()) {
65 
66  T& value = *iter;
67  ar >> IPSDK_MAKE_IITEM_VALUE(value);
68 
69  ++iter;
70  }
71 
72  // end archive section
73  IPSDK_END_ARCHIVE_SECTION("vector");
74 
75  // end archive section
76  IPSDK_END_ARCHIVE_SECTION(item._itemName);
77 
78  return ar;
79 }
80 
81 template <class T>
82 typename boost::enable_if_c<boost::is_arithmetic<T>::value == true &&
83  boost::is_same<T, bool>::value == false,
84  BaseIArchive&>::type
85 operator>> (BaseIArchive& ar, const SerializationIItem<std::vector<T> >& item)
86 {
87  // retrieve input collection
88  std::vector<T>& coll = item._value;
89 
90  // clear of input collection
91  coll.clear();
92 
93  // start a new archive section
94  IPSDK_START_ARCHIVE_SECTION(ar, item._itemName);
95 
96  // start a new archive section
97  IPSDK_START_ARCHIVE_SECTION(ar, "vector");
98 
99  // serialization of collection size
100  ipUInt32 size;
101  ar >> IPSDK_MAKE_IITEM_VALUE(size);
102  coll.resize(size);
103 
104  // serialization of collection data
105  if (ar.isTextArchive() == false)
106  ar.read(coll.data(), size * sizeof(T));
107  else {
108 
109  typename std::vector<T>::iterator iter = coll.begin();
110  while (iter != coll.end()) {
111 
112  T& value = *iter;
113  ar >> IPSDK_MAKE_IITEM_VALUE(value);
114 
115  ++iter;
116  }
117  }
118 
119  // end archive section
120  IPSDK_END_ARCHIVE_SECTION("vector");
121 
122  // end archive section
123  IPSDK_END_ARCHIVE_SECTION(item._itemName);
124 
125  return ar;
126 }
127 
128 template <class T>
129 typename boost::enable_if_c<boost::is_same<T, ipBool>::value == true,
130  BaseIArchive&>::type
131 operator>> (BaseIArchive& ar, const SerializationIItem<std::vector<T> >& item)
132 {
133  // retrieve input collection
134  std::vector<T>& coll = item._value;
135 
136  // clear of input collection
137  coll.clear();
138 
139  // start a new archive section
140  IPSDK_START_ARCHIVE_SECTION(ar, item._itemName);
141 
142  // start a new archive section
143  IPSDK_START_ARCHIVE_SECTION(ar, "vector");
144 
145  // serialization of collection size
146  ipUInt32 size;
147  ar >> IPSDK_MAKE_IITEM_VALUE(size);
148  coll.resize(size);
149 
150  // serialization of collection data
151  typename std::vector<T>::iterator iter = coll.begin();
152  while (iter != coll.end()) {
153 
154  T value;
155  ar >> IPSDK_MAKE_IITEM_VALUE(value);
156  *iter = value;
157 
158  ++iter;
159  }
160 
161  // end archive section
162  IPSDK_END_ARCHIVE_SECTION("vector");
163 
164  // end archive section
165  IPSDK_END_ARCHIVE_SECTION(item._itemName);
166 
167  return ar;
168 }
169 
170 template <class T>
171 typename boost::enable_if_c<boost::is_arithmetic<T>::value == false ||
172  boost::is_same<T, ipBool>::value == true,
173  BaseOArchive&>::type
174 operator<< (BaseOArchive& ar, const SerializationOItem<std::vector<T> >& item)
175 {
176  // retrieve input collection
177  const std::vector<T>& coll = item._value;
178 
179  // start a new archive section
180  IPSDK_START_ARCHIVE_SECTION(ar, item._itemName);
181 
182  // start a new archive section
183  IPSDK_START_ARCHIVE_SECTION(ar, "vector");
184 
185  // serialization of collection size
186  ipUInt32 size = static_cast<ipUInt32>(coll.size());
187  ar << IPSDK_MAKE_OITEM_VALUE(size);
188 
189  // serialization of collection data
190  typename std::vector<T>::const_iterator iter = coll.begin();
191  while (iter != coll.end()) {
192 
193  const T& value = *iter;
194  ar << IPSDK_MAKE_OITEM_VALUE(value);
195  ++iter;
196  }
197 
198  // end archive section
199  IPSDK_END_ARCHIVE_SECTION("vector");
200 
201  // end archive section
202  IPSDK_END_ARCHIVE_SECTION(item._itemName);
203 
204  return ar;
205 }
206 
207 template <class T>
208 typename boost::enable_if_c<boost::is_arithmetic<T>::value == true &&
209  boost::is_same<T, ipBool>::value == false,
210  BaseOArchive&>::type
211 operator<< (BaseOArchive& ar, const SerializationOItem<std::vector<T> >& item)
212 {
213  // retrieve input collection
214  const std::vector<T>& coll = item._value;
215 
216  // start a new archive section
217  IPSDK_START_ARCHIVE_SECTION(ar, item._itemName);
218 
219  // start a new archive section
220  IPSDK_START_ARCHIVE_SECTION(ar, "vector");
221 
222  // serialization of collection size
223  ipUInt32 size = static_cast<ipUInt32>(coll.size());
224  ar << IPSDK_MAKE_OITEM_VALUE(size);
225 
226  // serialization of collection data
227  if (ar.isTextArchive() == false)
228  ar.write(coll.data(), size * sizeof(T));
229  else {
230 
231  typename std::vector<T>::const_iterator iter = coll.begin();
232  while (iter != coll.end()) {
233 
234  const T& value = *iter;
235  ar << IPSDK_MAKE_OITEM_VALUE(value);
236  ++iter;
237  }
238  }
239 
240  // end archive section
241  IPSDK_END_ARCHIVE_SECTION("vector");
242 
243  // end archive section
244  IPSDK_END_ARCHIVE_SECTION(item._itemName);
245 
246  return ar;
247 }
249 
252 
255 template <class T>
256 BaseIArchive&
257 operator>> (BaseIArchive& ar, const SerializationIItem<std::list<T> >& item)
258 {
259  // retrieve input collection
260  std::list<T>& coll = item._value;
261 
262  // clear of input collection
263  coll.clear();
264 
265  // start a new archive section
266  IPSDK_START_ARCHIVE_SECTION(ar, item._itemName);
267 
268  // start a new archive section
269  IPSDK_START_ARCHIVE_SECTION(ar, "list");
270 
271  // serialization of collection size
272  ipUInt32 size;
273  ar >> IPSDK_MAKE_IITEM_VALUE(size);
274  coll.resize(size);
275 
276  // serialization of collection data
277  typename std::list<T>::iterator iter = coll.begin();
278  while (iter != coll.end()) {
279 
280  T& value = *iter;
281  ar >> IPSDK_MAKE_IITEM_VALUE(value);
282 
283  ++iter;
284  }
285 
286  // end archive section
288 
289  // end archive section
290  IPSDK_END_ARCHIVE_SECTION(item._itemName);
291 
292  return ar;
293 }
294 
295 template <class T>
296 BaseOArchive&
297 operator<< (BaseOArchive& ar, const SerializationOItem<std::list<T> >& item)
298 {
299  // retrieve input collection
300  const std::list<T>& coll = item._value;
301 
302  // start a new archive section
303  IPSDK_START_ARCHIVE_SECTION(ar, item._itemName);
304 
305  // start a new archive section
306  IPSDK_START_ARCHIVE_SECTION(ar, "list");
307 
308  // serialization of collection size
309  ipUInt32 size = static_cast<ipUInt32>(coll.size());
310  ar << IPSDK_MAKE_OITEM_VALUE(size);
311 
312  // serialization of collection data
313  typename std::list<T>::const_iterator iter = coll.begin();
314  while (iter != coll.end()) {
315 
316  const T& value = *iter;
317  ar << IPSDK_MAKE_OITEM_VALUE(value);
318  ++iter;
319  }
320 
321  // end archive section
323 
324  // end archive section
325  IPSDK_END_ARCHIVE_SECTION(item._itemName);
326 
327  return ar;
328 }
329 
331 
334 
337 
338 template <class Key, class Value>
339 BaseIArchive&
340 operator>> (BaseIArchive& ar, const SerializationIItem<std::map<Key, Value> >& item)
341 {
342  // retrieve input collection
343  std::map<Key, Value>& coll = item._value;
344 
345  // clear of input collection
346  coll.clear();
347 
348  // start a new archive section
349  IPSDK_START_ARCHIVE_SECTION(ar, item._itemName);
350 
351  // start a new archive section
352  IPSDK_START_ARCHIVE_SECTION(ar, "map");
353 
354  // serialization of collection size
355  ipUInt32 size;
356  ar >> IPSDK_MAKE_IITEM_VALUE(size);
357 
358  // serialization of collection data
359  for (ipUInt32 i=0; i<size; ++i) {
360 
361  Key key;
362  Value value;
363  ar >> IPSDK_MAKE_IITEM_VALUE(key);
364  ar >> IPSDK_MAKE_IITEM_VALUE(value);
365  coll[key] = value;
366  }
367 
368  // end archive section
370 
371  // end archive section
372  IPSDK_END_ARCHIVE_SECTION(item._itemName);
373 
374  return ar;
375 }
376 
377 template <class Key, class Value>
378 BaseOArchive&
379 operator<< (BaseOArchive& ar, const SerializationOItem<std::map<Key, Value> >& item)
380 {
381  // retrieve input collection
382  const std::map<Key, Value>& coll = item._value;
383 
384  // start a new archive section
385  IPSDK_START_ARCHIVE_SECTION(ar, item._itemName);
386 
387  // start a new archive section
388  IPSDK_START_ARCHIVE_SECTION(ar, "map");
389 
390  // serialization of collection size
391  ipUInt32 size = static_cast<ipUInt32>(coll.size());
392  ar << IPSDK_MAKE_OITEM_VALUE(size);
393 
394  // serialization of collection data
395  typename std::map<Key, Value>::const_iterator iter = coll.begin();
396  while (iter != coll.end()) {
397 
398  const Key& key = iter->first;
399  const Value& value = iter->second;
400  ar << IPSDK_MAKE_OITEM_VALUE(key);
401  ar << IPSDK_MAKE_OITEM_VALUE(value);
402 
403  ++iter;
404  }
405 
406  // end archive section
408 
409  // end archive section
410  IPSDK_END_ARCHIVE_SECTION(item._itemName);
411 
412  return ar;
413 }
414 
416 
419 
422 
423 template <class T>
424 BaseIArchive&
425 operator>> (BaseIArchive& ar, const SerializationIItem<std::set<T> >& item)
426 {
427  // retrieve input collection
428  std::set<T>& coll = item._value;
429 
430  // clear of input collection
431  coll.clear();
432 
433  // start a new archive section
434  IPSDK_START_ARCHIVE_SECTION(ar, item._itemName);
435 
436  // start a new archive section
437  IPSDK_START_ARCHIVE_SECTION(ar, "set");
438 
439  // serialization of collection size
440  ipUInt32 size;
441  ar >> IPSDK_MAKE_IITEM_VALUE(size);
442 
443  // serialization of collection data
444  for (ipUInt32 i=0; i<size; ++i) {
445 
446  T key;
447  ar >> IPSDK_MAKE_IITEM_VALUE(key);
448  coll.insert(key);
449  }
450 
451  // end archive section
453 
454  // end archive section
455  IPSDK_END_ARCHIVE_SECTION(item._itemName);
456 
457  return ar;
458 }
459 
460 template <class T>
461 BaseOArchive&
462 operator<< (BaseOArchive& ar, const SerializationOItem<std::set<T> >& item)
463 {
464  // retrieve input collection
465  const std::set<T>& coll = item._value;
466 
467  // start a new archive section
468  IPSDK_START_ARCHIVE_SECTION(ar, item._itemName);
469 
470  // start a new archive section
471  IPSDK_START_ARCHIVE_SECTION(ar, "set");
472 
473  // serialization of collection size
474  ipUInt32 size = static_cast<ipUInt32>(coll.size());
475  ar << IPSDK_MAKE_OITEM_VALUE(size);
476 
477  // serialization of collection data
478  typename std::set<T>::const_iterator iter = coll.begin();
479  while (iter != coll.end()) {
480 
481  const T& key = *iter;
482  ar << IPSDK_MAKE_OITEM_VALUE(key);
483 
484  ++iter;
485  }
486 
487  // end archive section
489 
490  // end archive section
491  IPSDK_END_ARCHIVE_SECTION(item._itemName);
492 
493  return ar;
494 }
495 
497 
500 
503 template <class T>
504 BaseIArchive&
505 operator>> (BaseIArchive& ar, const SerializationIItem<std::deque<T> >& item)
506 {
507  // retrieve input collection
508  std::deque<T>& coll = item._value;
509 
510  // clear of input collection
511  coll.clear();
512 
513  // start a new archive section
514  IPSDK_START_ARCHIVE_SECTION(ar, item._itemName);
515 
516  // start a new archive section
517  IPSDK_START_ARCHIVE_SECTION(ar, "deque");
518 
519  // serialization of collection size
520  ipUInt32 size;
521  ar >> IPSDK_MAKE_IITEM_VALUE(size);
522  coll.resize(size);
523 
524  // serialization of collection data
525  typename std::deque<T>::iterator iter = coll.begin();
526  while (iter != coll.end()) {
527 
528  T& value = *iter;
529  ar >> IPSDK_MAKE_IITEM_VALUE(value);
530 
531  ++iter;
532  }
533 
534  // end archive section
535  IPSDK_END_ARCHIVE_SECTION("deque");
536 
537  // end archive section
538  IPSDK_END_ARCHIVE_SECTION(item._itemName);
539 
540  return ar;
541 }
542 
543 template <class T>
544 BaseOArchive&
545 operator<< (BaseOArchive& ar, const SerializationOItem<std::deque<T> >& item)
546 {
547  // retrieve input collection
548  const std::deque<T>& coll = item._value;
549 
550  // start a new archive section
551  IPSDK_START_ARCHIVE_SECTION(ar, item._itemName);
552 
553  // start a new archive section
554  IPSDK_START_ARCHIVE_SECTION(ar, "deque");
555 
556  // serialization of collection size
557  ipUInt32 size = static_cast<ipUInt32>(coll.size());
558  ar << IPSDK_MAKE_OITEM_VALUE(size);
559 
560  // serialization of collection data
561  typename std::deque<T>::const_iterator iter = coll.begin();
562  while (iter != coll.end()) {
563 
564  const T& value = *iter;
565  ar << IPSDK_MAKE_OITEM_VALUE(value);
566  ++iter;
567  }
568 
569  // end archive section
570  IPSDK_END_ARCHIVE_SECTION("deque");
571 
572  // end archive section
573  IPSDK_END_ARCHIVE_SECTION(item._itemName);
574 
575  return ar;
576 }
577 
579 
582 
585 template <class T, class U>
586 BaseIArchive&
587 operator>> (BaseIArchive& ar, const SerializationIItem<std::pair<T, U> >& item)
588 {
589  // retrieve input collection
590  std::pair<T, U>& p = item._value;
591 
592  // start a new archive section
593  IPSDK_START_ARCHIVE_SECTION(ar, item._itemName);
594 
595  // start a new archive section
596  IPSDK_START_ARCHIVE_SECTION(ar, "pair");
597 
598  T first;
599  U second;
600 
601  ar >> IPSDK_MAKE_IITEM_VALUE(first);
602  ar >> IPSDK_MAKE_IITEM_VALUE(second);
603 
604  p.first = first;
605  p.second = second;
606 
607  // end archive section
609 
610  // end archive section
611  IPSDK_END_ARCHIVE_SECTION(item._itemName);
612 
613  return ar;
614 }
615 
616 template <class T, class U>
617 BaseOArchive&
618 operator<< (BaseOArchive& ar, const SerializationOItem<std::pair<T, U> >& item)
619 {
620  // retrieve input collection
621  const std::pair<T, U>& p = item._value;
622 
623  // start a new archive section
624  IPSDK_START_ARCHIVE_SECTION(ar, item._itemName);
625 
626  // start a new archive section
627  IPSDK_START_ARCHIVE_SECTION(ar, "pair");
628 
629  const T& first = p.first;
630  const U& second = p.second;
631 
632  ar << IPSDK_MAKE_OITEM_VALUE(first);
633  ar << IPSDK_MAKE_OITEM_VALUE(second);
634 
635  // end archive section
637 
638  // end archive section
639  IPSDK_END_ARCHIVE_SECTION(item._itemName);
640 
641  return ar;
642 }
643 
645 
648 
649 } // end of namespace ipsdk
650 
651 #endif // __IPSDKSERIALIZATION_STLSERIALIZATIONOPERATORS_H__
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
#define IPSDK_END_ARCHIVE_SECTION(unUsed)
macro allowing to end an archive section
Definition: ArchiveSectionMacros.h:29
Serialization operators for basic types.
#define IPSDK_MAKE_IITEM_VALUE(value)
macro for SerializationIItem creation
Definition: SerializationIItemMacros.h:26
Macro set allowing to handle input object serialization.
Macro set allowing to handle input object serialization.
virtual void read(const SerializationIItem< BaseSerializationObject > &item)
read an object derived of base class
#define IPSDK_MAKE_OITEM_VALUE(value)
macro for SerializationOItem creation
Definition: SerializationOItemMacros.h:26
bool isTextArchive() const
method allowing to test whether archive is an human readable text archive
Definition: BaseArchive.h:98
Base class for serialization input archives.
Definition: BaseIArchive.h:36
#define IPSDK_START_ARCHIVE_SECTION(ar, sectionName)
macro allowing to star an archive section
Definition: ArchiveSectionMacros.h:23
Item used to format inputs during serialization.
Definition: DataItemNodeHdrMacrosDetails.h:42
IPSDKBASESHAPEANALYSIS_API ipsdk::BaseIArchive & operator>>(ipsdk::BaseIArchive &ar, const ipsdk::SerializationIItem< ipsdk::shape::analysis::MeasureId > &item)
serialization of ipsdk::shape::analysis::MeasureId structure
Definition of import/export macro for library.
uint32_t ipUInt32
Base types definition.
Definition: BaseTypes.h:53