root/juggler/branches/1.0/Config/vjProperty.h
| Revision 8789, 6.8 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 | |
| 36 | #ifndef _VJ_PROPERTY_H_ |
| 37 | #define _VJ_PROPERTY_H_ |
| 38 | |
| 39 | #include <vjConfig.h> |
| 40 | #include <Config/vjVarValue.h> |
| 41 | #include <Config/vjPropertyDesc.h> |
| 42 | class vjChunkDesc; |
| 43 | |
| 44 | |
| 45 | //------------------------------------------------------------------ |
| 46 | //: Stores a property and all its values |
| 47 | // |
| 48 | // Unit of storage inside a vjConfigChunk. Has a name, type, |
| 49 | // and 0 or more values. Some vjPropertys have a fixed number |
| 50 | // of values (e.g. to store the three components of a point |
| 51 | // in 3space), while others have a variable number (e.g. to |
| 52 | // store a list of active devices) |
| 53 | // <p>Each instance is associated with |
| 54 | // a vjPropertyDesc at instantiation; this associated cannot |
| 55 | // be changed. |
| 56 | // <p>Note that the Property instance maintains a pointer to |
| 57 | // the PropertyDesc, so be careful. |
| 58 | // |
| 59 | // <p>author: Christopher Just |
| 60 | // |
| 61 | //------------------------------------------------------------------ |
| 62 | //!PUBLIC_API: |
| 63 | class vjProperty { |
| 64 | |
| 65 | private: |
| 66 | |
| 67 | //: Pointer to this vjProperty's description. |
| 68 | vjPropertyDesc *description; |
| 69 | |
| 70 | //: Type of value entries. |
| 71 | VarType type; |
| 72 | |
| 73 | //: A unit, if type is T_DISTANCE. (not fully functional) |
| 74 | CfgUnit units; |
| 75 | |
| 76 | unsigned int validation; // flag for testing validity of self |
| 77 | |
| 78 | public: |
| 79 | |
| 80 | //: Number of values. -1 for variable number (use getNum() ) |
| 81 | int num; |
| 82 | |
| 83 | //: Vector containing the actual vjVarValues. |
| 84 | std::vector<vjVarValue*> value; |
| 85 | |
| 86 | //: ChunkDesc for embedded chunk (if valtype is T_EMBEDDEDCHUNK) |
| 87 | vjChunkDesc *embeddesc; |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | //: Constructor |
| 93 | //! PRE: true |
| 94 | //! POST: Property is created. If num values is not -1, num |
| 95 | //+ vjVarValues are created and placed in value. |
| 96 | //+ Otherwise, value is left empty. |
| 97 | //! ARGS: pd - a pointer to a valid vjPropertyDesc. |
| 98 | //! NOTE: Self stores a pointer to its PropertyDesc pd. pd |
| 99 | //+ should not be deleted while self exists. |
| 100 | vjProperty (vjPropertyDesc *pd); |
| 101 | |
| 102 | |
| 103 | |
| 104 | //: Destructor |
| 105 | //! PRE: true |
| 106 | //! POST: self and its stored values are destroyed (but not |
| 107 | //+ the PropertyDesc!) |
| 108 | ~vjProperty (); |
| 109 | |
| 110 | |
| 111 | |
| 112 | vjProperty (const vjProperty& p); |
| 113 | |
| 114 | |
| 115 | |
| 116 | #ifdef VJ_DEBUG |
| 117 | void assertValid () const; |
| 118 | #else |
| 119 | inline void assertValid () const { |
| 120 | ; |
| 121 | } |
| 122 | #endif |
| 123 | |
| 124 | |
| 125 | |
| 126 | vjProperty& operator= (const vjProperty& p); |
| 127 | |
| 128 | |
| 129 | |
| 130 | bool operator== (const vjProperty& p) const; |
| 131 | inline bool operator != (const vjProperty& p) const { |
| 132 | return !(*this == p); |
| 133 | } |
| 134 | |
| 135 | |
| 136 | //: Returns actual current number of values in self |
| 137 | //! RETURNS: n - size of value vector. |
| 138 | int getNum () const; |
| 139 | |
| 140 | inline bool hasFixedNumberOfValues () const { |
| 141 | return (num >= 0); |
| 142 | } |
| 143 | |
| 144 | inline VarType getType () const { |
| 145 | return type; |
| 146 | } |
| 147 | |
| 148 | const std::string& getName () const; |
| 149 | |
| 150 | |
| 151 | const std::string& getToken () const; |
| 152 | |
| 153 | |
| 154 | //: Returns the VarValue at index |
| 155 | //! PRE: True |
| 156 | //! ARGS: ind - integer index of value to return (default 0) |
| 157 | //! RETURNS: v - indth element of value, or a T_INVALID VarValue |
| 158 | //+ if ind is out of bounds |
| 159 | vjVarValue& getValue (unsigned int ind = 0); |
| 160 | |
| 161 | |
| 162 | |
| 163 | //: set the value at ind |
| 164 | //! PRE: true |
| 165 | //! POST: the indth value of self is set to val, if ind is |
| 166 | //+ a valid index to self's value vector. If self has |
| 167 | //+ a variable number of values and ind is greater than |
| 168 | //+ the current number of values, the value vector will |
| 169 | //+ be padded with VarValues of the appropriate type |
| 170 | //+ (with default values). |
| 171 | //! NOTE: If the argument can't be assigned because of type |
| 172 | //+ mismatch, the value at ind won't be changed. |
| 173 | //+ See vjVarValue::= to see what happens. Padding |
| 174 | //+ of the value vector may still occur. |
| 175 | //! ARGS: val - value to assign. If char*, must be a valid |
| 176 | //+ non-NULL C string. |
| 177 | //! ARGS: ind - integer index to value vector |
| 178 | bool setValue (int val, int ind = 0); |
| 179 | bool setValue (float val, int ind = 0); |
| 180 | bool setValue (const std::string& val, int ind = 0); |
| 181 | bool setValue (vjConfigChunk* val, int ind = 0); |
| 182 | bool setValue (vjVarValue& val, int ind = 0); |
| 183 | |
| 184 | |
| 185 | inline vjEnumEntry* getEnumEntry (const std::string& n) const { |
| 186 | assertValid(); |
| 187 | return description->getEnumEntry (n); |
| 188 | } |
| 189 | vjEnumEntry* getEnumEntryWithValue (int val) const; |
| 190 | |
| 191 | |
| 192 | //: creates a vjVarValue of the correct type for this property |
| 193 | //! ARGS: i - position of this value. Useful for giving |
| 194 | //+ embedded chunks names based on valuelabels. |
| 195 | vjVarValue *createVarValue (int i = -1); |
| 196 | |
| 197 | |
| 198 | /** Converts the values in this property from units of u to units of feet. |
| 199 | * This is used when we're reading in a new distance property - The |
| 200 | * values have been read in as raw numbers, then we read in the unit type |
| 201 | * and realize what kind of conversion we have to do to put them in |
| 202 | * feet (our standard unit for internal storage of distances). |
| 203 | */ |
| 204 | bool applyUnits (CfgUnit u); |
| 205 | |
| 206 | |
| 207 | //: writes p to out |
| 208 | friend std::ostream& operator << (std::ostream &out, vjProperty& p); |
| 209 | |
| 210 | |
| 211 | |
| 212 | private: |
| 213 | |
| 214 | //: Utility function for setValue(val, ind) functions |
| 215 | //! POST: If self has a variable number of values, and ind |
| 216 | //+ is greater than the current size of the value |
| 217 | //+ vector, the vector is padded with new default-valued |
| 218 | //+ vjVarValues. |
| 219 | //! RETURNS: true if ind is a valid index to the values vector |
| 220 | //+ (after padding). |
| 221 | //! RETURNS: false if ind is out of bounds. |
| 222 | //! ARGS: ind - index into the values vector. |
| 223 | bool preSet (unsigned int index); |
| 224 | |
| 225 | }; |
| 226 | |
| 227 | |
| 228 | #endif |
| 229 | |
| 230 |
Note: See TracBrowser for help on using the browser.
