InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PersistK2Types.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Abhishek Gulati
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //========================================================================================
23 
24 
25 #ifndef __PersistK2__
26 #define __PersistK2__
27 
28 #include "IPMStream.h"
29 #include "K2Pair.h"
30 #include "KeyValuePair.h"
31 #include "K2Vector.h"
32 
41 namespace Persist
42 {
43 
47  template <typename _T1, typename _T2>
48  struct Serializer < K2Pair<_T1, _T2> >
49  {
50  inline static void Read (IPMStream* stream, K2Pair<_T1, _T2>& p)
51  {
52  ASSERT (stream && stream->IsReading());
53 
54  Persist::Read (stream, p.first);
55  Persist::Read (stream, p.second);
56  }
57 
58  inline static void Write (IPMStream* stream, const K2Pair<_T1, _T2>& p)
59  {
60  ASSERT (stream && stream->IsWriting());
61 
62  Persist::Write (stream, p.first);
63  Persist::Write (stream, p.second);
64  }
65  };
66 
70  template <typename _T1, typename _T2>
71  struct Serializer < KeyValuePair<_T1, _T2> >
72  {
73  inline static void Read (IPMStream* stream, KeyValuePair<_T1, _T2>& p)
74  {
75  ASSERT (stream && stream->IsReading());
76 
77  Persist::Read (stream, p.fKey);
78  Persist::Read (stream, p.fValue);
79  }
80 
81  inline static void Write (IPMStream* stream, const KeyValuePair<_T1, _T2>& p)
82  {
83  ASSERT (stream && stream->IsWriting());
84 
85  Persist::Write (stream, p.fKey);
86  Persist::Write (stream, p.fValue);
87  }
88  };
89 
93  template <typename T>
94  struct Serializer < K2Vector<T> >
95  {
96  inline static void Read (IPMStream* stream, K2Vector<T>& v)
97  {
98  ASSERT (stream && stream->IsReading());
99 
100  v.clear();
101 
102  int32 size;
103  Persist::Read (stream, size);
104 
105  T t{};
106  v.resize(size, t);
107  for (typename K2Vector<T>::iterator i = v.begin(); i != v.end(); ++i)
108  {
109  Persist::Read(stream, *i);
110  }
111  }
112 
113  inline static void Write (IPMStream* stream, const K2Vector<T>& v)
114  {
115  ASSERT (stream && stream->IsWriting());
116 
117  const int32 size = v.size();
118  Persist::Write (stream, size);
119 
120  for (typename K2Vector<T>::const_iterator i = v.begin(); i != v.end(); ++i)
121  {
122  Persist::Write(stream, *i);
123  }
124  }
125  };
126 }
127 
128 #endif