root/juggler/branches/1.0/Config/vjConfigChunkDB.h

Revision 8789, 9.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
35
36 #ifndef _VJ_CONFIGCHUNKDB_H_
37 #define _VJ_CONFIGCHUNKDB_H_
38
39 #include <vjConfig.h>
40 #include <Config/vjConfigChunk.h>
41
42
43 //------------------------------------------------------------------
44 //: Database of ConfigChunks
45 //
46 // The vjConfigChunkDB is a general-purpose container for
47 // ConfigChunks, with functionality for reading/writing
48 // files of ConfigChunks and querying for sets of configchunks
49 // with specific properties.
50 //
51 // @author Christopher Just
52 // October 1997
53 //
54 //!PUBLIC_API:
55 //------------------------------------------------------------------
56 class vjConfigChunkDB {
57
58 private:
59     //: vector of ConfigChunks
60     std::vector<vjConfigChunk*> chunks;
61
62     //: name of the file this DB was loaded from - used for includes
63     std::string file_name;
64
65 public:
66
67     typedef std::vector<vjConfigChunk*>::iterator iterator;
68
69     iterator begin() {
70         return chunks.begin();
71     }
72
73     iterator end() {
74         return chunks.end();
75     }
76
77     //: Constructor
78     //! PRE: true
79     //! POST: self is created. Chunks is empty.
80     vjConfigChunkDB ();
81
82
83
84     //: Copy constructor
85     vjConfigChunkDB (vjConfigChunkDB& db);
86
87
88
89     //: Destructor
90     //! PRE: true
91     //! POST: self is destroyed and its associated memory freed.
92     //+       This includes all ConfigChunks stored in self, but
93     //+       not any ChunkDescDB
94     ~vjConfigChunkDB ();
95
96
97
98     //: Assignment operator
99     vjConfigChunkDB& operator = (vjConfigChunkDB& db);
100
101
102
103     //: Checks if self is empty
104     //! RETURNS: true - if self contains no vjConfigChunks
105     //! RETURNS: false - otherwise
106     bool isEmpty();
107
108
109
110     //: Removes and destroys all vjConfigChunks in self
111     //! PRE: true
112     //! POST: All ConfigChunks in self have been removed and their
113     //+       associated memory freed.
114     void removeAll();
115
116
117
118     /* accessing individual chunks:  We ought to be able to do this by:
119      *   1. giving a name of a specific chunk
120      *   2. getting all the chunks of a specific type, or at least the
121      *      names of all the chunks of a specific type.
122      *      Maybe just a vector of names?
123      */
124
125
126
127     //: Finds a chunk with a given name
128     //! PRE: true
129     //! ARGS: name - a non-NULL C string.
130     //! RETURNS: p - A pointer to a ConfigChunk in self whose name matches
131     //+          the argument, or NULL if no such element exists.
132     //! NOTE: The memory associated with the return value belongs to
133     //+       the ConfigChunkDB, and should not be delete()d
134     vjConfigChunk *getChunk (const std::string& name);
135
136
137     //: return a vector of all the chunks
138     //! POST: returns
139     //! RETURNS: Copy of the pointers to the chunks in this.
140     std::vector<vjConfigChunk*> getChunks();
141
142
143
144     //: Add chunks to self
145     //! POST: self has added copies of all chunks in new_chunks
146     void addChunks(std::vector<vjConfigChunk*> new_chunks);
147
148
149
150     //: Add chunks to self
151     //! PRE: db is non-null.
152     //! POST: self has added copies of all chunks in db.
153     void addChunks(vjConfigChunkDB *db);
154
155
156
157     //: Adds a chunk to this
158     void addChunk(vjConfigChunk* new_chunk);
159
160
161
162     //: Returns all chunks of a given type.
163     //! PRE: true;
164     //! POST: true;
165     //! ARGS: property - a non-NULL C string, the name of a property.
166     //! ARGS: value - value of a property.  non-NULL C string.
167     //! RETURNS: p - Pointer to a vector of ConfigChunk* containing
168     //+          all vjConfigChunks in self that have the specified
169     //+          type (ie vjChunkDesc token).
170     //! NOTE: The memory for the vector should be deleted by the
171     //+       caller when it is no longer needed.  The individual
172     //+       vjConfigChunks in the vector should not be freed.
173     std::vector<vjConfigChunk*>* getMatching (const std::string& mytypename) {
174         return getMatching ("type", mytypename);
175     }
176
177
178
179     //: Returns all chunks with a given property and value.
180     //! PRE: true
181     //! ARGS: property - a non-NULL C string, the name of a property.
182     //! ARGS: value - value of a property.  If char*, must be non-NULL
183     //! RETURNS: p - Pointer to a vector of ConfigChunk* containing
184     //+          all ConfigChunks in self that have a property whose
185     //+          name matches the first argument and which has as
186     //+          one of its values the value given in the second
187     //+          argument.
188     //! NOTE: The memory for the vector should be deleted by the
189     //+       caller when it is no longer needed.  The individual
190     //+       ConfigChunks in the vector should not be freed.
191     std::vector<vjConfigChunk*>* getMatching (const std::string& property, const std::string value);
192     std::vector<vjConfigChunk*>* getMatching (const std::string& property, int value);
193     std::vector<vjConfigChunk*>* getMatching (const std::string& property, float value);
194
195
196
197     //: Alias for removeAll()
198     bool erase ();
199
200
201
202     //: Removes the named chunk
203     //! POST: If a ConfigChunk with the specified name exists
204     //+       in self, it is removed and its memory freed.
205     //! RETURNS: true - a matching chunk was found.
206     //! RETURNS: false - otherwise.
207     int removeNamed (const std::string& name);
208
209
210
211     //: Removes all chunks with a matching property and value
212     //! PRE: true
213     //! POST: All selected ConfigChunks in self are removed and
214     //+       their memory freed.  The selection criteria is
215     //+       the same as for getMatching(property, value)
216     //! ARGS: property - Name of a property. Non-NULL C string.
217     //! ARGS: value - value to match.  If char*, must be non-NULL
218     //+       C string.
219     //! RETURNS: n - Number of ConfigChunks removed.
220     int removeMatching (const std::string& property, int value);
221     int removeMatching (const std::string& property, float value);
222     int removeMatching (const std::string& property, const std::string& value);
223
224
225
226     //: Sorts the chunks based on dependencies
227     //! PRE: true
228     //! MODIFIES: self.  In place sort of the config chunks
229     //! ARGS: auxChunks - Auxilary chunks that have been loaded already
230     //! POST: (if returns != -1)
231     //+     for( i>=0 && i<chunks.size()) <br>
232     //+        chunks[i] dependent only of chunks[0...(i-1)] <br>
233     //+     This is a topological sorting of the dependencies. <br>
234     //+     informally( forall elts in the chunks list ) <br>
235     //! RETURNS: -1 - Failed to complete sort
236     int dependencySort(vjConfigChunkDB* auxChunks = NULL);
237
238
239     /* IO functions: */
240
241     //! POST: A text representation of self is written to out
242     //! ARGS: out - an output stream
243     //! ARGS: self - a ConfigChunkDB
244     //! RETURNS: out
245     friend std::ostream& operator << (std::ostream& out, vjConfigChunkDB& self);
246
247
248
249     //! POST: ConfigChunks are read from in and added to self until
250     //+       an 'end' token or EOF is read.
251     //! ARGS: in - an input stream.
252     //! ARGS: self - a ConfigChunkDB.
253     //! RETURNS: in
254     //! NOTE: Any ConfigChunks in self before the >> operation remain,
255     //+       unless they have the same name as a newly read chunk
256     //+       in which case they are replaced by the newer chunks.
257     friend std::istream& operator >> (std::istream& in, vjConfigChunkDB& self);
258
259
260
261     //: loads ConfigChunks from the given file
262     //! ARGS: fname - name of file to read from.
263     //! RETURNS: true - file was opened succesfully.
264     //! RETURNS: false - otherwise.
265     //! NOTE: This function calls operator >> to do its work.
266     //! NOTE: The return value only considers opening the file,
267     //+       and does not account for parsing or other reading
268     //+       errors.
269     bool load (const std::string& fname, const std::string& parentfile = "");
270
271
272
273     //: writes ConfigChunks to the given file
274     //! ARGS: fname - name of file to write to.
275     //! RETURNS: true - file was opened succesfully.
276     //! RETURNS: false - otherwise.
277     //! NOTE: This function calls operator << to do its work.
278     bool save (const std::string& fname);
279
280 };
281
282
283 #endif
Note: See TracBrowser for help on using the browser.