45 static unsigned int object_count = 0;
48 name(Name), otype(
"EGS_Object"), nref(0), factory(f) {
57 name(
""), otype(
"EGS_Object"), nref(0), factory(f) {
63 EGS_Object::~EGS_Object() {
87 sprintf(buf,
"object_%d",object_count);
109 static const char *locations[] = {
"HEN_HOUSE",
"EGS_HOME"};
110 int i = !where ? 0 : 1;
111 char *loc = getenv(locations[i]);
113 egsFatal(
"EGS_ObjectFactory: the environment variable "
114 "%s must be defined\n",locations[i]);
128 for (j=0; j<
objects.size(); j++) {
135 for (j=0; j<
libs.size(); j++) {
141 for (vector<EGS_Object *>::iterator i =
objects.begin();
155 const string §ion_delimeter,
const string &object_delimeter,
156 const string &select_key,
const char *funcname,
bool unique) {
158 egsWarning(
"EGS_ObjectFactory::createObjects(): null input?\n");
161 EGS_Input *input = i;
162 if (!i->
isA(section_delimeter)) {
165 egsWarning(
"EGS_ObjectFactory::createObjects(): the input is"
166 " not of type %s and also does not have items of this type\n",
167 section_delimeter.c_str());
180 if (errors)
egsWarning(
"EGS_ObjectFactory::createObjects(): %d errors"
181 " occured while creating objects\n",errors);
182 string sought_object;
187 int err = input->
getInput(select_key,sought_object);
190 if (!o)
egsWarning(
"EGS_ObjectFactory::createObjects(): an object "
191 "with the name %s does not exist\n",sought_object.c_str());
198 const char *funcname,
bool unique) {
200 egsWarning(
"EGS_ObjectFactory::createSingleObject(): null input?\n");
218 int error = i->
getInput(
"library",libname);
220 if (err)
egsWarning(
"EGS_ObjectFactory::createObject(): \n"
221 " input item %s does not define an object type or an object "
222 "library\n",i->
name());
223 else egsWarning(
"EGS_ObjectFactory::createObject(): input item %s\n"
224 " don't know anything about object type %s and no object"
225 "library defined\n",i->
name(),type.c_str());
229 for (
unsigned int j=0; j<
libs.size(); j++) {
230 if (libname ==
libs[j]->libraryName()) {
239 egsWarning(
"EGS_ObjectFactory::createObject(): "
240 "failed to load the library %s from %s\n",
246 EGS_ObjectCreationFunction create;
247 const char *fname = funcname ? funcname :
"createObject";
248 create = (EGS_ObjectCreationFunction) lib->
resolve(fname);
250 egsWarning(
"EGS_ObjectFactory::createObject():\n"
251 " failed to resolve the '%s' function in the library %s\n",
265 egsWarning(
"EGS_ObjectFactory::addObject(): attempt to add a null"
269 for (
unsigned int j=0; j<
objects.size(); j++) {
275 for (
unsigned int j=0; j<
objects.size(); j++) {
277 egsWarning(
"EGS_ObjectFactory::addObject(): an object with "
292 for (
unsigned int j=0; j<
objects.size(); j++) {
301 for (
unsigned int j=0; j<
objects.size(); j++) {
302 if (name ==
objects[j]->getObjectName()) {
310 for (vector<EGS_Object *>::iterator i =
objects.begin();
312 if ((*i)->getObjectName() == name) {
virtual EGS_Object * createSingleObject(EGS_Input *inp, const char *funcname=0, bool unique=true)
Create a single object from the information pointed to by inp.
bool haveObject(const EGS_Object *o) const
Does the factory own the object pointed to by o?
void removeObject(EGS_Object *o)
Remove o from the list of objects.
EGS_Object(const string &Name="", EGS_ObjectFactory *f=0)
Create an EGS_Object named Name belonging to the object factory f.
A class for dynamically loading shared libraries.
virtual ~EGS_ObjectFactory()
Destructor.
bool egsIsAbsolutePath(const string &path)
Does the string path represent an absolute path name?
vector< EGS_Library * > libs
DSOs loaded so far.
const string & getObjectName() const
Get the object name.
const char * libraryName() const
Returns the name of the library object as given in the constructor.
static string getUniqueName(const EGS_Object *o=0)
Create and return a unique object name.
string egsJoinPath(const string &first, const string &second)
Join two path variables (or a path and a file name) using the platform specific directory separator a...
static void deleteObject(EGS_Object *o)
Delete an object.
EGS_ObjectFactory * factory
The factory this object belongs to.
vector< string > known_typeids
Known typeid's.
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
EGS_ObjectFactory(const string &dsoPath, int where=0)
Create an object factory that will load shared libraries from the directory dsoPath.
EGS_Object * createObjects(EGS_Input *inp, const string §ion_delimeter, const string &object_delimeter, const string &select_key, const char *funcname=0, bool unique=true)
Create all objects specified by the information inp.
void setFactory(EGS_ObjectFactory *f)
Set the factory to which the object belongs.
EGS_Library class header file.
int deref()
Decrease the reference count to this object.
EGS_Object * takeObject(const string &Name)
Take the object named Name from the list of objects.
void setName(EGS_Input *inp)
Set the name of the object from the information provided by inp.
const string & getObjectType() const
Get the object type.
virtual bool addObject(EGS_Object *o, bool unique=true)
Add the object o to the factory's list of objects.
bool load()
Loads the library.
void addKnownTypeId(const char *typeid_name)
Add a known typeid to this factory.
string name
The object name.
EGS_Object and EGS_ObjectFactory class header file.
void * resolve(const char *func)
Returns the address of the exported symbol func.
EGS_Object * getObject(const string &Name)
Get the object named Name.
string dso_path
The path to look for DSOs.
vector< EGS_Object * > known_objects
known Objects
vector< EGS_Object * > objects
Created objects.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.
bool isLoaded() const
Returns true if the library is loaded, false otherwise.