value.h

00001 /***************************************************************************
00002 *   clipsmm C++ wrapper for the CLIPS c library                           *
00003 *   Copyright (C) 2006 by Rick L. Vinyard, Jr.                            *
00004 *   rvinyard@cs.nmsu.edu                                                  *
00005 *                                                                         *
00006 *   This program is free software; you can redistribute it and/or modify  *
00007 *   it under the terms of version 2 of the GNU General Public License as  *
00008 *   published by the Free Software Foundation.                            *
00009 *                                                                         *
00010 *   This program is distributed in the hope that it will be useful,       *
00011 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013 *   GNU General Public License for more details.                          *
00014 *                                                                         *
00015 *   You should have received a copy of the GNU Lesser General Public      *
00016 *   License along with this library; if not, write to the                 *
00017 *   Free Software Foundation, Inc.,                                       *
00018 *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA              *
00019 ***************************************************************************/
00020 #ifndef CLIPSVALUE_H
00021 #define CLIPSVALUE_H
00022 
00023 #include <string>
00024 #include <vector>
00025 
00026 #include <sigc++/sigc++.h>
00027 
00028 namespace CLIPS {
00029 
00030 typedef enum Type {
00031   TYPE_FLOAT = 0,
00032   TYPE_INTEGER = 1,
00033   TYPE_SYMBOL = 2,
00034   TYPE_STRING = 3,
00035   TYPE_EXTERNAL_ADDRESS = 5,
00036   TYPE_INSTANCE_ADDRESS = 7,
00037   TYPE_INSTANCE_NAME = 8,
00038 } Type;
00039 
00043   class Value: public sigc::trackable {
00044     public:
00045 
00047       Value (Type type);
00048 
00050       Value( float x );
00051 
00053       Value( double x );
00054 
00056       Value( short int x );
00057 
00059       Value( unsigned short int x );
00060 
00062       Value( int x );
00063 
00065       Value( unsigned int x );
00066 
00068       Value( long int x );
00069 
00071       Value( char* x, Type type=TYPE_STRING );
00072 
00074       Value( const std::string& x, Type type=TYPE_STRING );
00075       
00077       Value( void* x, Type type=TYPE_EXTERNAL_ADDRESS );
00078 
00079       Value( const Value& value );
00080 
00082       ~Value();
00083 
00084       double as_float() const;
00085       long int as_integer() const;
00086       std::string& as_string() const;
00087       void* as_address() const;
00088 
00089       Value& set( float x, bool change_type=false );
00090       Value& set( double x, bool change_type=false  );
00091       Value& set( short int x, bool change_type=false  );
00092       Value& set( unsigned short int x, bool change_type=false  );
00093       Value& set( int x, bool change_type=false  );
00094       Value& set( unsigned int x, bool change_type=false  );
00095       Value& set( long int x, bool change_type=false  );
00096       Value& set( const std::string& x, bool change_type=false, Type type=TYPE_STRING );
00097       Value& set( const char* x, bool change_type=false, Type type=TYPE_STRING );
00098       Value& set( void* x, bool change_type=false, Type type=TYPE_EXTERNAL_ADDRESS  );
00099       
00100       operator float( ) const;
00101       operator double( ) const;
00102       operator short int( ) const;
00103       operator unsigned short int( ) const;
00104       operator int( ) const;
00105       operator unsigned int( ) const;
00106       operator long int( ) const;
00107       operator std::string&( ) const;
00108       operator const char*( ) const;
00109       operator void*( ) const;
00110 
00112 //       T& operator() () const { return this->get(); }
00113 
00115 //       Value<T,CLIPSType>& operator() ( const T& val ) {
00116 //         this->set( val );
00117 //         return *this;
00118 //       }
00119 
00121 //       const std::type_info& type_info() const { return typeid( T ); }
00122 
00127       size_t size() const;
00128 
00130 //       Value<T,CLIPSType>& operator= ( const T& val ) {
00131 //         this->set( val );
00132 //         return *this;
00133 //       }
00134 
00135       Value& operator=( float x );
00136       Value& operator=( double x );
00137       Value& operator=( short int x );
00138       Value& operator=( unsigned short int x );
00139       Value& operator=( int x );
00140       Value& operator=( unsigned int x );
00141       Value& operator=( long int x );
00142       Value& operator=( const std::string& x );
00143       Value& operator=( const char* x );
00144       Value& operator=( void* x );
00145       Value& operator=( const Value& x );
00146       
00147       bool operator==( float x ) const;
00148       bool operator==( double x ) const;
00149       bool operator==( short int x ) const;
00150       bool operator==( unsigned short int x ) const;
00151       bool operator==( int x ) const;
00152       bool operator==( unsigned int x ) const;
00153       bool operator==( long int x ) const;
00154       bool operator==( const std::string& x ) const;
00155       bool operator==( const char* x ) const;
00156       bool operator==( void* x ) const;
00157 
00158       bool operator!=( float x ) const;
00159       bool operator!=( double x ) const;
00160       bool operator!=( short int x ) const;
00161       bool operator!=( unsigned short int x ) const;
00162       bool operator!=( int x ) const;
00163       bool operator!=( unsigned int x ) const;
00164       bool operator!=( long int x ) const;
00165       bool operator!=( const std::string& x ) const;
00166       bool operator!=( const char* x ) const;
00167       bool operator!=( void* x ) const;
00168 
00178 //       template <typename X>
00179 //       Value& operator+=( X other ) {
00180 //         this->set( this->get() + other );
00181 //         return *this;
00182 //       }
00183 
00193 //       template <typename X>
00194 //       Value& operator-=( X other ) {
00195 //         this->set( this->get() - other );
00196 //         return *this;
00197 //       }
00198 
00208 //       template <typename X>
00209 //       Value& operator*=( X other ) {
00210 //         this->set( this->get() * other );
00211 //         return *this;
00212 //       }
00213 
00223 //       template <typename X>
00224 //       Value& operator/=( X other ) {
00225 //         this->set( this->get() / other );
00226 //         return *this;
00227 //       }
00228 
00238 //       template <typename X>
00239 //       Value& operator%=( X other ) {
00240 //         this->set( this->get() % other );
00241 //         return *this;
00242 //       }
00243 
00245       Type type() const;
00246 
00248       Type set_type( Type type );
00249 
00251       sigc::signal<void> signal_changed();
00252 
00253     protected:
00255       void* m_value;
00256 
00258       Type m_clips_type;
00259       
00261       sigc::signal<void> m_signal_changed;
00262 
00263       void deallocate_storage();
00264   };
00265 
00266   typedef std::vector<Value> Values;
00267 
00268 }
00269 
00270 #endif

Generated on Sun Nov 12 11:55:35 2006 by  doxygen 1.5.1