00001 #ifndef ELEMENT_H 00002 #define ELEMENT_H 00003 00008 #include <string> 00009 #include <stdexcept> 00010 namespace dynamic 00011 { 00012 template<class T> 00016 class Counted 00017 { 00018 static int count; 00019 public: 00020 Counted () { count++; }; 00024 Counted(const Counted<T>&) { count++; }; 00025 ~Counted() { count--; } 00029 static int getCount() { return count; } 00030 }; 00031 template<class T> 00035 class Property 00036 { 00037 T m_value; 00038 public: 00039 Property(){}; 00043 Property(T value) {m_value = value;}; 00044 ~Property(){}; 00048 void set(T value) throw(std::invalid_argument) 00049 { 00050 //if (value==NULL) throw std::invalid_argument("set NULL"); 00051 m_value = value; 00052 }; 00056 T get() const {return m_value;}; 00057 }; 00058 template<class T,T comp_value> 00062 class PropertyGreaterThen : public Property<T> 00063 { 00064 public: 00068 PropertyGreaterThen(T value) {set(value);}; 00069 ~PropertyGreaterThen(){}; 00070 void set(T value) throw(std::invalid_argument) 00071 { 00072 if (value < comp_value) throw std::invalid_argument("value isn't greater then" + comp_value); 00073 Property<T>::set(value); 00074 }; 00075 }; 00076 template<class T,T comp_value> 00080 class PropertyLessThen : public Property<T> 00081 { 00082 public: 00086 PropertyLessThen(T value) {set(value);}; 00087 ~PropertyLessThen(){}; 00088 void set(T value) throw(std::invalid_argument) 00089 { 00090 if (value > comp_value) throw std::invalid_argument("value isn't less then" + comp_value); 00091 Property<T>::set(value); 00092 }; 00093 }; 00098 class Element 00099 { 00100 public: 00102 Element(); 00104 virtual ~Element(); 00108 static const double pi = 3.1415926; 00112 static const double two_pi = 6.2831852; 00116 Property<std::string> name; 00120 Property<std::string> maker; 00124 Property<std::string> type; 00125 }; 00126 } 00127 #endif //ELEMENT_H