root/juggler/branches/1.0/Config/vjConfigChunk.h
| Revision 8789, 8.9 kB (checked in by patrickh, 7 years ago) | |
|---|---|
| |
| 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 | #ifndef _VJ_CONFIGCHUNK_H_ |
| 36 | #define _VJ_CONFIGCHUNK_H_ |
| 37 | |
| 38 | #include <vjConfig.h> |
| 39 | #include <Config/vjChunkDesc.h> |
| 40 | #include <Config/vjProperty.h> |
| 41 | #include <Config/vjVarValue.h> |
| 42 | |
| 43 | #ifdef VJ_OS_HPUX |
| 44 | # include <float.h> |
| 45 | # include <stddef.h> |
| 46 | #endif |
| 47 | |
| 48 | |
| 49 | |
| 50 | struct VJCFGToken; |
| 51 | |
| 52 | |
| 53 | //------------------------------------------------------------------ |
| 54 | //: A container for configuration information |
| 55 | // |
| 56 | // A vjConfigChunk stores a number of vjPropertys that describe |
| 57 | // the configuration of a particular component of the system. |
| 58 | // It has an associated vjChunkDesc which describes its type |
| 59 | // and the vjPropertys that belong to it. |
| 60 | // |
| 61 | // @author Christopher Just |
| 62 | // |
| 63 | //!PUBLIC_API: |
| 64 | //------------------------------------------------------------------ |
| 65 | class vjConfigChunk { |
| 66 | |
| 67 | private: |
| 68 | vjChunkDesc* desc; |
| 69 | std::vector<vjProperty*> props; // Stores the set of properties |
| 70 | vjVarValue type_as_varvalue; |
| 71 | unsigned int validation; // flag for testing validity of self |
| 72 | |
| 73 | public: |
| 74 | |
| 75 | //: Constructs a vjConfigChunk with no given description. |
| 76 | //! NOTE: a ConfigChunk created with this function is essentially |
| 77 | //+ useless until a description has been assigned with |
| 78 | //+ associateDesc() or the Chunk is assigned into with =, |
| 79 | //+ but I want this so I can have vectors of |
| 80 | //+ ConfigChunks, instead of ptrs... |
| 81 | vjConfigChunk (); |
| 82 | |
| 83 | |
| 84 | //: Constructs a vjConfigChunk matching the given description. |
| 85 | //!PRE: desc points to a valid vjChunkDesc |
| 86 | //!POST: self has been created, and all its vjPropertys |
| 87 | //+ initialized to their default values. |
| 88 | vjConfigChunk (vjChunkDesc *_desc); |
| 89 | |
| 90 | |
| 91 | |
| 92 | //: Destroys a vjConfigChunk and all related memory. |
| 93 | //!POST: self has been destroyed, and all memory associated |
| 94 | //+ with it and its properties is freed (but not the |
| 95 | //+ memory associated with its vjChunkDesc). |
| 96 | ~vjConfigChunk (); |
| 97 | |
| 98 | |
| 99 | vjConfigChunk (const vjConfigChunk& c); |
| 100 | |
| 101 | |
| 102 | #ifdef VJ_DEBUG |
| 103 | void assertValid () const; |
| 104 | #else |
| 105 | inline void assertValid () const { |
| 106 | ; |
| 107 | } |
| 108 | #endif |
| 109 | |
| 110 | //: Associates the description d with this Chunk |
| 111 | //!NOTE: When this function is called, any previous properties etc. |
| 112 | //+ of this Chunk are destroyed, and new (blank) properties are |
| 113 | //+ created. |
| 114 | void associateDesc (vjChunkDesc* d); |
| 115 | |
| 116 | |
| 117 | vjConfigChunk& operator = (const vjConfigChunk& c); |
| 118 | |
| 119 | |
| 120 | |
| 121 | //: tests for equality of two vjConfigChunks |
| 122 | bool operator == (const vjConfigChunk& c) const; |
| 123 | |
| 124 | //: tests for inequality of two vjConfigChunks |
| 125 | inline bool operator != (const vjConfigChunk& c) const { |
| 126 | return !(*this == c); |
| 127 | } |
| 128 | |
| 129 | |
| 130 | //: Compares two vjConfigChunks based on their instance names |
| 131 | bool operator < (const vjConfigChunk& c) const; |
| 132 | |
| 133 | |
| 134 | |
| 135 | //: writes self to out |
| 136 | //!POST: self is written to out. Format is as defined |
| 137 | //+ in the ConfigFileFormats document. |
| 138 | //!RETURNS: out - the output stream |
| 139 | //!ARGS: out - a valid ostream. |
| 140 | //!ARGS: self - a valid vjConfigChunk |
| 141 | friend std::ostream& operator << (std::ostream& out, vjConfigChunk& self); |
| 142 | |
| 143 | |
| 144 | |
| 145 | //: reads a value from in |
| 146 | //!POST: the value of self is changed based on what is |
| 147 | //+ read from in. |
| 148 | //!RETURNS: in - the input stream |
| 149 | //!ARGS: in - a valid input stream |
| 150 | //!ARGS: self - a valid vjConfigChunk |
| 151 | friend std::istream& operator >> (std::istream& in, vjConfigChunk& self); |
| 152 | |
| 153 | |
| 154 | |
| 155 | //: Returns the name of a chunk's type. |
| 156 | //!RETURNS: s - a C string containing the token for this |
| 157 | //+ chunk's vjChunkDesc. |
| 158 | //!NOTE: this is the same as a call of getProperty ("type",0) |
| 159 | const vjVarValue& getType () const; |
| 160 | |
| 161 | |
| 162 | |
| 163 | //: returns number of values for the named property |
| 164 | //!ARGS: property - a non-NULL C string; the name of a property |
| 165 | //!RETURNS: n - the number of values contained by the named |
| 166 | //+ property. (could be 0) |
| 167 | //!RETURNS: 0 - if self does not contain a property with the |
| 168 | //+ given name. |
| 169 | //!NOTE: This should always be used before looking at any |
| 170 | //+ vjProperty that can have a variable number of values. |
| 171 | int getNum (const std::string& property) const; |
| 172 | |
| 173 | |
| 174 | |
| 175 | //: Returns one of the values for a given property. |
| 176 | //!ARGS: property - a non-NULL C string, the token of a property |
| 177 | //!ARGS: ind - an integer index, in the range from 0 to |
| 178 | //+ getNum(property) -1. Determines which of the |
| 179 | //+ values in the vjProperty to return. |
| 180 | //!RETURNS: v - a vjVarValue that can be cast directly if |
| 181 | //+ its type is known (float, int, etc). |
| 182 | const vjVarValue& getProperty (const std::string& property, int ind = 0) const; |
| 183 | |
| 184 | |
| 185 | //: Return all the values for a given property |
| 186 | // This is just a simple helper function |
| 187 | //! NOTE: The vector has COPIES of the var values. |
| 188 | std::vector<vjVarValue*> getAllProperties(const std::string& property); |
| 189 | |
| 190 | |
| 191 | //: Sets a value for the given property. |
| 192 | //!PRE: property is a non-null string, ind >= 0. |
| 193 | //!POST: If the named property is in self, and if the index |
| 194 | //+ given is valid, and the types match, then val is |
| 195 | //+ assigned to that value of that property |
| 196 | //!RETURNS: true - succesful assignment |
| 197 | //!RETURNS: false - failed assignment (type mismatch, |
| 198 | //+ no such property, invalid index, etc.) |
| 199 | //!NOTE: if ind is higher than the number of values in the |
| 200 | //+ property, but the property allows a variable number |
| 201 | //+ of values, the property will be padded with values |
| 202 | //+ so that the assignment can occure. |
| 203 | //+ <p>The char* version of setProperty allocates its |
| 204 | //+ own copy of the string value argument. |
| 205 | bool setProperty (const std::string& property, int val, int ind=0); |
| 206 | bool setProperty (const std::string& property, float val, int ind=0); |
| 207 | bool setProperty (const std::string& property, const std::string& val, int ind=0); |
| 208 | bool setProperty (const std::string& property, vjConfigChunk *val, int ind=0); |
| 209 | |
| 210 | |
| 211 | |
| 212 | //: Appends val to the set of values for the named vjProperty |
| 213 | //!NOTE: This can be considered a convenience function for |
| 214 | //+ "setValue (property, val, getNum(property))" |
| 215 | //!ARGS: property - non-NULL C string, token for a property. |
| 216 | //!ARGS: val - a value to be appended to the named property. |
| 217 | //!POST: The given vjProperty has the new value appended to |
| 218 | //+ the end of its list of values. |
| 219 | //!RETURNS: true - success |
| 220 | //!RETURNS: false - failure. (no such property, or it |
| 221 | //+ does exist but has a fixed number of values |
| 222 | bool addValue (const std::string& property, int val); |
| 223 | bool addValue (const std::string& property, float val); |
| 224 | bool addValue (const std::string& property, const std::string& val); |
| 225 | bool addValue (const std::string& property, vjConfigChunk* val); |
| 226 | |
| 227 | //: check to see if a property exists within a config chunk. |
| 228 | inline bool doesPropertyExistFromToken( const std::string& token ) const |
| 229 | { |
| 230 | return (this->getPropertyPtrFromToken( token ) != NULL); |
| 231 | } |
| 232 | |
| 233 | //: Return a list of chunk names dependant based on chunk ptrs |
| 234 | // Returns a list of the names of all the chunks |
| 235 | // that are pointed to by chunk ptrs of this chunk |
| 236 | std::vector<std::string> getChunkPtrDependencies() const; |
| 237 | |
| 238 | private: |
| 239 | vjProperty *getPropertyPtrFromName (const std::string& name) const; |
| 240 | |
| 241 | vjProperty *getPropertyPtrFromToken (const std::string& token) const; |
| 242 | |
| 243 | //: Attempts to assign a value (in tok) to the vjProperty's ith value. |
| 244 | //!NOTE: This function does a certain amount of type-mangling, and also |
| 245 | //+ handles enumeration lookups. Return value is success/failure. |
| 246 | bool tryassign (vjProperty *p, int i, const char* val); |
| 247 | |
| 248 | }; |
| 249 | |
| 250 | #endif |
| 251 | |
| 252 | |
| 253 |
Note: See TracBrowser for help on using the browser.
