00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00037
#ifndef TYPEFACTORY_H
00038
#define TYPEFACTORY_H
00039
00040
#include <string>
00041
#include <map>
00042
00043
#include "OptionBase.h"
00044
00045
namespace PLearn {
00046
using namespace std;
00047
00048
00049
class Object;
00050
00053 typedef Object* (*NEW_OBJECT)();
00054 typedef OptionList& (*GETOPTIONLIST_METHOD)();
00055 typedef bool (*ISA_METHOD)(
Object* o);
00056
00057 class TypeMapEntry
00058 {
00059
public:
00060 string type_name;
00061 string parent_class;
00062 NEW_OBJECT constructor;
00063 GETOPTIONLIST_METHOD getoptionlist_method;
00064 ISA_METHOD isa_method;
00065 string one_line_descr;
00066 string multi_line_help;
00067
00068 TypeMapEntry(
const string& the_type_name,
00069
const string& the_parent_class=
"",
00070 NEW_OBJECT the_constructor=0,
00071 GETOPTIONLIST_METHOD the_getoptionlist_method=0,
00072 ISA_METHOD the_isa_method=0,
00073
const string& the_one_line_descr =
"",
00074
const string& the_multi_line_help =
"")
00075 :
type_name(the_type_name),
00076
parent_class(the_parent_class),
00077
constructor(the_constructor),
00078
getoptionlist_method(the_getoptionlist_method),
00079
isa_method(the_isa_method),
00080
one_line_descr(the_one_line_descr),
00081
multi_line_help(the_multi_line_help)
00082 {}
00083 };
00084
00085 typedef map<string,TypeMapEntry>
TypeMap;
00086
00087
00088
00090
00091 class TypeFactory
00092 {
00093
protected:
00094 TypeMap type_map_;
00095
00096
public:
00097
00098
00100
static void register_type(
const string& type_name,
00101
const string& parent_class,
00102 NEW_OBJECT constructor,
00103 GETOPTIONLIST_METHOD getoptionlist_method,
00104 ISA_METHOD isa_method,
00105
const string& one_line_descr,
00106
const string& multi_line_help);
00107
00109
void registerType(
const TypeMapEntry& entry);
00110
00112
void unregisterType(
string type_name);
00113
00115
bool isRegistered(
string type_name)
const;
00116
00119
Object*
newObject(
string type_name)
const;
00120
00123
bool isAbstract(
string type_name)
const;
00124
00125 const TypeMap&
getTypeMap()
const
00126
{
return type_map_; }
00127
00129
static TypeFactory&
instance();
00130
00131 };
00132
00133
00135
void displayObjectHelp(ostream& out,
const string& classname);
00136
00137
00138 }
00139
00140
#endif