encapsulated more data in Func class.

git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/trunk@554 6778bc44-b910-0410-a7a0-be141de4315d
This commit is contained in:
w1z7ard
2007-10-09 15:57:34 +00:00
parent 9d673f4e8b
commit 1a3c110a94
3 changed files with 28 additions and 17 deletions

View File

@ -145,10 +145,10 @@ int BuiltinFuncs::insert_func( Func *func ) {
assert(func);
std::pair<std::map<std::string, Func*>::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();
}

View File

@ -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 */

View File

@ -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)