29 #include <arcs/arcscontext.h>
31 #include <arcs/arcslog.h>
44 this->factory = ctx.factory;
46 QHashIterator<QString, ARCSAbstractComponent*> i(ctx.componentPool);
51 componentPool[i.key()] = i.value()->clone();
54 constantPool = ctx.constantPool;
59 ARCSContext::~ARCSContext()
69 QStringList components = componentPool.keys();
70 QStringList constants = constantPool.keys();
74 for (i=0; i < components.count(); i++)
78 if (!result.contains(lib))
82 for (i=0; i < constants.count(); i++)
87 if (!result.contains(lib))
97 return constantPool.keys();
104 return componentPool.keys();
112 QHashIterator<QString, ARCSAbstractComponent*> i(componentPool);
118 if (v.isValid() && i.key() !=
"this" )
120 if (v == QVariant(
true))
136 constantPool.clear();
138 QHashIterator<QString, ARCSAbstractComponent*> i(componentPool);
145 componentPool.clear();
154 ARCSLog::logCritical(ARCS_SOURCE,
"cannot create component "+name+
" of type "+className);
160 if ( componentPool.contains(name))
162 qCritical() <<
"[Context] Component pool already contains a component named" << name;
166 componentPool.insert(name, candidate);
180 qCritical() <<
"[Context] Unable to parse contents:" << contents <<
"for object" << name <<
"of type" << className ;
182 if ( componentPool.contains(name))
184 qCritical() <<
"[Context] Component pool already contains a component named" << name;
188 componentPool.insert(name, candidate);
192 bool ARCSContext::renameComponent(QString oldName, QString newName)
194 if (componentPool.contains(newName))
197 if (! componentPool.contains(oldName))
202 componentPool.insert(newName,componentToRename);
209 if (componentPool.contains(name))
219 if (componentPool.contains(name))
220 return componentPool[name];
227 if (constantPool.contains(name))
229 qCritical() <<
"[Context] Constant pool already contains a constant name" << name;
238 constantPool[name] = var;
245 constantPool.remove(name);
251 if (constantPool.contains(name))
252 return constantPool[name];
257 QVariant ARCSContext::createValue(QString type, QString representation)
bool instanciate()
Instanciates the real component.
void removeConstant(QString name)
Removes a constant from the constant pool.
bool serializeConstant(QString name, QString &type, QString &representation)
Serializes constants.
void destroyComponent(ARCSAbstractComponent *aac)
Destroys a component.
QString getVariantType(QVariant var)
Returns the type of a QVariant.
QStringList getComponentList()
bool modifyConstant(QString name, QString representation)
Modifies a constant of the list.
QString getTypeLibrary(QString s)
Returns the path of the library associated to a certain kind of type.
bool addComponent(QString name, QString className, QString contents=QString::null)
Adds a component to the list.
static ARCSFactory * getInstance()
Returns the instance of the singleton ARCSFactory.
QVariant getProperty(QString name)
Gets a meta-property from this component.
Class handling the generic description of a component.
void removeComponent(QString name)
Removes a component from the component pool.
ARCSAbstractComponent * createComponent(QString componentType)
Creates a component given its class name.
ARCSContext()
Constructor.
ARCSAbstractComponent * getComponent(QString name)
Retrieves a component by its id.
bool addConstant(QString name, QString type, QString representation)
Adds a constant to the list.
QString getComponentLibrary(QString s)
Returns the path of the library associated to a certain kind of component.
QStringList computeLibraryList()
QVariant getConstant(QString name)
Retrieves a constant by its id.
This class manages components and constants in a given context.
QStringList getConstantList()
void reset()
Resets the component and constant lists.
bool instanciatePool()
Instanciates the whole pool of components inside the context.
QString dataSerialize(QVariant var)
Serializes data from their QVariant counterpart.
QVariant dataDeserialize(QString type, QString representation)
Deserialize data from their string representation.
void setProperty(QString name, QVariant value)
Sets a meta-property on this component.
bool isInstanciated()
Determines wether the component is instanciated or not.
virtual bool parseString(QString s)=0
Defines a basic seralization mechanism.