47 static unsigned int object_count = 0;
 
   50     name(Name), otype(
"EGS_Object"), nref(0), factory(f) {
 
   59     name(
""), otype(
"EGS_Object"), nref(0), factory(f) {
 
   65 EGS_Object::~EGS_Object() {
 
   89         sprintf(buf,
"object_%d",object_count);
 
  111         static const char *locations[] = {
"HEN_HOUSE",
"EGS_HOME"};
 
  112         int i = !where ? 0 : 1;
 
  113         char *loc = getenv(locations[i]);
 
  115             egsFatal(
"EGS_ObjectFactory: the environment variable " 
  116                      "%s must be defined\n",locations[i]);
 
  130     for (j=0; j<
objects.size(); j++) {
 
  137     for (j=0; j<
libs.size(); j++) {
 
  143     for (vector<EGS_Object *>::iterator i = 
objects.begin();
 
  157         const string §ion_delimeter, 
const string &object_delimeter,
 
  158         const string &select_key, 
const char *funcname, 
bool unique) {
 
  160         egsWarning(
"EGS_ObjectFactory::createObjects(): null input?\n");
 
  164     if (!i->
isA(section_delimeter)) {
 
  167             egsWarning(
"EGS_ObjectFactory::createObjects(): the input is" 
  168                        " not of type %s and also does not have items of this type\n",
 
  169                        section_delimeter.c_str());
 
  182     if (errors) 
egsWarning(
"EGS_ObjectFactory::createObjects(): %d errors" 
  183                                " occured while creating objects\n",errors);
 
  184     string sought_object;
 
  189     int err = input->
getInput(select_key,sought_object);
 
  192         if (!o) 
egsWarning(
"EGS_ObjectFactory::createObjects(): an object " 
  193                                "with the name %s does not exist\n",sought_object.c_str());
 
  200         const char *funcname, 
bool unique) {
 
  202         egsWarning(
"EGS_ObjectFactory::createSingleObject(): null input?\n");
 
  220     int error = i->
getInput(
"library",libname);
 
  222         if (err) 
egsWarning(
"EGS_ObjectFactory::createObject(): \n" 
  223                                 "  input item %s does not define an object type or an object " 
  224                                 "library\n",i->
name());
 
  225         else egsWarning(
"EGS_ObjectFactory::createObject(): input item %s\n" 
  226                             "  don't know anything about object type %s and no object" 
  227                             "library defined\n",i->
name(),type.c_str());
 
  231     for (
unsigned int j=0; j<
libs.size(); j++) {
 
  232         if (libname == 
libs[j]->libraryName()) {
 
  241             egsWarning(
"EGS_ObjectFactory::createObject(): " 
  242                        "failed to load the library %s from %s\n",
 
  248     EGS_ObjectCreationFunction create;
 
  249     const char *fname = funcname ? funcname : 
"createObject";
 
  250     create = (EGS_ObjectCreationFunction) lib->
resolve(fname);
 
  252         egsWarning(
"EGS_ObjectFactory::createObject():\n" 
  253                    "  failed to resolve the '%s' function in the library %s\n",
 
  267         egsWarning(
"EGS_ObjectFactory::addObject(): attempt to add a null" 
  271     for (
unsigned int j=0; j<
objects.size(); j++) {
 
  277         for (
unsigned int j=0; j<
objects.size(); j++) {
 
  279                 egsWarning(
"EGS_ObjectFactory::addObject(): an object with " 
  294     for (
unsigned int j=0; j<
objects.size(); j++) {
 
  303     for (
unsigned int j=0; j<
objects.size(); j++) {
 
  304         if (name == 
objects[j]->getObjectName()) {
 
  312     for (vector<EGS_Object *>::iterator i = 
objects.begin();
 
  314         if ((*i)->getObjectName() == name) {
 
A class for dynamically loading shared libraries.
const char * libraryName() const
Returns the name of the library object as given in the constructor.
bool isLoaded() const
Returns true if the library is loaded, false otherwise.
bool load()
Loads the library.
void * resolve(const char *func)
Returns the address of the exported symbol func.
void removeObject(EGS_Object *o)
Remove o from the list of objects.
vector< EGS_Object * > objects
Created objects.
virtual bool addObject(EGS_Object *o, bool unique=true)
Add the object o to the factory's list of objects.
void addKnownTypeId(const char *typeid_name)
Add a known typeid to this factory.
virtual ~EGS_ObjectFactory()
Destructor.
vector< string > known_typeids
Known typeid's.
string dso_path
The path to look for DSOs.
vector< EGS_Object * > known_objects
known Objects
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.
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.
EGS_Object * getObject(const string &Name)
Get the object named Name.
vector< EGS_Library * > libs
DSOs loaded so far.
EGS_Object * takeObject(const string &Name)
Take the object named Name from the list of objects.
bool haveObject(const EGS_Object *o) const
Does the factory own the object pointed to by o?
EGS_ObjectFactory(const string &dsoPath, int where=0)
Create an object factory that will load shared libraries from the directory dsoPath.
void setName(EGS_Input *inp)
Set the name of the object from the information provided by inp.
EGS_ObjectFactory * factory
The factory this object belongs to.
static void deleteObject(EGS_Object *o)
Delete an object.
void setFactory(EGS_ObjectFactory *f)
Set the factory to which the object belongs.
const string & getObjectType() const
Get the object type.
const string & getObjectName() const
Get the object name.
static string getUniqueName(const EGS_Object *o=0)
Create and return a unique object name.
string name
The object name.
EGS_Object(const string &Name="", EGS_ObjectFactory *f=0)
Create an EGS_Object named Name belonging to the object factory f.
int deref()
Decrease the reference count to this object.
EGS_Library class header file.
EGS_Object and EGS_ObjectFactory class header file.
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
bool egsIsAbsolutePath(const string &path)
Does the string path represent an absolute path 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...
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.