clipsmm - C++ CLIPS Interface Library

clipsmm logo

environment.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 CLIPSENVIRONMENT_H
00020 #define CLIPSENVIRONMENT_H
00021 
00022 #include <string>
00023 #include <map>
00024 #include <typeinfo>
00025 #include <stdexcept>
00026 #include <map>
00027 #include <queue>
00028 
00029 #include <iostream>
00030 
00031 #include <sigc++/sigc++.h>
00032 #include <glibmm.h>
00033 
00034 #include <clipsmm/enum.h>
00035 #include <clipsmm/object.h>
00036 
00037 #include <clipsmm/activation.h>
00038 #include <clipsmm/defaultfacts.h>
00039 #include <clipsmm/fact.h>
00040 #include <clipsmm/function.h>
00041 #include <clipsmm/global.h>
00042 #include <clipsmm/module.h>
00043 #include <clipsmm/rule.h>
00044 #include <clipsmm/template.h>
00045 
00046 #include <clipsmm/utility.h>
00047 #include <clipsmm/any.h>
00048 
00049 extern "C" {
00050   int EnvDefineFunction2WithContext( void *, char *, int, int ( * ) ( void * ), char *, char *, void * );
00051 }
00052 
00053 namespace CLIPS {
00054 
00058   class Environment: public Object {
00059     public:
00060       typedef CLIPSPointer<Environment> pointer;
00061 
00062       Environment();
00063 
00064       ~Environment();
00065 
00070       bool batch_evaluate( const std::string& filename );
00071 
00076       bool binary_load( const std::string& filename );
00077 
00082       bool binary_save( const std::string& filename );
00083 
00088       bool build( const std::string& construct );
00089 
00093       void clear( );
00094 
00100       Values evaluate( const std::string& expression );
00101 
00107       Values function( const std::string& function_name, const std::string& arguments=std::string() );
00108 
00120       int load( const std::string& filename );
00121 
00125       void reset();
00126 
00131       bool save( const std::string& filename );
00132 
00139       bool auto_float_dividend_enabled();
00140 
00148       bool use_auto_float_dividend( bool use = true );
00149 
00156       bool dynamic_constraint_checking_enabled();
00157 
00165       bool use_dynamic_constraint_checking( bool use = true );
00166 
00173       bool sequence_operator_recognition_enabled();
00174 
00182       bool use_sequence_operator_recognition( bool use = true );
00183 
00190       bool static_constraint_checking_enabled();
00191 
00198       bool use_static_constraint_checking( bool use = true );
00199 
00207       bool fact_duplication_enabled();
00208 
00215       bool use_fact_duplication( bool use = true );
00216 
00217       bool incremental_reset_enabled();
00218 
00219       bool use_incremental_reset( bool use = true );
00220 
00221       bool global_reset_enable();
00222 
00223       bool use_global_reset( bool use=true );
00224 
00229       bool is_dribble_active( );
00230 
00235       bool dribble_off( );
00236 
00241       bool dribble_on( const std::string& dribble_file );
00242 
00250       int is_watched( const std::string& item );
00251 
00252       bool watch( const std::string& item );
00253 
00254       bool unwatch( const std::string& item );
00255 
00256       void set_as_current();
00257 
00258       Fact::pointer assert_fact( const std::string& factstring );
00259 
00260       void clear_focus_stack();
00261 
00264       DefaultFacts::pointer get_default_facts( const std::string& default_facts_name );
00265 
00267       std::vector<std::string> get_default_facts_names();
00268 
00270       std::vector<std::string> get_default_facts_names( const Module& module );
00271 
00273       std::vector<std::string> get_default_facts_names( Module::pointer module );
00274 
00275       DefaultFacts::pointer get_default_facts_list_head();
00276 
00277       Template::pointer get_template( const std::string& template_name );
00278 
00280       std::vector<std::string> get_template_names();
00281 
00283       std::vector<std::string> get_template_names( const Module& module );
00284 
00286       std::vector<std::string> get_template_names( Module::pointer module );
00287 
00288       Template::pointer get_template_list_head();
00289 
00290       Rule::pointer get_rule( const std::string& rule_name );
00291 
00293       std::vector<std::string> get_rule_names();
00294 
00296       std::vector<std::string> get_rule_names( const Module& module );
00297 
00299       std::vector<std::string> get_rule_names( Module::pointer module );
00300 
00301       Rule::pointer get_rule_list_head();
00302 
00303       void remove_rules();
00304 
00305       Module::pointer get_module( const std::string& module_name );
00306 
00307       Module::pointer get_current_module();
00308 
00309       std::vector<std::string> get_module_names();
00310 
00311       Module::pointer get_module_list_head();
00312 
00318       void refresh_agenda();
00319 
00325       void refresh_agenda( const Module& module );
00326 
00332       void refresh_agenda( Module::pointer module );
00333 
00339       void reorder_agenda();
00340 
00346       void reorder_agenda( const Module& module );
00347 
00353       void reorder_agenda( Module::pointer module );
00354 
00364       long int run( long int runlimit = -1 );
00365 
00384       void run_threaded( long int runlimit = -1, int priority = 0 );
00385 
00387       void join_run_thread();
00388 
00390       sigc::signal<void, long int> signal_run();
00391 
00393       SalienceEvaluation get_salience_evaluation();
00394 
00399       SalienceEvaluation set_salience_evaluation( SalienceEvaluation se );
00400 
00402       ConflictResolution get_conflict_resolution_strategy();
00403 
00408       ConflictResolution set_conflict_resolution_strategy( ConflictResolution cr );
00409 
00418       bool check_agenda_changed();
00419 
00420       Module::pointer get_focused_module();
00421 
00422       std::vector<std::string> get_focus_stack();
00423 
00424       Activation::pointer get_activation_list_head();
00425 
00426       Global::pointer get_global( const std::string& global_name );
00427 
00428       Global::pointer get_global_list_head();
00429 
00431       std::vector<std::string> get_globals_names();
00432 
00434       std::vector<std::string> get_globals_names( const Module& module );
00435 
00437       std::vector<std::string> get_globals_names( Module::pointer module );
00438 
00439       bool check_globals_changed();
00440 
00441       Function::pointer get_function( const std::string& function_name );
00442 
00443       Function::pointer get_function_list_head();
00444 
00446       std::vector<std::string> get_function_names();
00447 
00449       std::vector<std::string> get_function_names( const Module& module );
00450 
00452       std::vector<std::string> get_function_names( Module::pointer module );
00453 
00454       sigc::signal<void> signal_clear();
00455       sigc::signal<void> signal_periodic();
00456       sigc::signal<void> signal_reset();
00457       sigc::signal<void> signal_rule_firing();
00458       sigc::signal<void> signal_agenda_changed();
00459       sigc::signal<void> signal_globals_changed();
00460 
00461       template < typename T_return >
00462       bool add_function( std::string name, const sigc::slot0<T_return>& slot);
00463 
00464       template < typename T_return, typename T_arg1 >
00465       bool add_function( std::string name, const sigc::slot1<T_return, T_arg1>& slot);
00466 
00467       template < typename T_return, typename T_arg1, typename T_arg2 >
00468       bool add_function( std::string name, const sigc::slot2<T_return, T_arg1, T_arg2>& slot);
00469 
00470       template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3 >
00471       bool add_function( std::string name, const sigc::slot3<T_return, T_arg1, T_arg2, T_arg3>& slot);
00472 
00473       template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4 >
00474       bool add_function( std::string name, const sigc::slot4<T_return, T_arg1, T_arg2, T_arg3, T_arg4>& slot);
00475 
00476       template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5 >
00477       bool add_function( std::string name, const sigc::slot5<T_return, T_arg1, T_arg2, T_arg3, T_arg4, T_arg5>& slot);
00478 
00479       template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6 >
00480       bool add_function( std::string name, const sigc::slot6<T_return, T_arg1, T_arg2, T_arg3, T_arg4, T_arg5, T_arg6>& slot);
00481 
00482       template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7 >
00483       bool add_function( std::string name, const sigc::slot7<T_return, T_arg1, T_arg2, T_arg3, T_arg4, T_arg5, T_arg6, T_arg7>& slot);
00484 
00485       bool remove_function( std::string name );
00486 
00487     protected:
00494       std::map<std::string,any> m_slots;
00495 
00496       sigc::signal<void> m_signal_clear;
00497       sigc::signal<void> m_signal_periodic;
00498       sigc::signal<void> m_signal_reset;
00499       sigc::signal<void> m_signal_rule_firing;
00500       sigc::signal<void> m_signal_agenda_changed;
00501       sigc::signal<void> m_signal_globals_changed;
00502 
00504       typedef struct Job {
00506         Job( int p, long int rl ) : priority(p), runlimit(rl) { }
00507 
00509         bool operator<( const Job& other ) const { return priority < other.priority; }
00510 
00512         int priority;
00513 
00518         long int runlimit;
00519       } Job;
00520 
00521       Glib::Thread* m_run_thread; 
00522       std::priority_queue<Job> m_run_queue; 
00523       Glib::Mutex m_mutex_run_queue; 
00524       Glib::Mutex m_mutex_run; 
00525       Glib::Mutex m_mutex_threaded_run; 
00526       Glib::Mutex m_mutex_run_signal; 
00527       sigc::signal<void, long int> m_signal_run; 
00530       void threaded_run();
00531 
00532       static std::map<void*, Environment*> m_environment_map;
00533 
00534 
00535       static void clear_callback( void* env );
00536       static void periodic_callback( void* env );
00537       static void reset_callback( void* env );
00538       static void rule_firing_callback( void* end );
00539 
00540       static void* strcallback( void* theEnv );
00541 
00542       template < typename T_arg1 >
00543       static void* strcallback( void* theEnv );
00544 
00545       template < typename T_arg1, typename T_arg2 >
00546       static void* strcallback( void* theEnv );
00547 
00548       template < typename T_arg1, typename T_arg2, typename T_arg3 >
00549       static void* strcallback( void* theEnv );
00550 
00551       template < typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4 >
00552       static void* strcallback( void* theEnv );
00553 
00554       template < typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5 >
00555       static void* strcallback( void* theEnv );
00556 
00557       template < typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6 >
00558       static void* strcallback( void* theEnv );
00559 
00560       template < typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7 >
00561       static void* strcallback( void* theEnv );
00562 
00563       template < typename T_return >
00564       static T_return callback( void* theEnv );
00565 
00566       template < typename T_return, typename T_arg1 >
00567       static T_return callback( void* theEnv );
00568 
00569       template < typename T_return, typename T_arg1, typename T_arg2 >
00570       static T_return callback( void* theEnv );
00571 
00572       template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3 >
00573       static T_return callback( void* theEnv );
00574 
00575       template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4 >
00576       static T_return callback( void* theEnv );
00577 
00578       template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5 >
00579       static T_return callback( void* theEnv );
00580 
00581       template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6 >
00582       static T_return callback( void* theEnv );
00583 
00584       template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7 >
00585       static T_return callback( void* theEnv );
00586 
00587       int ( *get_callback( const sigc::slot0<std::string>& slot ))( void* )
00588         { return ( int ( * ) ( void* ) ) ( std::string ( * ) ( void* ) ) callback<std::string>; }
00589 
00590       template < typename T_arg1 >
00591       int ( *get_callback( const sigc::slot1<std::string,T_arg1>& slot ))( void* )
00592         { return ( int ( * ) ( void* ) ) ( std::string ( * ) ( void* ) ) callback<std::string,T_arg1>; }
00593 
00594       template < typename T_arg1, typename T_arg2 >
00595       int ( *get_callback( const sigc::slot2<std::string,T_arg1,T_arg2>& slot ))( void* )
00596         { return ( int ( * ) ( void* ) ) ( void* ( * ) ( void* ) ) strcallback<T_arg1,T_arg2>; }
00597 
00598       template < typename T_arg1, typename T_arg2, typename T_arg3 >
00599       int ( *get_callback( const sigc::slot3<std::string,T_arg1,T_arg2,T_arg3>& slot ))( void* )
00600         { return (int(*)(void*)) (std::string(*)(void*)) callback<std::string,T_arg1,T_arg2,T_arg3>; }
00601 
00602       template < typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4 >
00603       int ( *get_callback( const sigc::slot4<std::string,T_arg1,T_arg2,T_arg3,T_arg4>& slot ))( void* )
00604         { return (int(*)(void*)) (std::string(*)(void*)) callback<std::string,T_arg1,T_arg2,T_arg3,T_arg4>; }
00605 
00606       template < typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5 >
00607       int ( *get_callback( const sigc::slot5<std::string,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5>& slot ))( void* )
00608         { return (int(*)(void*)) (std::string(*)(void*)) callback<std::string,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5>; }
00609 
00610       template < typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6 >
00611       int ( *get_callback( const sigc::slot6<std::string,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6>& slot ))( void* )
00612         { return (int(*)(void*)) (std::string(*)(void*)) callback<std::string,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6>; }
00613 
00614       template < typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7 >
00615       int ( *get_callback( const sigc::slot7<std::string,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6,T_arg7>& slot ))( void* )
00616         { return (int(*)(void*)) (std::string(*)(void*)) callback<std::string,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6,T_arg7>; }
00617 
00618       template < typename T_return >
00619       int ( *get_callback( const sigc::slot0<T_return>& slot ))( void* )
00620         { return ( int ( * ) ( void* ) ) ( T_return ( * ) ( void* ) ) callback<T_return>; }
00621 
00622       template < typename T_return, typename T_arg1 >
00623       int ( *get_callback( const sigc::slot1<T_return,T_arg1>& slot ))( void* )
00624         { return ( int ( * ) ( void* ) ) ( T_return ( * ) ( void* ) ) callback<T_return,T_arg1>; }
00625 
00626       template < typename T_return, typename T_arg1, typename T_arg2 >
00627       int ( *get_callback( const sigc::slot2<T_return,T_arg1,T_arg2>& slot ))( void* )
00628         { return ( int ( * ) ( void* ) ) ( T_return ( * ) ( void* ) ) callback<T_return,T_arg1,T_arg2>; }
00629 
00630       template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3 >
00631       int ( *get_callback( const sigc::slot3<T_return,T_arg1,T_arg2,T_arg3>& slot ))( void* )
00632         { return (int(*)(void*)) (T_return(*)(void*)) callback<T_return,T_arg1,T_arg2,T_arg3>; }
00633 
00634       template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4 >
00635       int ( *get_callback( const sigc::slot4<T_return,T_arg1,T_arg2,T_arg3,T_arg4>& slot ))( void* )
00636         { return (int(*)(void*)) (T_return(*)(void*)) callback<T_return,T_arg1,T_arg2,T_arg3,T_arg4>; }
00637 
00638       template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5 >
00639       int ( *get_callback( const sigc::slot5<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5>& slot ))( void* )
00640         { return (int(*)(void*)) (T_return(*)(void*)) callback<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5>; }
00641 
00642       template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6 >
00643       int ( *get_callback( const sigc::slot6<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6>& slot ))( void* )
00644         { return (int(*)(void*)) (T_return(*)(void*)) callback<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6>; }
00645 
00646       template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7 >
00647       int ( *get_callback( const sigc::slot7<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6,T_arg7>& slot ))( void* )
00648         { return (int(*)(void*)) (T_return(*)(void*)) callback<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6,T_arg7>; }
00649 
00650       static int get_arg_count( void* env );
00651       static void* get_function_context( void* env );
00652       static void* add_symbol( const char* s );
00653 
00654 
00655   };
00656 
00657   template < typename T_return>
00658   inline
00659   T_return Environment::callback( void* theEnv ) {
00660     sigc::slot0<T_return>* cb;
00661     void * cbptr = get_function_context( theEnv );
00662     if ( cbptr ) {
00663       if ( get_arg_count( theEnv ) != 0 )
00664         throw std::logic_error( "clipsmm: wrong # args on slot callback; expected 0" );
00665       cb = static_cast<sigc::slot0<T_return>*>( cbptr );
00666       return ( *cb ) ();
00667     }
00668     throw;
00669   }
00670 
00671   template < typename T_return, typename T_arg1 >
00672   inline
00673   T_return Environment::callback( void* theEnv ) {
00674     sigc::slot1<T_return,T_arg1>* cb;
00675     void * cbptr = get_function_context( theEnv );
00676     T_arg1 arg1;
00677     if ( cbptr ) {
00678       if ( get_arg_count( theEnv ) != 1 )
00679         throw std::logic_error( "clipsmm: wrong # args on slot callback; expected 1" );
00680       get_argument( theEnv, 1, arg1 );
00681       cb = static_cast<sigc::slot1<T_return,T_arg1>*>( cbptr );
00682       return ( *cb ) ( arg1 );
00683     }
00684     throw;
00685   }
00686 
00687   template < typename T_return, typename T_arg1, typename T_arg2 >
00688   inline
00689   T_return Environment::callback( void* theEnv ) {
00690     sigc::slot2<T_return, T_arg1, T_arg2>* cb;
00691     void * cbptr = get_function_context( theEnv );
00692     T_arg1 arg1;
00693     T_arg2 arg2;
00694     if ( cbptr ) {
00695       if ( get_arg_count( theEnv ) != 2 )
00696         throw std::logic_error( "clipsmm: wrong # args on slot callback; expected 2" );
00697       get_argument( theEnv, 1, arg1 );
00698       get_argument( theEnv, 2, arg2 );
00699       cb = static_cast<sigc::slot2<T_return, T_arg1, T_arg2>*>( cbptr );
00700       return ( *cb ) ( arg1, arg2 );
00701     }
00702     throw;
00703   }
00704 
00705   template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3 >
00706   inline
00707   T_return Environment::callback( void* theEnv ) {
00708     sigc::slot3<T_return,T_arg1,T_arg2,T_arg3>* cb;
00709     void * cbptr = get_function_context( theEnv );
00710     T_arg1 arg1;
00711     T_arg2 arg2;
00712     T_arg3 arg3;
00713     if ( cbptr ) {
00714       if ( get_arg_count( theEnv ) != 3 )
00715         throw std::logic_error( "clipsmm: wrong # args on slot callback; expected 3" );
00716       get_argument( theEnv, 1, arg1 );
00717       get_argument( theEnv, 2, arg2 );
00718       get_argument( theEnv, 3, arg3 );
00719       cb = static_cast<sigc::slot3<T_return, T_arg1, T_arg2,T_arg3>*>( cbptr );
00720       return ( *cb ) ( arg1, arg2, arg3 );
00721     }
00722     throw;
00723   }
00724 
00725   template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4 >
00726   inline
00727   T_return Environment::callback( void* theEnv ) {
00728     sigc::slot4<T_return,T_arg1,T_arg2,T_arg3,T_arg4>* cb;
00729     void * cbptr = get_function_context( theEnv );
00730     T_arg1 arg1;
00731     T_arg2 arg2;
00732     T_arg3 arg3;
00733     T_arg4 arg4;
00734     if ( cbptr ) {
00735       if ( get_arg_count( theEnv ) != 4 )
00736         throw std::logic_error( "clipsmm: wrong # args on slot callback; expected 4" );
00737       get_argument( theEnv, 1, arg1 );
00738       get_argument( theEnv, 2, arg2 );
00739       get_argument( theEnv, 3, arg3 );
00740       get_argument( theEnv, 4, arg4 );
00741       cb = static_cast<sigc::slot4<T_return, T_arg1, T_arg2,T_arg3,T_arg4>*>( cbptr );
00742       return ( *cb ) ( arg1, arg2, arg3, arg4 );
00743     }
00744     throw;
00745   }
00746 
00747   template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5 >
00748   inline
00749   T_return Environment::callback( void* theEnv ) {
00750     sigc::slot5<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5>* cb;
00751     void * cbptr = get_function_context( theEnv );
00752     T_arg1 arg1;
00753     T_arg2 arg2;
00754     T_arg3 arg3;
00755     T_arg4 arg4;
00756     T_arg5 arg5;
00757     if ( cbptr ) {
00758       if ( get_arg_count( theEnv ) != 5 )
00759         throw std::logic_error( "clipsmm: wrong # args on slot callback; expected 5" );
00760       get_argument( theEnv, 1, arg1 );
00761       get_argument( theEnv, 2, arg2 );
00762       get_argument( theEnv, 3, arg3 );
00763       get_argument( theEnv, 4, arg4 );
00764       get_argument( theEnv, 5, arg5 );
00765       cb = static_cast<sigc::slot5<T_return, T_arg1, T_arg2,T_arg3,T_arg4,T_arg5>*>( cbptr );
00766       return ( *cb ) ( arg1, arg2, arg3, arg4, arg5 );
00767     }
00768     throw;
00769   }
00770 
00771  template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6 >
00772  inline
00773  T_return Environment::callback( void* theEnv ) {
00774    sigc::slot6<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6>* cb;
00775    void * cbptr = get_function_context( theEnv );
00776    T_arg1 arg1;
00777    T_arg2 arg2;
00778    T_arg3 arg3;
00779    T_arg4 arg4;
00780    T_arg5 arg5;
00781    T_arg6 arg6;
00782    if ( cbptr ) {
00783      if ( get_arg_count( theEnv ) != 6 )
00784        throw std::logic_error( "clipsmm: wrong # args on slot callback; expected 6" );
00785      get_argument( theEnv, 1, arg1 );
00786      get_argument( theEnv, 2, arg2 );
00787      get_argument( theEnv, 3, arg3 );
00788      get_argument( theEnv, 4, arg4 );
00789      get_argument( theEnv, 5, arg5 );
00790      get_argument( theEnv, 6, arg6 );
00791      cb = static_cast<sigc::slot6<T_return, T_arg1, T_arg2,T_arg3,T_arg4,T_arg5,T_arg6>*>( cbptr );
00792      return ( *cb ) ( arg1, arg2, arg3, arg4, arg5, arg6 );
00793    }
00794    throw;
00795  }
00796 
00797   template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7 >
00798   inline
00799   T_return Environment::callback( void* theEnv ) {
00800     sigc::slot7<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6,T_arg7>* cb;
00801     void * cbptr = get_function_context( theEnv );
00802     T_arg1 arg1;
00803     T_arg2 arg2;
00804     T_arg3 arg3;
00805     T_arg4 arg4;
00806     T_arg5 arg5;
00807     T_arg6 arg6;
00808     T_arg7 arg7;
00809     if ( cbptr ) {
00810       if ( get_arg_count( theEnv ) != 7 )
00811         throw std::logic_error( "clipsmm: wrong # args on slot callback; expected 7" );
00812       get_argument( theEnv, 1, arg1 );
00813       get_argument( theEnv, 2, arg2 );
00814       get_argument( theEnv, 3, arg3 );
00815       get_argument( theEnv, 4, arg4 );
00816       get_argument( theEnv, 5, arg5 );
00817       get_argument( theEnv, 6, arg6 );
00818       get_argument( theEnv, 7, arg7 );
00819       cb = static_cast<sigc::slot7<T_return, T_arg1, T_arg2,T_arg3,T_arg4,T_arg5,T_arg6,T_arg7>*>( cbptr );
00820       return ( *cb ) ( arg1, arg2, arg3, arg4, arg5, arg6, arg7 );
00821     }
00822     throw;
00823   }
00824 
00825   inline
00826   void* Environment::strcallback( void* theEnv ) {
00827     sigc::slot0<std::string>* cb;
00828     void * cbptr = get_function_context( theEnv );
00829     if ( cbptr ) {
00830       if ( get_arg_count( theEnv ) != 0 )
00831         throw std::logic_error( "clipsmm: wrong # args on slot callback; expected 0" );
00832       cb = static_cast<sigc::slot0<std::string>*>( cbptr );
00833       return add_symbol( ( ( *cb ) ( )).c_str() );
00834     }
00835     throw;
00836   }
00837 
00838   template < typename T_arg1 >
00839   inline
00840   void* Environment::strcallback( void* theEnv ) {
00841     sigc::slot1<std::string,T_arg1>* cb;
00842     void * cbptr = get_function_context( theEnv );
00843     T_arg1 arg1;
00844     if ( cbptr ) {
00845       if ( get_arg_count( theEnv ) != 1 )
00846         throw std::logic_error( "clipsmm: wrong # args on slot callback; expected 1" );
00847       get_argument( theEnv, 1, arg1 );
00848       cb = static_cast<sigc::slot1<std::string,T_arg1>*>( cbptr );
00849       return add_symbol( ( ( *cb ) ( arg1 )).c_str() );
00850     }
00851     throw;
00852   }
00853 
00854   template < typename T_arg1, typename T_arg2 >
00855   inline
00856   void* Environment::strcallback( void* theEnv ) {
00857     sigc::slot2<std::string, T_arg1, T_arg2>* cb;
00858     void * cbptr = get_function_context( theEnv );
00859     T_arg1 arg1;
00860     T_arg2 arg2;
00861     if ( cbptr ) {
00862       if ( get_arg_count( theEnv ) != 2 )
00863         throw std::logic_error( "clipsmm: wrong # args on slot callback; expected 2" );
00864       get_argument( theEnv, 1, arg1 );
00865       get_argument( theEnv, 2, arg2 );
00866       cb = static_cast<sigc::slot2<std::string, T_arg1, T_arg2>*>( cbptr );
00867       return add_symbol( ( ( *cb ) ( arg1, arg2 )).c_str() );
00868     }
00869     throw;
00870   }
00871 
00872   template < typename T_arg1, typename T_arg2, typename T_arg3 >
00873   inline
00874   void* Environment::strcallback( void* theEnv ) {
00875     sigc::slot3<std::string,T_arg1,T_arg2,T_arg3>* cb;
00876     void * cbptr = get_function_context( theEnv );
00877     T_arg1 arg1;
00878     T_arg2 arg2;
00879     T_arg3 arg3;
00880     if ( cbptr ) {
00881       if ( get_arg_count( theEnv ) != 3 )
00882         throw std::logic_error( "clipsmm: wrong # args on slot callback; expected 3" );
00883       get_argument( theEnv, 1, arg1 );
00884       get_argument( theEnv, 2, arg2 );
00885       get_argument( theEnv, 3, arg3 );
00886       cb = static_cast<sigc::slot3<std::string, T_arg1, T_arg2,T_arg3>*>( cbptr );
00887       return add_symbol( ( ( *cb ) ( arg1, arg2, arg3 )).c_str() );
00888     }
00889     throw;
00890   }
00891 
00892   template < typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4 >
00893   inline
00894   void* Environment::strcallback( void* theEnv ) {
00895     sigc::slot4<std::string,T_arg1,T_arg2,T_arg3,T_arg4>* cb;
00896     void * cbptr = get_function_context( theEnv );
00897     T_arg1 arg1;
00898     T_arg2 arg2;
00899     T_arg3 arg3;
00900     T_arg4 arg4;
00901     std::string s;
00902     if ( cbptr ) {
00903       if ( get_arg_count( theEnv ) != 4 )
00904         throw std::logic_error( "clipsmm: wrong # args on slot callback; expected 4" );
00905       get_argument( theEnv, 1, arg1 );
00906     std::cout << "Arg1: " << arg1 << std::endl;
00907       get_argument( theEnv, 2, arg2 );
00908     std::cout << "Arg2: " << arg2 << std::endl;
00909       get_argument( theEnv, 3, arg3 );
00910     std::cout << "Arg3: " << arg3 << std::endl;
00911       get_argument( theEnv, 4, arg4 );
00912     std::cout << "Arg4: " << arg4 << std::endl;
00913       cb = static_cast<sigc::slot4<std::string, T_arg1, T_arg2,T_arg3,T_arg4>*>( cbptr );
00914       s = ( *cb ) ( arg1, arg2, arg3, arg4 );
00915     std::cout << "Adding: " << s << std::endl;
00916       return add_symbol( s.c_str() );
00917     }
00918     throw;
00919   }
00920 
00921   template < typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5 >
00922   inline
00923   void* Environment::strcallback( void* theEnv ) {
00924     sigc::slot5<std::string,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5>* cb;
00925     void * cbptr = get_function_context( theEnv );
00926     T_arg1 arg1;
00927     T_arg2 arg2;
00928     T_arg3 arg3;
00929     T_arg4 arg4;
00930     T_arg5 arg5;
00931     if ( cbptr ) {
00932       if ( get_arg_count( theEnv ) != 5 )
00933         throw std::logic_error( "clipsmm: wrong # args on slot callback; expected 5" );
00934       get_argument( theEnv, 1, arg1 );
00935       get_argument( theEnv, 2, arg2 );
00936       get_argument( theEnv, 3, arg3 );
00937       get_argument( theEnv, 4, arg4 );
00938       get_argument( theEnv, 5, arg5 );
00939       cb = static_cast<sigc::slot5<std::string, T_arg1, T_arg2,T_arg3,T_arg4,T_arg5>*>( cbptr );
00940       return add_symbol( ( ( *cb ) ( arg1, arg2, arg3, arg4, arg5 )).c_str() );
00941     }
00942     throw;
00943   }
00944 
00945   template < typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6 >
00946   inline
00947   void* Environment::strcallback( void* theEnv ) {
00948     sigc::slot6<std::string,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6>* cb;
00949     void * cbptr = get_function_context( theEnv );
00950     T_arg1 arg1;
00951     T_arg2 arg2;
00952     T_arg3 arg3;
00953     T_arg4 arg4;
00954     T_arg5 arg5;
00955     T_arg6 arg6;
00956     if ( cbptr ) {
00957       if ( get_arg_count( theEnv ) != 6 )
00958         throw std::logic_error( "clipsmm: wrong # args on slot callback; expected 6" );
00959       get_argument( theEnv, 1, arg1 );
00960       get_argument( theEnv, 2, arg2 );
00961       get_argument( theEnv, 3, arg3 );
00962       get_argument( theEnv, 4, arg4 );
00963       get_argument( theEnv, 5, arg5 );
00964       get_argument( theEnv, 6, arg6 );
00965       cb = static_cast<sigc::slot6<std::string, T_arg1, T_arg2,T_arg3,T_arg4,T_arg5,T_arg6>*>( cbptr );
00966       return add_symbol( ( ( *cb ) ( arg1, arg2, arg3, arg4, arg5, arg6 )).c_str() );
00967     }
00968     throw;
00969   }
00970 
00971   template < typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7 >
00972   inline
00973   void* Environment::strcallback( void* theEnv ) {
00974     sigc::slot7<std::string,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6,T_arg7>* cb;
00975     void * cbptr = get_function_context( theEnv );
00976     T_arg1 arg1;
00977     T_arg2 arg2;
00978     T_arg3 arg3;
00979     T_arg4 arg4;
00980     T_arg5 arg5;
00981     T_arg6 arg6;
00982     T_arg7 arg7;
00983     if ( cbptr ) {
00984       if ( get_arg_count( theEnv ) != 7 )
00985         throw std::logic_error( "clipsmm: wrong # args on slot callback; expected 7" );
00986       get_argument( theEnv, 1, arg1 );
00987       get_argument( theEnv, 2, arg2 );
00988       get_argument( theEnv, 3, arg3 );
00989       get_argument( theEnv, 4, arg4 );
00990       get_argument( theEnv, 5, arg5 );
00991       get_argument( theEnv, 6, arg6 );
00992       get_argument( theEnv, 7, arg7 );
00993       cb = static_cast<sigc::slot7<std::string, T_arg1, T_arg2,T_arg3,T_arg4,T_arg5,T_arg6,T_arg7>*>( cbptr );
00994       return add_symbol( ( ( *cb ) ( arg1, arg2, arg3, arg4, arg5, arg6, arg7 )).c_str() );
00995     }
00996     throw;
00997   }
00998 
00999 template < typename T_return >
01000   inline
01001   bool Environment::add_function( std::string name, const sigc::slot0<T_return>& slot) {
01002     char retcode = get_return_code<T_return>( );
01003     char argstring[ 10 ] = { '0', '0', 'u', 0x00 };
01004     sigc::slot0<T_return>* scb = new sigc::slot0<T_return>(slot);
01005     any holder = CLIPSPointer<sigc::slot0<T_return> >(scb);
01006     m_slots[name] = holder;
01007     return ( EnvDefineFunction2WithContext( m_cobj,
01008                                  const_cast<char*>( name.c_str() ),
01009                                  retcode,
01010                                  get_callback(slot),
01011                                  const_cast<char*>( name.c_str() ),
01012                                  argstring,
01013                                  ( void* ) scb ) );
01014   }
01015 
01016   template < typename T_return, typename T_arg1 >
01017   inline
01018   bool Environment::add_function( std::string name, const sigc::slot1<T_return, T_arg1>& slot) {
01019     char retcode = get_return_code<T_return>( );
01020     char argstring[ 10 ] = { '1', '1', 'u', 0x00 };
01021     argstring[ 3 ] = get_argument_code<T_arg1>( );
01022     sigc::slot1<T_return, T_arg1>* scb = new sigc::slot1<T_return, T_arg1>(slot);
01023     any holder = CLIPSPointer<sigc::slot1<T_return, T_arg1> >(scb);
01024     m_slots[name] = holder;
01025     return ( EnvDefineFunction2WithContext( m_cobj,
01026                                  const_cast<char*>( name.c_str() ),
01027                                  retcode,
01028                                  get_callback(slot),
01029                                  const_cast<char*>( name.c_str() ),
01030                                  argstring,
01031                                  scb ) );
01032   }
01033 
01034   template < typename T_return, typename T_arg1, typename T_arg2 >
01035   inline
01036   bool Environment::add_function( std::string name, const sigc::slot2<T_return, T_arg1, T_arg2>& slot) {
01037     char retcode = get_return_code<T_return>( );
01038     char argstring[ 10 ] = { '2', '2', 'u', 0x00 };
01039     argstring[ 3 ] = get_argument_code<T_arg1>( );
01040     argstring[ 4 ] = get_argument_code<T_arg2>( );
01041     sigc::slot2<T_return, T_arg1, T_arg2>* scb = new sigc::slot2<T_return, T_arg1, T_arg2>(slot);
01042     any holder = CLIPSPointer<sigc::slot2<T_return, T_arg1, T_arg2> >(scb);
01043     m_slots[name] = holder;
01044     return ( EnvDefineFunction2WithContext( m_cobj,
01045                                  const_cast<char*>( name.c_str() ),
01046                                  retcode,
01047                                  get_callback(slot),
01048                                  const_cast<char*>( name.c_str() ),
01049                                  argstring,
01050                                  scb ) );
01051   }
01052 
01053   template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3 >
01054   inline
01055   bool Environment::add_function( std::string name, const sigc::slot3<T_return,T_arg1,T_arg2,T_arg3>& slot) {
01056     char retcode = get_return_code<T_return>( );
01057     char argstring[ 10 ] = { '3', '3', 'u', 0x00 };
01058     argstring[ 3 ] = get_argument_code<T_arg1>( );
01059     argstring[ 4 ] = get_argument_code<T_arg2>( );
01060     argstring[ 5 ] = get_argument_code<T_arg3>( );
01061     sigc::slot3<T_return,T_arg1,T_arg2,T_arg3>* scb =
01062         new sigc::slot3<T_return,T_arg1,T_arg2,T_arg3>(slot);
01063     any holder = CLIPSPointer<sigc::slot3<T_return,T_arg1,T_arg2,T_arg3> >(scb);
01064     m_slots[name] = holder;
01065     return ( EnvDefineFunction2WithContext( m_cobj,
01066                                  const_cast<char*>( name.c_str() ),
01067                                  retcode,
01068                                  get_callback(slot),
01069                                  const_cast<char*>( name.c_str() ),
01070                                  argstring,
01071                                  scb )
01072            );
01073   }
01074 
01075   template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4 >
01076   inline
01077   bool Environment::add_function( std::string name, const sigc::slot4<T_return,T_arg1,T_arg2,T_arg3,T_arg4>& slot) {
01078     char retcode = get_return_code<T_return>( );
01079     char argstring[ 10 ] = { '4', '4', 'u', 0x00 };
01080     argstring[ 3 ] = get_argument_code<T_arg1>( );
01081     argstring[ 4 ] = get_argument_code<T_arg2>( );
01082     argstring[ 5 ] = get_argument_code<T_arg3>( );
01083     argstring[ 6 ] = get_argument_code<T_arg4>( );
01084     sigc::slot4<T_return,T_arg1,T_arg2,T_arg3,T_arg4>* scb =
01085         new sigc::slot4<T_return,T_arg1,T_arg2,T_arg3,T_arg4>(slot);
01086     any holder = CLIPSPointer<sigc::slot4<T_return,T_arg1,T_arg2,T_arg3,T_arg4> >(scb);
01087     m_slots[name] = holder;
01088     return ( EnvDefineFunction2WithContext( m_cobj,
01089                                  const_cast<char*>( name.c_str() ),
01090                                  retcode,
01091                                  get_callback(slot),
01092                                  const_cast<char*>( name.c_str() ),
01093                                  argstring,
01094                                  scb )
01095            );
01096   }
01097 
01098   template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5 >
01099   inline
01100   bool Environment::add_function( std::string name,
01101                               const sigc::slot5<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5>& slot) {
01102     char retcode = get_return_code<T_return>( );
01103     char argstring[ 10 ] = { '5', '5', 'u', 0x00 };
01104     argstring[ 3 ] = get_argument_code<T_arg1>( );
01105     argstring[ 4 ] = get_argument_code<T_arg2>( );
01106     argstring[ 5 ] = get_argument_code<T_arg3>( );
01107     argstring[ 6 ] = get_argument_code<T_arg4>( );
01108     argstring[ 7 ] = get_argument_code<T_arg5>( );
01109     sigc::slot5<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5>* scb =
01110         new sigc::slot5<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5>(slot);
01111     any holder = CLIPSPointer<sigc::slot5<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5> >(scb);
01112     m_slots[name] = holder;
01113     return ( EnvDefineFunction2WithContext( m_cobj,
01114                                  const_cast<char*>( name.c_str() ),
01115                                  retcode,
01116                                  get_callback(slot),
01117                                  const_cast<char*>( name.c_str() ),
01118                                  argstring,
01119                                  scb )
01120            );
01121   }
01122 
01123   template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6 >
01124   inline
01125   bool Environment::add_function( std::string name,
01126                               const sigc::slot6<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6>& slot) {
01127     char retcode = get_return_code<T_return>( );
01128     char argstring[ 10 ] = { '6', '6', 'u', 0x00 };
01129     argstring[ 3 ] = get_argument_code<T_arg1>( );
01130     argstring[ 4 ] = get_argument_code<T_arg2>( );
01131     argstring[ 5 ] = get_argument_code<T_arg3>( );
01132     argstring[ 6 ] = get_argument_code<T_arg4>( );
01133     argstring[ 7 ] = get_argument_code<T_arg5>( );
01134     argstring[ 8 ] = get_argument_code<T_arg6>( );
01135     sigc::slot6<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6>* scb =
01136         new sigc::slot6<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6>(slot);
01137     any holder = CLIPSPointer<sigc::slot6<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6> >(scb);
01138     m_slots[name] = holder;
01139     return ( EnvDefineFunction2WithContext( m_cobj,
01140                                  const_cast<char*>( name.c_str() ),
01141                                  retcode,
01142                                  get_callback(slot),
01143                                  const_cast<char*>( name.c_str() ),
01144                                  argstring,
01145                                  scb )
01146            );
01147   }
01148 
01149   template < typename T_return, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7 >
01150   inline
01151   bool Environment::add_function( std::string name,
01152                                   const sigc::slot7<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6,T_arg7>& slot) {
01153     char retcode = get_return_code<T_return>( );
01154     char argstring[ 10 ] = { '7', '7', 'u', 0x00 };
01155     argstring[ 3 ] = get_argument_code<T_arg1>( );
01156     argstring[ 4 ] = get_argument_code<T_arg2>( );
01157     argstring[ 5 ] = get_argument_code<T_arg3>( );
01158     argstring[ 6 ] = get_argument_code<T_arg4>( );
01159     argstring[ 7 ] = get_argument_code<T_arg5>( );
01160     argstring[ 8 ] = get_argument_code<T_arg6>( );
01161     argstring[ 9 ] = get_argument_code<T_arg7>( );
01162     sigc::slot7<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6,T_arg7>* scb =
01163         new sigc::slot7<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6,T_arg7>(slot);
01164     any holder = CLIPSPointer<sigc::slot7<T_return,T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6,T_arg7> >(scb);
01165     m_slots[name] = holder;
01166     return ( EnvDefineFunction2WithContext( m_cobj,
01167                                  const_cast<char*>( name.c_str() ),
01168                                  retcode,
01169                                  get_callback(slot),
01170                                  const_cast<char*>( name.c_str() ),
01171                                  argstring,
01172                                  scb )
01173            );
01174   }
01175 
01176 
01177 }
01178 
01179 
01180 
01340 #endif

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