clipsmm - C++ CLIPS Interface Library

clipsmm logo

value.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2006  Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu>       *
00003  *   Copyright (C) 2013  Tim Niemueller [www.niemueller.de]                *
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_UNKNOWN = -1,
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 
00044 class Value: public sigc::trackable {
00045  public:
00046 
00048   Value ();
00049 
00051   Value (Type type);
00052 
00054   Value( float x );
00055 
00057   Value( double x );
00058 
00060   Value( short int x );
00061 
00063   Value( unsigned short int x );
00064 
00066   Value( int x );
00067 
00069   Value( unsigned int x );
00070 
00072   Value( long int x );
00073 
00075   Value( long long int x );
00076 
00078   Value( const char* x, Type type=TYPE_STRING );
00079 
00081   Value( const std::string& x, Type type=TYPE_STRING );
00082       
00084   Value( void* x, Type type=TYPE_EXTERNAL_ADDRESS );
00085 
00086   Value( const Value& value );
00087 
00089   ~Value();
00090 
00091   double as_float() const;
00092   long long int as_integer() const;
00093   std::string& as_string() const;
00094   void* as_address() const;
00095 
00096   Value& set( float x, bool change_type=false );
00097   Value& set( double x, bool change_type=false  );
00098   Value& set( short int x, bool change_type=false  );
00099   Value& set( unsigned short int x, bool change_type=false  );
00100   Value& set( int x, bool change_type=false  );
00101   Value& set( unsigned int x, bool change_type=false  );
00102   Value& set( long int x, bool change_type=false  );
00103   Value& set( long long int x, bool change_type=false  );
00104   Value& set( const std::string& x, bool change_type=false, Type type=TYPE_STRING );
00105   Value& set( const char* x, bool change_type=false, Type type=TYPE_STRING );
00106   Value& set( void* x, bool change_type=false, Type type=TYPE_EXTERNAL_ADDRESS  );
00107       
00108   operator float( ) const;
00109   operator double( ) const;
00110   operator short int( ) const;
00111   operator unsigned short int( ) const;
00112   operator int( ) const;
00113   operator unsigned int( ) const;
00114   operator long int( ) const;
00115   operator long long int( ) const;
00116   operator std::string&( ) const;
00117   operator const char*( ) const;
00118   operator void*( ) const;
00119 
00121   //       T& operator() () const { return this->get(); }
00122 
00124   //       Value<T,CLIPSType>& operator() ( const T& val ) {
00125   //         this->set( val );
00126   //         return *this;
00127   //       }
00128 
00130   //       const std::type_info& type_info() const { return typeid( T ); }
00131 
00136   size_t size() const;
00137 
00139   //       Value<T,CLIPSType>& operator= ( const T& val ) {
00140   //         this->set( val );
00141   //         return *this;
00142   //       }
00143 
00144   Value& operator=( float x );
00145   Value& operator=( double x );
00146   Value& operator=( short int x );
00147   Value& operator=( unsigned short int x );
00148   Value& operator=( int x );
00149   Value& operator=( unsigned int x );
00150   Value& operator=( long int x );
00151   Value& operator=( long long int x );
00152   Value& operator=( const std::string& x );
00153   Value& operator=( const char* x );
00154   Value& operator=( void* x );
00155   Value& operator=( const Value& x );
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==( long 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 
00169   bool operator!=( float x ) const;
00170   bool operator!=( double x ) const;
00171   bool operator!=( short int x ) const;
00172   bool operator!=( unsigned short int x ) const;
00173   bool operator!=( int x ) const;
00174   bool operator!=( unsigned int x ) const;
00175   bool operator!=( long int x ) const;
00176   bool operator!=( long long int x ) const;
00177   bool operator!=( const std::string& x ) const;
00178   bool operator!=( const char* x ) const;
00179   bool operator!=( void* x ) const;
00180 
00190   //       template <typename X>
00191   //       Value& operator+=( X other ) {
00192   //         this->set( this->get() + other );
00193   //         return *this;
00194   //       }
00195 
00205   //       template <typename X>
00206   //       Value& operator-=( X other ) {
00207   //         this->set( this->get() - other );
00208   //         return *this;
00209   //       }
00210 
00220   //       template <typename X>
00221   //       Value& operator*=( X other ) {
00222   //         this->set( this->get() * other );
00223   //         return *this;
00224   //       }
00225 
00235   //       template <typename X>
00236   //       Value& operator/=( X other ) {
00237   //         this->set( this->get() / other );
00238   //         return *this;
00239   //       }
00240 
00250   //       template <typename X>
00251   //       Value& operator%=( X other ) {
00252   //         this->set( this->get() % other );
00253   //         return *this;
00254   //       }
00255 
00257   Type type() const;
00258 
00260   Type set_type( Type type );
00261 
00263   sigc::signal<void> signal_changed();
00264 
00265  protected:
00267   void* m_value;
00268 
00270   Type m_clips_type;
00271       
00273   sigc::signal<void> m_signal_changed;
00274 
00275   void deallocate_storage();
00276 };
00277 
00278  typedef std::vector<Value> Values;
00279 
00280 }
00281 
00282 #endif

Generated on Thu Apr 11 14:03:48 2013 for clipsmm by doxygen 1.6.1