DefaultScriptingFunctions.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   (c) Art Tevs, MPI Informatik Saarbruecken                             *
00004  *       mailto: <tevs@mpi-sb.mpg.de>                                      *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  *                                                                         *
00011  ***************************************************************************/
00012 
00013 namespace nrEngine{
00014 
00015         //------------------------------------------------------------------------
00016         // Helper class for default scripting functions
00017         //------------------------------------------------------------------------
00018         class DefaultScriptingFunctions
00019         {
00020                 public:
00021                         static void addMethods()
00022                         {
00023                                 Engine::sScriptEngine()->add("set", set);
00024                                 Engine::sScriptEngine()->add("get", get);
00025                                 Engine::sScriptEngine()->add("list", list);
00026                         }
00027 
00028 
00029                         static void delMethods()
00030                         {
00031                                 Engine::sScriptEngine()->del("set");
00032                                 Engine::sScriptEngine()->del("get");
00033                                 Engine::sScriptEngine()->del("list");
00034                         }
00035                 
00036                 private:
00037 
00038                         /**
00039                          * Set new value to specified property in the property database
00040                          **/
00041                         ScriptFunctionDef(set);
00042 
00043                         /**
00044                          * Get value of specified property
00045                          **/
00046                         ScriptFunctionDef(get);
00047 
00048                         /**
00049                          * List all properties in specified group
00050                          **/
00051                         ScriptFunctionDef(list);
00052                         
00053         };
00054 
00055         //----------------------------------------------------------------------------------
00056         ScriptFunctionDec(set, DefaultScriptingFunctions)
00057         {
00058                 // check parameter count
00059                 if (args.size() < 3){
00060                         return ScriptResult(std::string("Not valid parameter count! Parameters (value, name, [group])"));
00061                 }
00062 
00063                 // get parameters
00064                 std::string value, name, group;
00065                 value = args[1];
00066                 name  = args[2];
00067                 if (args.size() > 3) group = args[3];
00068 
00069                 // set new value to the property
00070                 Engine::sPropertyManager()->set(Property(name, value), name, group);
00071                 return ScriptResult();
00072         }
00073         
00074         //----------------------------------------------------------------------------------
00075         ScriptFunctionDec(get, DefaultScriptingFunctions)
00076         {
00077                 // check parameter count
00078                 if (args.size() < 1){
00079                         return ScriptResult(std::string("Not valid parameter count! Parameters (name, [group])"));
00080                 }
00081 
00082                 // get parameters
00083                 std::string name, group;
00084                 name  = args[1];
00085                 if (args.size() > 2) group = args[2];
00086 
00087                 // set new value to the property
00088                 Property& p = Engine::sPropertyManager()->getProperty(name, group);
00089                 return ScriptResult(p.getValue());
00090         }
00091 
00092         //----------------------------------------------------------------------------------
00093         ScriptFunctionDec(list, DefaultScriptingFunctions)
00094         {
00095                 // get parameters
00096                 std::string group;
00097                 if (args.size() > 1) group = args[1];
00098 
00099                 // get list of all properties from the db
00100                 const PropertyList& l = Engine::sPropertyManager()->getPropertyList(group);
00101 
00102                 // iterate through the list
00103                 ScriptResult res;
00104                 for (PropertyList::const_iterator it = l.begin(); it != l.end(); it++){
00105                         res , it->getValue();
00106                 }
00107                 
00108                 // set new value to the property
00109                 return res;
00110         }
00111 
00112 };
00113 

Generated on Wed Sep 12 23:19:42 2007 for nrEngine by  doxygen 1.5.1