void Dynamic::Output(Lex& lex, FILE *h, FILE *cpp, const char *class_name) { static int count = 0; Param *next; Func *func; count++; fprintf(cpp, "struct __func%d_t {\n" "\tmolib::mo_name_t f_name;\n" "\tvoid (%s::*f_func)(", count, class_name); if(f_timed) { fprintf(cpp, "time_t __time"); } next = f_params; while(next != 0) { if(next != f_params || f_timed) { fprintf(cpp, ", "); } fprintf(cpp, "%s", next->f_type); next = next->f_next; } fprintf(cpp, ");\n" "};\n" "static molib::moBase::compare_t __compare_func%d(const void *a, const void *b)\n" "{\n" "\treturn molib::moBase::CompareInt(" "reinterpret_cast<const __func%d_t *>(a)->f_name, " "reinterpret_cast<const __func%d_t *>(b)->f_name);\n" "}\n" , count, count, count); fprintf(h, "\tvirtual void %s(const molib::moName& __name", f_name); fprintf(cpp, "void %s::%s(const molib::moName& __name", class_name, f_name); if(f_timed) { fprintf(h, ", time_t __time"); fprintf(cpp, ", time_t __time"); } next = f_params; while(next != 0) { fprintf(h, ", %s", next->f_type); fprintf(cpp, ", %s", next->f_type); if(next->f_default_value != 0) { fprintf(h, " = %s", next->f_default_value); } next = next->f_next; } fprintf(h, ");\n"); fprintf(cpp, ")\n" "{\n" "\tmolib::moSortedArray __array(sizeof(__func%d_t), &__compare_func%d);\n" "\t__func%d_t __f;\n" "\tif(__array.Count() == 0) {\n" "\t\tconst molib::moNamePool& __pool = molib::moNamePool::GetNamePool();\n", count, count, count); // We first insert all the '*::<name>' because // they will always be in front of all the other // entries! (the name of an interface has to // start with [A-Za-z_]) func = f_funcs; while(func != 0) { fprintf(cpp, "\t\t__f.f_name = __pool.Get(\"*::%s\");\n" "\t\t__f.f_func = &%s::%s;\n" "\t\t__array.Insert(&__f);\n", func->GetName(), class_name, func->GetName()); func = func->Next(); } func = f_funcs; while(func != 0) { fprintf(cpp, "\t\t__f.f_name = __pool.Get(\"%s::%s\");\n" "\t\t__f.f_func = &%s::%s;\n" "\t\t__array.Insert(&__f);\n", class_name, func->GetName(), class_name, func->GetName()); func = func->Next(); } fprintf(cpp, "\t}\n" "\t__f.f_name = __name;\n" "\tmolib::moArray::position_t __pos = __array.Find(&__f);\n" "\tif(__pos != molib::moArray::NO_POSITION) {\n" "\t\t(this->*reinterpret_cast<const __func%d_t *>(__array.Get(__pos))->f_func)(", count); if(f_timed) { fprintf(cpp, "__time"); } next = f_params; while(next != 0) { if(next != f_params || f_timed) { fprintf(cpp, ", "); } fprintf(cpp, "%s", next->f_name); next = next->f_next; } fprintf(cpp, ");\n" "\t}\n" "}\n" "\n"); }