OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimObjectFactoryRegistry.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: See top level LICENSE.txt file.
5 //
6 // Author: Garrett Potts
7 //
8 //*************************************************************************
9 // $Id: ossimObjectFactoryRegistry.cpp 22650 2014-02-28 14:39:20Z gpotts $
10 
12 
13 RTTI_DEF1(ossimObjectFactoryRegistry, "ossimObjectFactoryRegistry", ossimObject);
17 #include <ossim/base/ossimString.h>
18 #include <ossim/base/ossimRefPtr.h>
19 using namespace std;
20 
21 
23 {
24  registerFactory(ossimBaseObjectFactory::instance());
25 }
26 
28 {
29 }
30 
32 {
33  static ossimObjectFactoryRegistry sharedInstance;
34 
35  return &sharedInstance;
36 }
37 
38 #if 0
40 {
41  return registerFactory(factory);
42 }
43 
45 {
46  if(factory)
47  {
48  if(!findFactory(factory))
49  {
50  theFactoryList.push_back(factory);
51  return true;
52  }
53  else
54  {
55  return true;
56  }
57  }
58 
59  return false;
60 }
61 
63 {
64  vector<ossimObjectFactory*>::iterator iter = theFactoryList.begin();
65 
66  while(iter != theFactoryList.end())
67  {
68  if( (*iter) == factory)
69  {
70  theFactoryList.erase(iter);
71  return;
72  }
73  ++iter;
74  }
75 }
76 
78 {
79  ossimObject* result = NULL;
80  unsigned long index = 0;
81 
82  while((index < theFactoryList.size()) &&(!result))
83  {
84  result = theFactoryList[index]->createObject(name);
85  ++index;
86  }
87  return result;
88 }
89 
91  const char* prefix)const
92 {
93  ossimObject* result = NULL;
94  unsigned long index = 0;
95 
96  while((index < theFactoryList.size()) &&(!result))
97  {
98  result = theFactoryList[index]->createObject(kwl,
99  prefix);
100  ++index;
101  }
102 
103  return result;
104 }
105 
106 void ossimObjectFactoryRegistry::getTypeNameList(std::vector<ossimString>& typeList)const
107 {
108  vector<ossimString> result;
109  vector<ossimObjectFactory*>::const_iterator iter = theFactoryList.begin();
110 
111  while(iter != theFactoryList.end())
112  {
113  result.clear();
114  (*iter)->getTypeNameList(result);
115 
116  typeList.insert(typeList.end(),
117  result.begin(),
118  result.end());
119  ++iter;
120  }
121 }
122 
124 {
125  vector<ossimObjectFactory*>::const_iterator iter = theFactoryList.begin();
126 
127  while(iter != theFactoryList.end())
128  {
129  if( (*iter) == factory)
130  {
131  return factory;
132  }
133  ++iter;
134  }
135 
136  return NULL;
137 }
138 #endif
139 
140 void ossimObjectFactoryRegistry::getTypeNameList(std::vector<ossimString>& typeList,
141  const ossimString& baseType)const
142 {
143  vector<ossimString> allTypeList;
144 
145  getTypeNameList(allTypeList);
146 
147  if(baseType == "")
148  {
149  typeList.insert(typeList.end(),
150  allTypeList.begin(),
151  allTypeList.end());
152  }
153  else
154  {
155  int i = 0;
157  for(i = 0; i < (int)allTypeList.size(); ++i)
158  {
159  obj = createObject(allTypeList[i]);
160  if(obj.valid())
161  {
162  if(obj->canCastTo(baseType))
163  {
164  typeList.push_back(allTypeList[i]);
165  }
166  }
167  }
168  }
169 }
170 
171 
173 {
175 }
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
static ossimBaseObjectFactory * instance()
static ossimObjectFactoryRegistry * instance()
RTTI_DEF1(ossimObjectFactoryRegistry, "ossimObjectFactoryRegistry", ossimObject)
void addFactory(ossimObjectFactory *factory)
This is for backward compatability and calls registerFactory for simple adds.
void unregisterFactory(ossimObjectFactory *factory)
Will remove the factory from the registry.
ossimObject * createObject(const ossimString &objectType)
Definition: kwl.cpp:64
void registerFactory(ossimObjectFactory *factory, bool pushToFrontFlag=false)
Will register a factory to the factory list.
virtual void getTypeNameList(std::vector< ossimString > &typeList) const
virtual ossimObject * createObject(const ossimString &name) const
virtual bool canCastTo(ossimObject *obj) const
Definition: ossimObject.cpp:74
bool findFactory(ossimObjectFactory *factory) const
Utility to find a factory in the list.
void * ossimObjectFactoryRegistryGetInstance()