OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
OperationIndex Class Reference

#include <OperationIndex.hh>

Collaboration diagram for OperationIndex:
Collaboration graph

Public Member Functions

 OperationIndex ()
 
virtual ~OperationIndex ()
 
void addPath (const std::string &path)
 
std::string path (int i) const
 
int pathCount () const
 
OperationModulemodule (int i)
 
int moduleCount () const
 
OperationModulemodule (int i, const std::string &path)
 
int moduleCount (const std::string &path) const
 
void addModule (OperationModule *module, const std::string &path)
 
void removeModule (const std::string &path, const std::string &modName)
 
void refreshModule (const std::string &path, const std::string &modName)
 
OperationModulemoduleOf (const std::string &name)
 
std::string operationName (int i, const OperationModule &om)
 
int operationCount (const OperationModule &om)
 
OperationeffectiveOperation (const TCEString &name)
 

Static Public Attributes

static const std::string PROPERTY_FILE_EXTENSION = ".opp"
 

Private Types

typedef std::map< std::string, std::vector< OperationModule * > > ModuleTable
 Contains all operation modules indexed by full path names.
 
typedef std::map< std::string, ObjectState * > DefinitionTable
 Contains all object state trees of modules indexed by operation definition module names.
 

Private Member Functions

 OperationIndex (const OperationIndex &)
 Copying not allowed.
 
OperationIndexoperator= (const OperationIndex &)
 Assignment not allowed.
 
void readOperations (const OperationModule &module)
 
OperationModulemoduleOf (const std::string &path, const std::string &operName)
 

Private Attributes

std::vector< std::string > paths_
 List of paths searched for the operation modules.
 
ModuleTable modulesInPath_
 Contains all operation modules found in a search path organized by path names.
 
DefinitionTable opDefinitions_
 Contains all operation definitions defined in available operation modules indexed by module names.
 
std::vector< OperationModule * > modules_
 Container holding all modules.
 
OperationSerializer serializer_
 Reads the operation property definitions.
 
OperationBehaviorLoader loader_
 
std::vector< OperationBehaviorProxy * > proxies_
 
std::set< const OperationModule * > brokenModules_
 

Detailed Description

Class that holds information about search paths, modules and operations.

An indexed table of all operations available organized by modules and indexed by names.

Definition at line 58 of file OperationIndex.hh.

Member Typedef Documentation

◆ DefinitionTable

typedef std::map<std::string, ObjectState*> OperationIndex::DefinitionTable
private

Contains all object state trees of modules indexed by operation definition module names.

Definition at line 90 of file OperationIndex.hh.

◆ ModuleTable

typedef std::map<std::string, std::vector<OperationModule*> > OperationIndex::ModuleTable
private

Contains all operation modules indexed by full path names.

Definition at line 87 of file OperationIndex.hh.

Constructor & Destructor Documentation

◆ OperationIndex() [1/2]

OperationIndex::OperationIndex ( )

Constructor.

Definition at line 58 of file OperationIndex.cc.

58 : loader_(*this) {
59}
OperationBehaviorLoader loader_

◆ ~OperationIndex()

OperationIndex::~OperationIndex ( )
virtual

Destructor.

Deletes all object state trees modeling module properties. Deletes all modules.

Definition at line 67 of file OperationIndex.cc.

67 {
71}
static void deleteAllValues(ContainerType &aMap)
DefinitionTable opDefinitions_
Contains all operation definitions defined in available operation modules indexed by module names.
std::vector< OperationBehaviorProxy * > proxies_
std::vector< OperationModule * > modules_
Container holding all modules.
static void deleteAllItems(SequenceType &aSequence)

References SequenceTools::deleteAllItems(), AssocTools::deleteAllValues(), modules_, opDefinitions_, and proxies_.

Here is the call graph for this function:

◆ OperationIndex() [2/2]

OperationIndex::OperationIndex ( const OperationIndex )
private

Copying not allowed.

Member Function Documentation

◆ addModule()

void OperationIndex::addModule ( OperationModule module,
const std::string &  path 
)

Adds a new module to OperationIndex.

Parameters
moduleModule to be added.
pathPath in which module is located.
Exceptions
PathNotFoundIf path is not found.

Definition at line 193 of file OperationIndex.cc.

193 {
194 ModuleTable::iterator it = modulesInPath_.find(path);
195 if (it == modulesInPath_.end()) {
196 string method = "OperationIndex::addModule()";
197 string msg = "Path not found.";
198 throw PathNotFound(__FILE__, __LINE__, method, msg, path);
199 }
200 modules_.push_back(module);
201 (*it).second.push_back(module);
202}
ModuleTable modulesInPath_
Contains all operation modules found in a search path organized by path names.
OperationModule & module(int i)
std::string path(int i) const

References module(), modules_, modulesInPath_, and path().

Referenced by OSEdAddModuleCmd::Do().

Here is the call graph for this function:

◆ addPath()

void OperationIndex::addPath ( const std::string &  path)

Adds a path to search path list.

When the path is added, all modules in that path are automatically scanned and recorded.

Parameters
pathThe path to be added.

Definition at line 82 of file OperationIndex.cc.

82 {
83
84 ModuleTable::iterator iter = modulesInPath_.find(path);
85 if (iter != modulesInPath_.end()) {
86 return;
87 }
88
89 paths_.push_back(path);
90 vector<string> modules;
91 string pattern = path + FileSystem::DIRECTORY_SEPARATOR +
93
94 FileSystem::globPath(pattern, modules);
95
96 vector<OperationModule*> opModules;
97 for (unsigned int i = 0; i < modules.size(); i++) {
98 string file = FileSystem::fileOfPath(modules[i]);
99 string behaviourFile = modules[i];
100 string behaviourSourceFile =
101 behaviourFile.substr(0, behaviourFile.length() - 3) + "cc";
102
103 // behaviour is .opb , change last letter from p to b
104 *(behaviourFile.rbegin()) = 'b';
105
106 // load only modules which have behaviour file.
107 if (!FileSystem::fileExists(behaviourFile) &&
108 FileSystem::fileExists(behaviourSourceFile)) {
110 std::vector<std::string> output;
111 bool buildOk = opBuilder.buildObject(
112 file.substr(0, file.length()-4), behaviourSourceFile,
113 path, output);
114 if (!buildOk || !FileSystem::fileExists(behaviourFile)) {
115 std::cerr << "Warning: Found operation module specification "
116 << "file " << modules[i] << " and operation "
117 << "behavious source file " << behaviourSourceFile
118 << " without compiled behaviour "
119 << "implementation file "
120 << behaviourFile << "." << std::endl;
121 std::cerr << "Tried to compile behaviour impelementaton "
122 << "file, but the compilation failed to error: "
123 << std::endl;
124 for (unsigned int j = 0; j < output.size(); j++) {
125 std::cerr << output[j] << std::endl;
126 }
127 std::cerr << "This may cause program to hang if operation "
128 << "in this module is attempted to be simulated."
129 << std::endl;
130 }
131 }
132 OperationModule* module =
133 new OperationModule(FileSystem::fileNameBody(file), path);
134 modules_.push_back(module);
135 opModules.push_back(module);
136 }
137 modulesInPath_[path] = opModules;
138}
static void globPath(const std::string &pattern, std::vector< std::string > &filenames)
static const std::string DIRECTORY_SEPARATOR
static std::string fileOfPath(const std::string pathName)
static const std::string STRING_WILD_CARD
static bool fileExists(const std::string fileName)
static OperationBuilder & instance()
bool buildObject(const std::string &baseName, const std::string &behaviorFile, const std::string &path, std::vector< std::string > &output)
static const std::string PROPERTY_FILE_EXTENSION
std::vector< std::string > paths_
List of paths searched for the operation modules.

References OperationBuilder::buildObject(), FileSystem::DIRECTORY_SEPARATOR, FileSystem::fileExists(), FileSystem::fileOfPath(), FileSystem::globPath(), OperationBuilder::instance(), module(), modules_, modulesInPath_, path(), paths_, PROPERTY_FILE_EXTENSION, and FileSystem::STRING_WILD_CARD.

Referenced by OSEdAddModuleCmd::Do(), OperationContainer::operation(), OperationContainer::operationIndex(), and OperationPoolPimpl::OperationPoolPimpl().

Here is the call graph for this function:

◆ effectiveOperation()

Operation * OperationIndex::effectiveOperation ( const TCEString name)

Returns a new instance of the Operation with the given name that is 'effective' based on the search path priorities.

Definition at line 454 of file OperationIndex.cc.

454 {
455
456 OperationModule& mod = moduleOf(name);
457
458 DefinitionTable::const_iterator dt =
460
461 assert (dt != opDefinitions_.end());
462
463 ObjectState* root = (*dt).second;
464 ObjectState* child = NULL;
465
466 // load operations
467 for (int i = 0; i < root->childCount(); i++) {
468 child = root->child(i);
469 const TCEString operName =
471
472 /* Do not load all operations in the module because the user
473 might have overridden some of the operation (properties)
474 in a local search path with higher order. Just load the one
475 requested. */
476 if (!operName.ciEqual(name))
477 continue;
478
479 Operation* oper =
481
482 oper->loadState(child);
483 // add the behavior loader proxy
484 OperationBehaviorProxy* proxy =
486 proxies_.push_back(proxy);
487 oper->setBehavior(*proxy);
488 return oper;
489 }
490 return NULL;
491}
#define assert(condition)
static NullOperationBehavior & instance()
ObjectState * child(int index) const
std::string stringAttribute(const std::string &name) const
int childCount() const
OperationModule & moduleOf(const std::string &name)
virtual std::string propertiesModule() const
virtual void setBehavior(OperationBehavior &behavior)
Definition Operation.cc:378
static const char * OPRN_NAME
Object state name for name.
Definition Operation.hh:67
virtual void loadState(const ObjectState *state)
Definition Operation.cc:480
bool ciEqual(const TCEString &other) const
Definition TCEString.cc:63

References assert, ObjectState::child(), ObjectState::childCount(), TCEString::ciEqual(), NullOperationBehavior::instance(), loader_, Operation::loadState(), moduleOf(), opDefinitions_, Operation::OPRN_NAME, OperationModule::propertiesModule(), proxies_, Operation::setBehavior(), and ObjectState::stringAttribute().

Referenced by OperationPoolPimpl::operation(), and FUGen::parseOperations().

Here is the call graph for this function:

◆ module() [1/2]

OperationModule & OperationIndex::module ( int  i)

◆ module() [2/2]

OperationModule & OperationIndex::module ( int  i,
const std::string &  path 
)

Returns the module by the given index in a given path.

Parameters
iThe index of wanted module.
pathThe path of the module
Returns
The module by the given index in a given path, or null module if path is not found.
Exceptions
OutOfRangeIf index i is out of range.
PathNotFoundIf path is not found.

Definition at line 151 of file OperationIndex.cc.

151 {
152 ModuleTable::iterator it = modulesInPath_.find(path);
153 if (it == modulesInPath_.end()) {
154 string msg = "Path for the module not found.";
155 throw PathNotFound(__FILE__, __LINE__, __func__, msg, path);
156 }
157
158 if (i < 0 || i > static_cast<int>((*it).second.size()) - 1) {
159 string msg = "Index out of range.";
160 throw OutOfRange(__FILE__, __LINE__, __func__, msg);
161 }
162
163 OperationModule* module = ((*it).second)[i];
164 return *module;
165}
#define __func__

References __func__, modulesInPath_, and path().

Here is the call graph for this function:

◆ moduleCount() [1/2]

int OperationIndex::moduleCount ( ) const

◆ moduleCount() [2/2]

int OperationIndex::moduleCount ( const std::string &  path) const

Returns the number of modules in a path.

Parameters
pathThe path of the modules.
Returns
The number of modules in a path.
Exceptions
PathNotFoundIf path is not found.

Definition at line 175 of file OperationIndex.cc.

175 {
176 ModuleTable::const_iterator it =
177 modulesInPath_.find(path);
178 if (it == modulesInPath_.end()) {
179 string msg = "Path for the modules not found.";
180 throw PathNotFound(__FILE__, __LINE__, __func__, msg, path);
181 }
182 return (*it).second.size();
183}

References __func__, modulesInPath_, and path().

Here is the call graph for this function:

◆ moduleOf() [1/2]

OperationModule & OperationIndex::moduleOf ( const std::string &  name)

Returns the module in which a given operation is defined.

If operation module is not found, a null operation module is returned.

Parameters
nameThe name of the operation.
Returns
The OperationModule in which operation is defined.

Definition at line 315 of file OperationIndex.cc.

315 {
316
317 // let's iterate through every module to search an operation
318 for (unsigned int i = 0; i < paths_.size(); i++) {
319 OperationModule& module = moduleOf(paths_[i], name);
321 return module;
322 }
323 }
325}
static NullOperationModule & instance()

References NullOperationModule::instance(), module(), and paths_.

Referenced by effectiveOperation().

Here is the call graph for this function:

◆ moduleOf() [2/2]

OperationModule & OperationIndex::moduleOf ( const std::string &  path,
const std::string &  operName 
)
private

Searches for a module in which a given operation is defined all in a given path.

If no module is found, NullOperationModule is returned.

Parameters
pathThe name of the path.
operNameThe name of the operation.
Returns
The module in which operation is defined or NullOperationModule.

Definition at line 403 of file OperationIndex.cc.

405 {
406
407 ModuleTable::const_iterator mt = modulesInPath_.find(path);
408 if (mt == modulesInPath_.end()) {
410 }
411
412 vector<OperationModule*> mods = (*mt).second;
413
414 // let's iterate through all modules in this path
415 for (unsigned int j = 0; j < mods.size(); j++) {
416
417 if (brokenModules_.count(mods[j]))
418 continue;
419 DefinitionTable::const_iterator dt =
420 opDefinitions_.find(mods[j]->propertiesModule());
421 if (dt == opDefinitions_.end()) {
422
423 // operations for this module are not yet read from XML file
424 // let's read them now
425 try {
426 readOperations(*mods[j]);
427 dt = opDefinitions_.find(mods[j]->propertiesModule());
428 } catch (const SerializerException& s) {
429 brokenModules_.insert(mods[j]);
430 // error occurred in reading, let's keep searching
431 continue;
432 }
433 }
434
435 // let's go through all operations and try to find a specific
436 // one
437 ObjectState* op = (*dt).second;
438 for (int i = 0; i < op->childCount(); i++) {
439 ObjectState* child = op->child(i);
441 if (childName.ciEqual(operName)) {
442 return *(mods[j]);
443 }
444 }
445 }
447}
void readOperations(const OperationModule &module)
std::set< const OperationModule * > brokenModules_

References brokenModules_, ObjectState::child(), ObjectState::childCount(), TCEString::ciEqual(), NullOperationModule::instance(), modulesInPath_, opDefinitions_, Operation::OPRN_NAME, path(), readOperations(), and ObjectState::stringAttribute().

Here is the call graph for this function:

◆ operationCount()

int OperationIndex::operationCount ( const OperationModule om)

Returns the number of operations in a particular module.

Parameters
omThe OperationModule.
Returns
The number of operations in a module.
Exceptions
BadOperationModuleWhen module is invalid.

Definition at line 363 of file OperationIndex.cc.

363 {
364 DefinitionTable::iterator it = opDefinitions_.find(om.propertiesModule());
365 if (it == opDefinitions_.end()) {
366 try {
367 readOperations(om);
368 it = opDefinitions_.find(om.propertiesModule());
369 } catch (const SerializerException& s) {
370 brokenModules_.insert(&om);
371 string msg = "Error when reading module: " + s.errorMessage();
372 throw BadOperationModule(__FILE__, __LINE__, __func__, msg);
373 }
374 }
375 ObjectState* op = (*it).second;
376 return op->childCount();
377}
std::string errorMessage() const
Definition Exception.cc:123

References __func__, brokenModules_, ObjectState::childCount(), Exception::errorMessage(), opDefinitions_, OperationModule::propertiesModule(), and readOperations().

Referenced by OSEdTreeView::constructTree(), VectorLSGenerator::createVectorLSU(), OSEdAddOperationCmd::Do(), ProGeTools::generateableDAGOperations(), Automagic::generateableDAGOperations(), OperationContainer::isEffective(), OperationContainer::operationExists(), OSEdInfoView::operationView(), OpsetDialog::TransferDataToWindow(), OperationPropertyDialog::updateAffected(), and writeCustomOpMacros().

Here is the call graph for this function:

◆ operationName()

string OperationIndex::operationName ( int  i,
const OperationModule om 
)

Returns the name of the operation by the given index in a given module.

Parameters
iThe index of the operation.
omThe OperationModule.
Returns
The name of the operation by the given index in a given module.
Exceptions
OutOfRangeIf index i is out of range.
BadOperationModuleWhen module is invalid.

Definition at line 337 of file OperationIndex.cc.

337 {
338 DefinitionTable::iterator it = opDefinitions_.find(om.propertiesModule());
339 if (it == opDefinitions_.end()) {
340 try {
341 readOperations(om);
342 it = opDefinitions_.find(om.propertiesModule());
343 } catch (const SerializerException& s) {
344 brokenModules_.insert(&om);
345 string msg = "Error when reading module: " + s.errorMessage();
346 throw BadOperationModule(__FILE__, __LINE__, __func__, msg);
347 }
348 }
349
350 ObjectState* op = (*it).second;
351 ObjectState* child = op->child(i);
353}

References __func__, brokenModules_, ObjectState::child(), Exception::errorMessage(), opDefinitions_, Operation::OPRN_NAME, OperationModule::propertiesModule(), readOperations(), and ObjectState::stringAttribute().

Referenced by OSEdTreeView::constructTree(), VectorLSGenerator::createVectorLSU(), OSEdAddOperationCmd::Do(), ProGeTools::generateableDAGOperations(), Automagic::generateableDAGOperations(), OperationContainer::isEffective(), OperationContainer::operationExists(), OSEdInfoView::operationView(), OpsetDialog::TransferDataToWindow(), OperationPropertyDialog::updateAffected(), and writeCustomOpMacros().

Here is the call graph for this function:

◆ operator=()

OperationIndex & OperationIndex::operator= ( const OperationIndex )
private

Assignment not allowed.

◆ path()

std::string OperationIndex::path ( int  i) const

◆ pathCount()

int OperationIndex::pathCount ( ) const

◆ readOperations()

void OperationIndex::readOperations ( const OperationModule module)
private

Read all operation definitions of a module.

Parameters
moduleThe operation module to be read operations from.
Exceptions
SerializerExceptionIf reading fails.

Definition at line 386 of file OperationIndex.cc.

386 {
389 opDefinitions_[module.propertiesModule()] = tree;
390}
OperationSerializer serializer_
Reads the operation property definitions.
void setSourceFile(const std::string &filename)
virtual ObjectState * readState()

References module(), opDefinitions_, OperationModule::propertiesModule(), OperationSerializer::readState(), serializer_, and OperationSerializer::setSourceFile().

Referenced by moduleOf(), operationCount(), and operationName().

Here is the call graph for this function:

◆ refreshModule()

void OperationIndex::refreshModule ( const std::string &  path,
const std::string &  modName 
)

Refreshes module (usually when new operation is added to it).

Refreshing is done by erasing the ObjectState tree of the module. That way it has to be read again.

Parameters
pathThe name of the path.
modNameThe name of the module.
Exceptions
PathNotFoundIf path is not found.

Definition at line 272 of file OperationIndex.cc.

273 {
274 ModuleTable::iterator modIter = modulesInPath_.find(path);
275 if (modIter == modulesInPath_.end()) {
276 string msg = "Path for the module not found.";
277 throw PathNotFound(__FILE__, __LINE__, __func__, msg, path);
278 }
279
280 vector<OperationModule*>::iterator iter = (*modIter).second.begin();
281 OperationModule* module = NULL;
282 while (iter != (*modIter).second.end()) {
283 if ((*iter)->name() == modName) {
284 module = (*iter);
285 break;
286 }
287 iter++;
288 }
289
290 if (module == NULL) {
291 throw InstanceNotFound(
292 __FILE__, __LINE__, __func__,
293 "Operation module " + path + ":" + modName + " not found.");
294 }
295
296 DefinitionTable::iterator it =
298 if (it == opDefinitions_.end()) {
299 return;
300 } else {
301 delete (*it).second;
302 opDefinitions_.erase(it);
303 }
304}

References __func__, module(), modulesInPath_, opDefinitions_, path(), and OperationModule::propertiesModule().

Referenced by OSEdAddOperationCmd::Do(), OSEdPropertiesCmd::Do(), and OSEdRemoveOperationCmd::Do().

Here is the call graph for this function:

◆ removeModule()

void OperationIndex::removeModule ( const std::string &  path,
const std::string &  modName 
)

Removes the module in a given path.

Parameters
pathThe name of the path.
modNameThe name of the module.
Exceptions
PathNotFoundIf path is not found.

Definition at line 212 of file OperationIndex.cc.

213 {
214 ModuleTable::iterator iter = modulesInPath_.find(path);
215 if (iter == modulesInPath_.end()) {
216 string msg = "Paths of the module not found.";
217 throw PathNotFound(__FILE__, __LINE__, __func__, msg, path);
218 }
219
220 OperationModule* toBeErased = NULL;
221
222 vector<OperationModule*>::iterator modIter = (*iter).second.begin();
223 while (modIter != (*iter).second.end()) {
224 if ((*modIter)->name() == modName) {
225 toBeErased = *modIter;
226 (*iter).second.erase(modIter);
227 break;
228 }
229 modIter++;
230 }
231
232 if (toBeErased == NULL) {
233 throw InstanceNotFound(
234 __FILE__, __LINE__, __func__,
235 "Operation module " + path + ":" + modName + " not found.");
236 }
237
238 modIter = modules_.begin();
239 while (modIter != modules_.end()) {
240 if (*modIter == toBeErased) {
241 modules_.erase(modIter);
242 break;
243 }
244 modIter++;
245 }
246
247 // erase module from DefinitionTable
248 DefinitionTable::iterator dIter = opDefinitions_.begin();
249 while (dIter != opDefinitions_.end()) {
250 if ((*dIter).first == toBeErased->propertiesModule()) {
251 opDefinitions_.erase(dIter);
252 delete (*dIter).second;
253 break;
254 }
255 dIter++;
256 }
257
258 delete toBeErased;
259}

References __func__, modules_, modulesInPath_, opDefinitions_, path(), and OperationModule::propertiesModule().

Referenced by OSEdRemoveModuleCmd::Do().

Here is the call graph for this function:

Member Data Documentation

◆ brokenModules_

std::set<const OperationModule*> OperationIndex::brokenModules_
private

Definition at line 117 of file OperationIndex.hh.

Referenced by moduleOf(), operationCount(), and operationName().

◆ loader_

OperationBehaviorLoader OperationIndex::loader_
private

Definition at line 115 of file OperationIndex.hh.

Referenced by effectiveOperation().

◆ modules_

std::vector<OperationModule*> OperationIndex::modules_
private

Container holding all modules.

Definition at line 112 of file OperationIndex.hh.

Referenced by addModule(), addPath(), removeModule(), and ~OperationIndex().

◆ modulesInPath_

ModuleTable OperationIndex::modulesInPath_
private

Contains all operation modules found in a search path organized by path names.

Definition at line 107 of file OperationIndex.hh.

Referenced by addModule(), addPath(), module(), moduleCount(), moduleOf(), refreshModule(), and removeModule().

◆ opDefinitions_

DefinitionTable OperationIndex::opDefinitions_
private

Contains all operation definitions defined in available operation modules indexed by module names.

Definition at line 110 of file OperationIndex.hh.

Referenced by effectiveOperation(), moduleOf(), operationCount(), operationName(), readOperations(), refreshModule(), removeModule(), and ~OperationIndex().

◆ paths_

std::vector<std::string> OperationIndex::paths_
private

List of paths searched for the operation modules.

Definition at line 104 of file OperationIndex.hh.

Referenced by addPath(), and moduleOf().

◆ PROPERTY_FILE_EXTENSION

const string OperationIndex::PROPERTY_FILE_EXTENSION = ".opp"
static

Definition at line 61 of file OperationIndex.hh.

Referenced by addPath().

◆ proxies_

std::vector<OperationBehaviorProxy*> OperationIndex::proxies_
private

Definition at line 116 of file OperationIndex.hh.

Referenced by effectiveOperation(), and ~OperationIndex().

◆ serializer_

OperationSerializer OperationIndex::serializer_
private

Reads the operation property definitions.

Definition at line 114 of file OperationIndex.hh.

Referenced by readOperations().


The documentation for this class was generated from the following files: