1 /* 2 * Copyright 2006, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 */ 8 9 #ifndef PROPERTY_H 10 #define PROPERTY_H 11 12 #include <limits.h> 13 14 #include <Archivable.h> 15 #include <String.h> 16 #include <TypeConstants.h> 17 18 class PropertyAnimator; 19 20 // Property 21 class Property : public BArchivable { 22 public: 23 Property(uint32 identifier); 24 Property(const Property& other); 25 Property(BMessage* archive); 26 virtual ~Property(); 27 28 // BArchivable interface 29 virtual status_t Archive(BMessage* archive, 30 bool deep = true) const; 31 32 // Property 33 virtual Property* Clone() const = 0; 34 35 virtual type_code Type() const = 0; 36 37 virtual bool SetValue(const char* value) = 0; 38 virtual bool SetValue(const Property* other) = 0; 39 virtual void GetValue(BString& string) = 0; 40 41 // animation 42 virtual bool InterpolateTo(const Property* other, 43 float scale); 44 45 inline uint32 Identifier() const 46 { return fIdentifier; } 47 48 void SetEditable(bool editable); 49 inline bool IsEditable() const 50 { return fEditable; } 51 52 private: 53 uint32 fIdentifier; 54 bool fEditable; 55 }; 56 57 // IntProperty 58 class IntProperty : public Property { 59 public: 60 IntProperty(uint32 identifier, 61 int32 value = 0, 62 int32 min = INT32_MIN, 63 int32 max = INT32_MAX); 64 IntProperty(const IntProperty& other); 65 IntProperty(BMessage* archive); 66 virtual ~IntProperty(); 67 68 virtual status_t Archive(BMessage* archive, 69 bool deep = true) const; 70 static BArchivable* Instantiate(BMessage* archive); 71 72 virtual Property* Clone() const; 73 74 virtual type_code Type() const 75 { return B_INT32_TYPE; } 76 77 virtual bool SetValue(const char* value); 78 virtual bool SetValue(const Property* other); 79 virtual void GetValue(BString& string); 80 81 virtual bool InterpolateTo(const Property* other, 82 float scale); 83 84 // IntProperty 85 bool SetValue(int32 value); 86 87 inline int32 Value() const 88 { return fValue; } 89 inline int32 Min() const 90 { return fMin; } 91 inline int32 Max() const 92 { return fMax; } 93 94 private: 95 int32 fValue; 96 int32 fMin; 97 int32 fMax; 98 }; 99 100 // FloatProperty 101 class FloatProperty : public Property { 102 public: 103 FloatProperty(uint32 identifier, 104 float value = 0.0, 105 float min = -1000000.0, 106 float max = 1000000.0); 107 FloatProperty(const FloatProperty& other); 108 FloatProperty(BMessage* archive); 109 virtual ~FloatProperty(); 110 111 virtual status_t Archive(BMessage* archive, 112 bool deep = true) const; 113 static BArchivable* Instantiate(BMessage* archive); 114 115 virtual Property* Clone() const; 116 117 virtual type_code Type() const 118 { return B_FLOAT_TYPE; } 119 120 virtual bool SetValue(const char* value); 121 virtual bool SetValue(const Property* other); 122 virtual void GetValue(BString& string); 123 124 virtual bool InterpolateTo(const Property* other, 125 float scale); 126 127 // FloatProperty 128 bool SetValue(float value); 129 130 inline float Value() const 131 { return fValue; } 132 inline float Min() const 133 { return fMin; } 134 inline float Max() const 135 { return fMax; } 136 137 private: 138 float fValue; 139 float fMin; 140 float fMax; 141 }; 142 143 // UInt8Property 144 class UInt8Property : public Property { 145 public: 146 UInt8Property(uint32 identifier, 147 uint8 value = 255); 148 UInt8Property(const UInt8Property& other); 149 UInt8Property(BMessage* archive); 150 virtual ~UInt8Property(); 151 152 virtual status_t Archive(BMessage* archive, 153 bool deep = true) const; 154 static BArchivable* Instantiate(BMessage* archive); 155 156 virtual Property* Clone() const; 157 158 virtual type_code Type() const 159 { return B_INT8_TYPE; } 160 161 virtual bool SetValue(const char* value); 162 virtual bool SetValue(const Property* other); 163 virtual void GetValue(BString& string); 164 165 virtual bool InterpolateTo(const Property* other, 166 float scale); 167 168 // UInt8Property 169 bool SetValue(uint8 value); 170 171 inline uint8 Value() const 172 { return fValue; } 173 174 private: 175 uint8 fValue; 176 }; 177 178 // BoolProperty 179 class BoolProperty : public Property { 180 public: 181 BoolProperty(uint32 identifier, 182 bool value = false); 183 BoolProperty(const BoolProperty& other); 184 BoolProperty(BMessage* archive); 185 virtual ~BoolProperty(); 186 187 virtual status_t Archive(BMessage* archive, 188 bool deep = true) const; 189 static BArchivable* Instantiate(BMessage* archive); 190 191 virtual Property* Clone() const; 192 193 virtual type_code Type() const 194 { return B_BOOL_TYPE; } 195 196 virtual bool SetValue(const char* value); 197 virtual bool SetValue(const Property* other); 198 virtual void GetValue(BString& string); 199 200 virtual bool InterpolateTo(const Property* other, 201 float scale); 202 203 // BoolProperty 204 bool SetValue(bool value); 205 206 inline bool Value() const 207 { return fValue; } 208 209 private: 210 bool fValue; 211 }; 212 213 // StringProperty 214 class StringProperty : public Property { 215 public: 216 StringProperty(uint32 identifier, 217 const char* string); 218 StringProperty(const StringProperty& other); 219 StringProperty(BMessage* archive); 220 virtual ~StringProperty(); 221 222 virtual status_t Archive(BMessage* archive, 223 bool deep = true) const; 224 static BArchivable* Instantiate(BMessage* archive); 225 226 virtual Property* Clone() const; 227 228 virtual type_code Type() const 229 { return B_STRING_TYPE; } 230 231 virtual bool SetValue(const char* value); 232 virtual bool SetValue(const Property* other); 233 virtual void GetValue(BString& string); 234 235 // StringProperty 236 inline const char* Value() const 237 { return fValue.String(); } 238 239 private: 240 BString fValue; 241 }; 242 243 #endif // PROPERTY_H 244