Tide 0.1.0
|
00001 /* Tide 00002 * 00003 * Header file for the primitive data element object. 00004 * 00005 * Copyright 2011 Geoffrey Biggs geoffrey.biggs@aist.go.jp 00006 * RT-Synthesis Research Group 00007 * Intelligent Systems Research Institute, 00008 * National Institute of Advanced Industrial Science and Technology (AIST), 00009 * Japan 00010 * All rights reserved. 00011 * 00012 * This file is part of Tide. 00013 * 00014 * Tide is free software; you can redistribute it and/or modify it under 00015 * the terms of the GNU Lesser General Public License as published by 00016 * the Free Software Foundation; either version 2.1 of the License, or 00017 * (at your option) any later version. 00018 * 00019 * Tide is distributed in the hope that it will be useful, but WITHOUT 00020 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00021 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00022 * License for more details. 00023 * 00024 * You should have received a copy of the GNU Lesser General Public 00025 * License along with Tide. If not, see <http://www.gnu.org/licenses/>. 00026 */ 00027 00028 #if !defined(TIDE_PRIM_ELEMENT_H_) 00029 #define TIDE_PRIM_ELEMENT_H_ 00030 00031 00032 #include <boost/operators.hpp> 00033 #include <stdint.h> 00034 #include <string> 00035 #include <tide/element.h> 00036 #include <tide/exceptions.h> 00037 #include <tide/win_dll.h> 00038 00041 00042 namespace tide 00043 { 00064 template<typename T> 00065 class TIDE_EXPORT PrimitiveElement : public Element, 00066 public boost::equality_comparable<PrimitiveElement<T> > 00067 { 00068 public: 00075 PrimitiveElement(uint32_t id, T value) 00076 : Element(id), 00077 value_(value), has_default_(false) 00078 { 00079 } 00080 00088 PrimitiveElement(uint32_t id, T value, T default_value) 00089 : Element(id), 00090 value_(value), default_(default_value), has_default_(true) 00091 { 00092 } 00093 00095 virtual PrimitiveElement& operator=(T const& rhs) 00096 { 00097 value_ = rhs; 00098 return *this; 00099 } 00100 00102 virtual uint32_t id() const { return Element::id(); } 00103 00109 virtual void id(uint32_t id) 00110 { 00111 if (id == 0 || 00112 id == 0xFF || 00113 id == 0xFFFF || 00114 id == 0xFFFFFF || 00115 id == 0xFFFFFFFF) 00116 { 00117 throw InvalidElementID() << err_id(id); 00118 } 00119 id_ = id; 00120 } 00121 00123 virtual T value() const { return value_; } 00125 virtual void value(T value) { value_ = value; } 00127 operator T() const { return value_; } 00128 00130 virtual bool has_default() const { return has_default_; } 00132 virtual T get_default() const { return default_; } 00134 virtual void set_default(T default_value) 00135 { 00136 default_ = default_value; 00137 has_default_ = true; 00138 } 00143 virtual T remove_default() 00144 { 00145 has_default_ = false; 00146 return default_; 00147 } 00153 virtual bool is_default() const 00154 { return value_ == default_ && has_default_; } 00155 00157 friend bool operator==(PrimitiveElement<T> const& lhs, 00158 PrimitiveElement<T> const& rhs) 00159 { 00160 return lhs.value_ == rhs.value_; 00161 } 00162 00163 protected: 00164 T value_; 00165 T default_; 00166 bool has_default_; 00167 00168 virtual bool equal_(PrimitiveElement<T> const& rhs) 00169 { 00170 return value_ == rhs.value_; 00171 } 00172 }; // class Element 00173 }; // namespace tide 00174 00177 00178 #endif // TIDE_PRIM_ELEMENT_H_ 00179