From 1a3c110a94ca38cc41ca773282b4555b8da2cac5 Mon Sep 17 00:00:00 2001 From: w1z7ard Date: Tue, 9 Oct 2007 15:57:34 +0000 Subject: [PATCH] encapsulated more data in Func class. git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/trunk@554 6778bc44-b910-0410-a7a0-be141de4315d --- src/projectM-engine/BuiltinFuncs.cpp | 4 ++-- src/projectM-engine/Func.hpp | 31 ++++++++++++++++++++-------- src/projectM-engine/Parser.cpp | 10 ++++----- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/projectM-engine/BuiltinFuncs.cpp b/src/projectM-engine/BuiltinFuncs.cpp index 8668bec3c..f3ace3dd5 100644 --- a/src/projectM-engine/BuiltinFuncs.cpp +++ b/src/projectM-engine/BuiltinFuncs.cpp @@ -145,10 +145,10 @@ int BuiltinFuncs::insert_func( Func *func ) { assert(func); std::pair::iterator, bool> inserteePair = - builtin_func_tree.insert(std::make_pair(std::string(func->name), func)); + builtin_func_tree.insert(std::make_pair(std::string(func->getName()), func)); if (!inserteePair.second) { - std::cerr << "Failed to insert builtin function \"" << func->name << "\" into collection! Bailing..." << std::endl; + std::cerr << "Failed to insert builtin function \"" << func->getName() << "\" into collection! Bailing..." << std::endl; abort(); } diff --git a/src/projectM-engine/Func.hpp b/src/projectM-engine/Func.hpp index 96d95cc56..f7f89285d 100755 --- a/src/projectM-engine/Func.hpp +++ b/src/projectM-engine/Func.hpp @@ -35,20 +35,33 @@ /* Function Type */ class Func { public: - std::string name; - float (*func_ptr)(float*); - int num_args; - Func(const std::string & _name, float (*func_ptr)(float*), int num_args ); + /// Create a new function wrapper object + /// \param name a name to uniquely identify the function. + /// \param func_ptr a pointer to a function of floating point arguments + /// \param num_args the number of floating point arguments this function requires + Func(const std::string & name, float (*func_ptr)(float*), int num_args ); /* Public Prototypes */ DLLEXPORT ~Func(); - }; + inline const std::string & getName() const { + return name; + } -/** Splay traversal */ -inline void free_func_helper( void *func ) { - delete (Func *)func; -} + inline void * getFuncPtr() { + return func_ptr; + } + + inline int getNumArgs() const { + return num_args; + } + +private: + std::string name; + float (*func_ptr)(float*); + int num_args; + +}; #endif /** !_FUNC_H */ diff --git a/src/projectM-engine/Parser.cpp b/src/projectM-engine/Parser.cpp index 878ce7650..20d0f0054 100755 --- a/src/projectM-engine/Parser.cpp +++ b/src/projectM-engine/Parser.cpp @@ -779,11 +779,11 @@ GenExpr * Parser::parse_gen_expr ( std::istream & fs, TreeExpr * tree_expr, Pre if (PARSE_DEBUG) { std::cerr << "parse_gen_expr: found prefix function (name = \"" - << func->name << "\") (LINE " << line_count << ")" << std::endl; + << func->getName() << "\") (LINE " << line_count << ")" << std::endl; } /* Parse the functions arguments */ - if ((expr_list = parse_prefix_args(fs, func->num_args, preset)) == NULL) + if ((expr_list = parse_prefix_args(fs, func->getNumArgs(), preset)) == NULL) { if (PARSE_DEBUG) { @@ -798,21 +798,19 @@ GenExpr * Parser::parse_gen_expr ( std::istream & fs, TreeExpr * tree_expr, Pre } /* Convert function to expression */ - if ((gen_expr = GenExpr::prefun_to_expr((float (*)(void *))func->func_ptr, expr_list, func->num_args)) == NULL) + if ((gen_expr = GenExpr::prefun_to_expr((float (*)(void *))func->getFuncPtr(), expr_list, func->getNumArgs())) == NULL) { if (PARSE_DEBUG) printf("parse_prefix_args: failed to convert prefix function to general expression (LINE %d) \n", line_count); if (tree_expr) delete tree_expr; - for (i = 0; i < func->num_args;i++) + for (i = 0; i < func->getNumArgs();i++) delete expr_list[i]; free(expr_list); expr_list = NULL; return NULL; } - - token = parseToken(fs, string); if (*string != 0)