root/juggler/tags/1.0_alpha_02/Config/vjProperty.h
| Revision 191, 4.2 kB (checked in by cjust, 10 years ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | |
| 2 | #ifndef _VJ_PROPERTY_H_ |
| 3 | #define _VJ_PROPERTY_H_ |
| 4 | |
| 5 | #include <Config/vjVarValue.h> |
| 6 | #include <Config/vjChunkDesc.h> |
| 7 | |
| 8 | |
| 9 | //------------------------------------------------------------------ |
| 10 | //: Stores a property and all its values |
| 11 | // |
| 12 | // Unit of storage inside a vjConfigChunk. Has a name, type, |
| 13 | // and 0 or more values. Some vjPropertys have a fixed number |
| 14 | // of values (e.g. to store the three components of a point |
| 15 | // in 3space), while others have a variable number (e.g. to |
| 16 | // store a list of active devices) |
| 17 | // <p>Each instance is associated with |
| 18 | // a vjPropertyDesc at instantiation; this associated cannot |
| 19 | // be changed. |
| 20 | // <p>Note that the Property instance maintains a pointer to |
| 21 | // the PropertyDesc, so be careful. |
| 22 | // |
| 23 | // <p>author: Christopher Just |
| 24 | // |
| 25 | //------------------------------------------------------------------ |
| 26 | class vjProperty { |
| 27 | |
| 28 | public: |
| 29 | |
| 30 | //: Pointer to this vjProperty's description. |
| 31 | vjPropertyDesc *description; |
| 32 | |
| 33 | //: Name of the vjProperty (shortcut for description->name) |
| 34 | char *name; |
| 35 | |
| 36 | //: Number of values. -1 for variable number (use getNum() ) |
| 37 | int num; |
| 38 | |
| 39 | //: Type of value entries. |
| 40 | VarType type; |
| 41 | |
| 42 | //: A unit, if type is T_DISTANCE. (not fully functional) |
| 43 | CfgUnit units; |
| 44 | |
| 45 | //: Vector containing the actual vjVarValues. |
| 46 | vector<vjVarValue*> value; |
| 47 | |
| 48 | |
| 49 | |
| 50 | //: Constructor |
| 51 | //! PRE: true |
| 52 | //! POST: Property is created. If num values is not -1, num |
| 53 | //+ vjVarValues are created and placed in value. |
| 54 | //+ Otherwise, value is left empty. |
| 55 | //! ARGS: pd - a pointer to a valid vjPropertyDesc. |
| 56 | //! NOTE: Self stores a pointer to its PropertyDesc pd. pd |
| 57 | //+ should not be deleted while self exists. |
| 58 | vjProperty (vjPropertyDesc *pd); |
| 59 | |
| 60 | |
| 61 | |
| 62 | //: Destructor |
| 63 | //! PRE: true |
| 64 | //! POST: self and its stored values are destroyed (but not |
| 65 | //+ the PropertyDesc!) |
| 66 | ~vjProperty (); |
| 67 | |
| 68 | |
| 69 | //: Returns actual current number of values in self |
| 70 | //! RETURNS: n - size of value vector. |
| 71 | int getNum (); |
| 72 | |
| 73 | |
| 74 | |
| 75 | //: Returns the VarValue at index |
| 76 | //! PRE: True |
| 77 | //! ARGS: ind - integer index of value to return (default 0) |
| 78 | //! RETURNS: v - indth element of value, or a T_INVALID VarValue |
| 79 | //+ if ind is out of bounds |
| 80 | vjVarValue& getValue (int ind = 0); |
| 81 | |
| 82 | |
| 83 | |
| 84 | //: set the value at ind |
| 85 | //! PRE: true |
| 86 | //! POST: the indth value of self is set to val, if ind is |
| 87 | //+ a valid index to self's value vector. If self has |
| 88 | //+ a variable number of values and ind is greater than |
| 89 | //+ the current number of values, the value vector will |
| 90 | //+ be padded with VarValues of the appropriate type |
| 91 | //+ (with default values). |
| 92 | //! NOTE: If the argument can't be assigned because of type |
| 93 | //+ mismatch, the value at ind won't be changed. |
| 94 | //+ See vjVarValue::= to see what happens. Padding |
| 95 | //+ of the value vector may still occur. |
| 96 | //! ARGS: val - value to assign. If char*, must be a valid |
| 97 | //+ non-NULL C string. |
| 98 | //! ARGS: ind - integer index to value vector |
| 99 | bool setValue (int val, int ind = 0); |
| 100 | bool setValue (float val, int ind = 0); |
| 101 | bool setValue (char* val, int ind = 0); |
| 102 | |
| 103 | |
| 104 | |
| 105 | vjEnumEntry* getEnumEntry (char *n); |
| 106 | vjEnumEntry* getEnumEntry (int val); |
| 107 | |
| 108 | |
| 109 | |
| 110 | /** Converts the values in this property from units of u to units of feet. |
| 111 | * This is used when we're reading in a new distance property - The |
| 112 | * values have been read in as raw numbers, then we read in the unit type |
| 113 | * and realize what kind of conversion we have to do to put them in |
| 114 | * feet (our standard unit for internal storage of distances). |
| 115 | */ |
| 116 | bool applyUnits (CfgUnit u); |
| 117 | |
| 118 | |
| 119 | //: writes p to out |
| 120 | friend ostream& operator << (ostream &out, vjProperty& p); |
| 121 | |
| 122 | |
| 123 | |
| 124 | private: |
| 125 | |
| 126 | //: Utility function for setValue(val, ind) |
| 127 | //! POST: If self has a variable number of values, and ind |
| 128 | //+ is greater than the current size of the value |
| 129 | //+ vector, the vector is padded with new default-valued |
| 130 | //+ vjVarValues. |
| 131 | //! RETURNS: true if ind is a valid index to the values vector |
| 132 | //+ (after padding). |
| 133 | //! RETURNS: false if ind is out of bounds. |
| 134 | //! ARGS: ind - index into the values vector. |
| 135 | bool preSet (int ind); |
| 136 | |
| 137 | }; |
| 138 | |
| 139 | |
| 140 | #endif |
Note: See TracBrowser for help on using the browser.
