blob: 377ed9382083376295b19ce383b9b226e9ea14b1 [file] [log] [blame]
Emeric Vigier2f625822012-08-06 11:09:52 -04001// Copyright (C) 2002-2003 Chad C. Yates cyates@uidaho.edu
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation; either version 2 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16//
17// As a special exception to the GNU General Public License, permission is
18// granted for additional uses of the text contained in its release
19// of Common C++.
20//
21// The exception is that, if you link the Common C++ library with other
22// files to produce an executable, this does not by itself cause the
23// resulting executable to be covered by the GNU General Public License.
24// Your use of that executable is in no way restricted on account of
25// linking the Common C++ library code into it.
26//
27// This exception does not however invalidate any other reasons why
28// the executable file might be covered by the GNU General Public License.
29//
30// This exception applies only to the code released under the
31// name Common C++. If you copy code from other releases into a copy of
32// Common C++, as the General Public License permits, the exception does
33// not apply to the code that you add in this way. To avoid misleading
34// anyone as to the status of such modified files, you must delete
35// this exception notice from them.
36//
37// If you write modifications of your own for Common C++, it is your choice
38// whether to permit this exception to apply to your modifications.
39// If you do not wish that, delete this exception notice.
40
41#include "SampleObject.h"
42
43IMPLEMENT_PERSISTENCE(Test,"Test")
44
45Test::Test()
46: iInteger(0), strString("Null"), strString2("Null")
47{
48 nullPtr = NULL;
49 //uninitializedNullPtr; // to test whether unpersisting a non constructed NULL var works.
50 subObjectPtr = NULL;
51 subObjectPtr2 = subObjectPtr; // points to the same thing as subObjectPtr for testing
52}
53
54Test::Test(Test &ob)
55{
56 iInteger = ob.iInteger;
57 strString = ob.strString;
58}
59
60bool Test::operator==(const Test &ob) const
61{
62 return
63 iInteger == ob.iInteger &&
64 strString == ob.strString &&
65 strString2 == ob.strString2 &&
66 numbers == ob.numbers &&
67 strings == ob.strings &&
68 moreStrings == ob.moreStrings &&
69 nullPtr == ob.nullPtr &&
70 uninitializedNullPtr == ob.uninitializedNullPtr &&
71 *subObjectPtr == *ob.subObjectPtr &&
72 *subObjectPtr2 == *ob.subObjectPtr2 &&
73 subObjectRef == ob.subObjectRef &&
74 subObjects == ob.subObjects;
75}
76
77bool Test::write(Engine& archive) const
78{
79 archive << iInteger << strString << strString2;
80 archive << numbers;
81 archive << strings;
82 archive << nullPtr;
83 archive << uninitializedNullPtr;
84 archive << subObjectPtr;
85 archive << subObjectPtr2;
86 archive << subObjectRef;
87 archive << moreStrings;
88 archive << subObjects;
89
90 return true;
91}
92
93bool Test::read(Engine& archive)
94{
95 archive >> iInteger >> strString >> strString2;
96 archive >> numbers;
97 archive >> strings;
98 archive >> nullPtr;
99 archive >> uninitializedNullPtr;
100 archive >> subObjectPtr;
101 archive >> subObjectPtr2;
102 archive >> subObjectRef;
103 archive >> moreStrings;
104 archive >> subObjects;
105
106 return true;
107}
108
109void Test::print(const std::string& name)
110{
111 cout <<
112 name << ":\n" <<
113 " iInteger: " << iInteger << endl <<
114 " strString: '" << strString << "'" << endl <<
115 " strString2: '" << strString2 << "'" << endl;
116
117 cout <<
118 " numbers: ";
119 std::copy(numbers.begin(), numbers.end(), std::ostream_iterator<double>(cout, " "));
120 cout << endl;
121
122 cout <<
123 " strings: ";
124 std::copy(strings.begin(), strings.end(), std::ostream_iterator<string>(cout, " "));
125 cout << endl;
126
127 cout <<
128 " moreStrings: ";
129 std::copy(moreStrings.begin(), moreStrings.end(), std::ostream_iterator<string>(cout, " "));
130 cout << endl;
131
132 subObjectPtr->print("subObjectPtr");
133 subObjectPtr2->print("subObjectPtr2");
134 subObjectRef.print("subObjectRef");
135
136 cout <<
137 "\nsubObjects (deque):\n";
138 for (std::deque<TestSub>::const_iterator i = subObjects.begin(); i != subObjects.end(); ++i)
139 i->print("element in deque");
140 cout << endl;
141
142 cout << "====================================\n\n";
143}
144