clipsmm - C++ CLIPS Interface Library

clipsmm logo

value.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2006 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This file is part of the clipsmm library.                             *
00006  *                                                                         *
00007  *   The clipsmm library is free software; you can redistribute it and/or  *
00008  *   modify it under the terms of the GNU General Public License           *
00009  *   version 3 as published by the Free Software Foundation.               *
00010  *                                                                         *
00011  *   The clipsmm library is distributed in the hope that it will be        *
00012  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty   *
00013  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
00014  *   General Public License for more details.                              *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU General Public License     *
00017  *   along with this software. If not see <http://www.gnu.org/licenses/>.  *
00018  ***************************************************************************/
00019 #ifndef CLIPSVALUE_H
00020 #define CLIPSVALUE_H
00021 
00022 #include <string>
00023 #include <vector>
00024 
00025 #include <sigc++/sigc++.h>
00026 
00027 namespace CLIPS {
00028 
00029 typedef enum Type {
00030   TYPE_FLOAT = 0,
00031   TYPE_INTEGER = 1,
00032   TYPE_SYMBOL = 2,
00033   TYPE_STRING = 3,
00034   TYPE_EXTERNAL_ADDRESS = 5,
00035   TYPE_INSTANCE_ADDRESS = 7,
00036   TYPE_INSTANCE_NAME = 8,
00037 } Type;
00038 
00042   class Value: public sigc::trackable {
00043     public:
00044 
00046       Value (Type type);
00047 
00049       Value( float x );
00050 
00052       Value( double x );
00053 
00055       Value( short int x );
00056 
00058       Value( unsigned short int x );
00059 
00061       Value( int x );
00062 
00064       Value( unsigned int x );
00065 
00067       Value( long int x );
00068 
00070       Value( char* x, Type type=TYPE_STRING );
00071 
00073       Value( const std::string& x, Type type=TYPE_STRING );
00074       
00076       Value( void* x, Type type=TYPE_EXTERNAL_ADDRESS );
00077 
00078       Value( const Value& value );
00079 
00081       ~Value();
00082 
00083       double as_float() const;
00084       long int as_integer() const;
00085       std::string& as_string() const;
00086       void* as_address() const;
00087 
00088       Value& set( float x, bool change_type=false );
00089       Value& set( double x, bool change_type=false  );
00090       Value& set( short int x, bool change_type=false  );
00091       Value& set( unsigned short int x, bool change_type=false  );
00092       Value& set( int x, bool change_type=false  );
00093       Value& set( unsigned int x, bool change_type=false  );
00094       Value& set( long int x, bool change_type=false  );
00095       Value& set( const std::string& x, bool change_type=false, Type type=TYPE_STRING );
00096       Value& set( const char* x, bool change_type=false, Type type=TYPE_STRING );
00097       Value& set( void* x, bool change_type=false, Type type=TYPE_EXTERNAL_ADDRESS  );
00098       
00099       operator float( ) const;
00100       operator double( ) const;
00101       operator short int( ) const;
00102       operator unsigned short int( ) const;
00103       operator int( ) const;
00104       operator unsigned int( ) const;
00105       operator long int( ) const;
00106       operator std::string&( ) const;
00107       operator const char*( ) const;
00108       operator void*( ) const;
00109 
00111 //       T& operator() () const { return this->get(); }
00112 
00114 //       Value<T,CLIPSType>& operator() ( const T& val ) {
00115 //         this->set( val );
00116 //         return *this;
00117 //       }
00118 
00120 //       const std::type_info& type_info() const { return typeid( T ); }
00121 
00126       size_t size() const;
00127 
00129 //       Value<T,CLIPSType>& operator= ( const T& val ) {
00130 //         this->set( val );
00131 //         return *this;
00132 //       }
00133 
00134       Value& operator=( float x );
00135       Value& operator=( double x );
00136       Value& operator=( short int x );
00137       Value& operator=( unsigned short int x );
00138       Value& operator=( int x );
00139       Value& operator=( unsigned int x );
00140       Value& operator=( long int x );
00141       Value& operator=( const std::string& x );
00142       Value& operator=( const char* x );
00143       Value& operator=( void* x );
00144       Value& operator=( const Value& x );
00145       
00146       bool operator==( float x ) const;
00147       bool operator==( double x ) const;
00148       bool operator==( short int x ) const;
00149       bool operator==( unsigned short int x ) const;
00150       bool operator==( int x ) const;
00151       bool operator==( unsigned int x ) const;
00152       bool operator==( long int x ) const;
00153       bool operator==( const std::string& x ) const;
00154       bool operator==( const char* x ) const;
00155       bool operator==( void* x ) const;
00156 
00157       bool operator!=( float x ) const;
00158       bool operator!=( double x ) const;
00159       bool operator!=( short int x ) const;
00160       bool operator!=( unsigned short int x ) const;
00161       bool operator!=( int x ) const;
00162       bool operator!=( unsigned int x ) const;
00163       bool operator!=( long int x ) const;
00164       bool operator!=( const std::string& x ) const;
00165       bool operator!=( const char* x ) const;
00166       bool operator!=( void* x ) const;
00167 
00177 //       template <typename X>
00178 //       Value& operator+=( X other ) {
00179 //         this->set( this->get() + other );
00180 //         return *this;
00181 //       }
00182 
00192 //       template <typename X>
00193 //       Value& operator-=( X other ) {
00194 //         this->set( this->get() - other );
00195 //         return *this;
00196 //       }
00197 
00207 //       template <typename X>
00208 //       Value& operator*=( X other ) {
00209 //         this->set( this->get() * other );
00210 //         return *this;
00211 //       }
00212 
00222 //       template <typename X>
00223 //       Value& operator/=( X other ) {
00224 //         this->set( this->get() / other );
00225 //         return *this;
00226 //       }
00227 
00237 //       template <typename X>
00238 //       Value& operator%=( X other ) {
00239 //         this->set( this->get() % other );
00240 //         return *this;
00241 //       }
00242 
00244       Type type() const;
00245 
00247       Type set_type( Type type );
00248 
00250       sigc::signal<void> signal_changed();
00251 
00252     protected:
00254       void* m_value;
00255 
00257       Type m_clips_type;
00258       
00260       sigc::signal<void> m_signal_changed;
00261 
00262       void deallocate_storage();
00263   };
00264 
00265   typedef std::vector<Value> Values;
00266 
00267 }
00268 
00269 #endif

Generated on Wed Jul 29 12:04:08 2009 for clipsmm by doxygen 1.5.8