#include <Object.h>
Inheritance diagram for Object::Factory:
Static Public Methods | |
Object * | create (std::string class_name) |
Create an object for the given class. | |
bool | is_recognized_class (std::string class_name) |
Return true if a factory is ready to create objects of this class. | |
Public Attributes | |
const std::string | production_type |
The class name. | |
Protected Methods | |
Factory (std::string production_type) | |
Create a factory and register it as handling a class name. | |
virtual | ~Factory () |
This method unregisters the class. | |
virtual Object * | create ()=0 |
Create an object. | |
Private Types | |
typedef std::vector< Factory * > | Factories |
typedef Factories::iterator | iterator |
Static Private Methods | |
Factories & | get_factories () |
Return all the created factory objects. | |
Factory * | find_factory (std::string class_name) |
Returned a pointer to the Factory assigned to create Entities of type <class_name>. |
Each factory is in charge with making a certain class of objects. It is registered with the class name it supports, and called as needed when reading in a drawing file. Factory is subclassed as an inner class in most Tool subclasses and DrawElement subclasses. It's used by XMLDrawFile to create objects from the names it reads from the draw file.
|
|
|
|
|
Create a factory and register it as handling a class name.
00103 : production_type(p_type) 00104 { 00105 // quality control: 00106 if (production_type.empty()) 00107 throw invalid_argument("Object::Factory: received an empty type name"); 00108 00109 // make sure that no other Factory produces the same "type" of Object. 00110 if (is_recognized_class(production_type)) 00111 throw runtime_error("Factory for " + production_type + " already exists."); 00112 00113 get_factories().push_back(this); 00114 // add this Factory to the set of known Factories. 00115 } |
|
This method unregisters the class. This method currently does nothing.
00123 {
00124 // get_factories().remove(this);
00125 }
|
|
Create an object.
Implemented in Circle::Factory, CircleTool::Factory, ColorTool::Factory, CutTool::Factory, Drawing::Factory, ExitTool::Factory, Group::Factory, MoveTool::Factory, MutateTool::Factory, Rectangle::Factory, RectangleTool::Factory, SelectTool::Factory, ToBackTool::Factory, and ToFrontTool::Factory. |
|
Create an object for the given class.
00134 { 00135 Factory* f = find_factory(cl_name); 00136 00137 // if the class has no Factory, throw an exception. 00138 if (!f) 00139 { 00140 throw unknown_class(cl_name); 00141 } 00142 00143 return f -> create(); 00144 } |
|
Returned a pointer to the Factory assigned to create Entities of type <class_name>. If no Factory was found, returned NULL. This is accomplished by a simple linear search of the known factories.
00083 { 00084 Factories& factories = get_factories(); 00085 iterator begin = factories.begin(), end = factories.end(); 00086 00087 // search the Factories from begin to end. 00088 for (iterator i = begin; i != end; ++i) 00089 if (class_name == (*i) -> production_type) 00090 return (*i); 00091 00092 return NULL; 00093 // since none was found in the loop, return NULL. 00094 } |
|
Return all the created factory objects. This is stored as a static vector declade inside the function that is returned to the caller.
00071 { 00072 static Factories known_factories; 00073 return known_factories; 00074 } |
|
Return true if a factory is ready to create objects of this class. Uses find_factory to see if the Factory exists.
00152 { 00153 return bool(find_factory(class_name)); 00154 } |
|
The class name.
|