root/juggler/branches/1.0/Config/vjChunkDesc.cpp

Revision 8789, 6.1 kB (checked in by patrickh, 7 years ago)

Copyright update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
2  *
3  * VR Juggler is (C) Copyright 1998, 1999, 2000, 2001, 2002
4  *   by Iowa State University
5  *
6  * Original Authors:
7  *   Allen Bierbaum, Christopher Just,
8  *   Patrick Hartling, Kevin Meinert,
9  *   Carolina Cruz-Neira, Albert Baker
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the
23  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24  * Boston, MA 02111-1307, USA.
25  *
26  * -----------------------------------------------------------------
27  * File:          $RCSfile$
28  * Date modified: $Date$
29  * Version:       $Revision$
30  * -----------------------------------------------------------------
31  *
32  *************** <auto-copyright.pl END do not edit this line> ***************/
33
34 #include <vjConfig.h>
35
36 #include <Config/vjChunkDesc.h>
37 #include <Config/vjParseUtil.h>
38 #include <Kernel/vjAssert.h>
39
40
41 vjChunkDesc::vjChunkDesc () :plist() {
42     validation = 1;
43     name = "unnamed";
44     token = "unnamed";
45     help = "";
46     vjPropertyDesc *d = new vjPropertyDesc("name",1,T_STRING," ");
47     add (d);
48 }
49
50
51
52 vjChunkDesc::vjChunkDesc (const vjChunkDesc& desc): plist() {
53     validation = 1;
54     *this = desc;
55 }
56
57
58
59 vjChunkDesc::~vjChunkDesc() {
60     /* XXX: Leave it for now
61     for (unsigned int i = 0; i < plist.size(); i++)
62         delete plist[i];
63     */
64     validation = 0;
65 }
66
67
68 #ifdef VJ_DEBUG
69 void vjChunkDesc::assertValid () const {
70     vjASSERT (validation == 1 && "Trying to use deleted vjChunkDesc");
71      for (unsigned int i = 0; i < plist.size(); i++)
72          plist[i]->assertValid();
73 }
74 #endif
75
76
77
78 vjChunkDesc& vjChunkDesc::operator= (const vjChunkDesc& other) {
79     assertValid();
80     other.assertValid();
81
82     unsigned int i;
83
84     if (&other == this)
85         return *this;
86
87     /* XXX: Leave it alone for now
88     for (i = 0; i < plist.size(); i++)
89     {
90        delete plist[i];
91        plist[i] = NULL;       // Overwrite dangling pointer
92     }
93     */
94     plist.clear();
95
96     name = other.name;
97     token = other.token;
98     help = other.help;
99
100     plist.reserve (other.plist.size());
101     for (i = 0; i < other.plist.size(); i++) {
102         //plist.push_back ( other.plist[i]);
103         plist.push_back ( new vjPropertyDesc(*(other.plist[i])));
104     }
105
106     return *this;
107 }
108
109
110
111 void vjChunkDesc::setName (const std::string& _name) {
112     assertValid();
113
114     name = _name;
115 }
116
117
118
119 void vjChunkDesc::setToken (const std::string& _token) {
120     assertValid();
121
122     token = _token;
123 }
124
125
126
127 void vjChunkDesc::setHelp (const std::string& _help) {
128     assertValid();
129
130     help = _help;
131 }
132
133
134
135 std::string vjChunkDesc::getName () {
136     assertValid();
137
138     return name;
139 }
140
141
142 std::string vjChunkDesc::getToken () {
143     assertValid();
144
145     return token;
146 }
147
148
149 std::string vjChunkDesc::getHelp () {
150     assertValid();
151
152     return help;
153 }
154
155
156 void vjChunkDesc::add (vjPropertyDesc *pd) {
157     assertValid();
158
159     remove(pd->getToken());
160     plist.push_back(pd);
161 }
162
163
164
165 vjPropertyDesc* vjChunkDesc::getPropertyDesc (const std::string& _token) {
166     assertValid();
167
168     for (unsigned int i = 0; i < plist.size(); i++)
169         if (!vjstrcasecmp (_token, plist[i]->getToken()))
170             return plist[i];
171     return NULL;
172 }
173
174
175
176 bool vjChunkDesc::remove (const std::string& _token)
177 {
178     assertValid();
179
180     std::vector<vjPropertyDesc*>::iterator cur_desc = plist.begin();
181     while (cur_desc != plist.end()) {
182         if (!vjstrcasecmp ((*cur_desc)->getToken(), _token)) {
183             /* XXX:
184                delete (*cur_desc);
185                *cur_desc = NULL;
186                */
187             cur_desc = plist.erase(cur_desc);
188             return true;
189         }
190         cur_desc++;
191     }
192     return false;
193 }
194
195
196
197 std::ostream& operator << (std::ostream& out, vjChunkDesc& self) {
198     self.assertValid();
199
200     out << self.token.c_str() << " \"" << self.name.c_str() << "\" \""
201         << self.help.c_str() << '"' << std::endl;
202     for (unsigned int i = 0; i < self.plist.size(); i++)
203         out << "  " << *(self.plist[i]) << std::endl;
204     out << "  end" << std::endl;
205     return out;
206 }
207
208
209 std::istream& operator >> (std::istream& in, vjChunkDesc& self)
210 {
211     self.assertValid();
212
213     const int buflen = 512;
214     char str[buflen];
215     vjPropertyDesc *p;
216    
217     readString (in, str, buflen);
218     self.token = str;
219
220     readString (in, str, buflen);
221     self.name = str;
222
223     readString (in, str, buflen);
224     self.help = str;
225
226     for (unsigned int i = 0; i < self.plist.size(); i++) {
227         /* XXX: Leave the memory for now.  Need to fix
228            delete self.plist[i];
229            self.plist[i] = NULL;                  // Get rid of dangling pointer
230         */
231     }
232     self.plist.clear();
233    
234     // this could use improvement
235     do {
236         p = new vjPropertyDesc();
237         in >> *p;
238         if (!vjstrcasecmp (p->getToken(),std::string("end"))) {
239             /* XXX:
240                delete p;
241             */
242             break;
243         }
244         self.add(p);
245     } while (!in.eof());
246    
247     if (!self.getPropertyDesc ("name"))
248         self.plist.insert (self.plist.begin(), new vjPropertyDesc("name",1,T_STRING," "));
249     return in;
250 }
251
252
253
254 //:equality operator
255 // a little stricter than it needs to be.. it shouldn't care about the order of
256 // propertydescs...
257 bool vjChunkDesc::operator== (const vjChunkDesc& d) {
258     assertValid();
259     d.assertValid();
260
261     if (vjstrcasecmp (token, d.token))
262         return false;
263     if (vjstrcasecmp (name, d.name))
264         return false;
265     if (plist.size() != d.plist.size())
266         return false;
267     for (unsigned int i = 0; i < plist.size(); i++)
268         if ((*plist[i]) != (*d.plist[i]))
269             return false;
270     return true;
271 }
Note: See TracBrowser for help on using the browser.