OpenASIP  2.0
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
OperationPropertyLoader Class Reference

#include <OperationPropertyLoader.hh>

Collaboration diagram for OperationPropertyLoader:
Collaboration graph

Public Member Functions

 OperationPropertyLoader ()
 
virtual ~OperationPropertyLoader ()
 
void loadOperationProperties (Operation &operation, const OperationModule &module)
 

Private Types

typedef std::map< std::string, std::vector< ObjectState * > > ObjectStateCache
 Container containing already read ObjectState trees. More...
 
typedef ObjectStateCache::iterator MapIter
 Iterator for map containing already read ObjectState trees. More...
 
typedef ObjectStateCache::value_type ValueType
 value_type for map containing already read ObjectState trees. More...
 

Private Member Functions

 OperationPropertyLoader (const OperationPropertyLoader &)
 Copying not allowed. More...
 
OperationPropertyLoaderoperator= (const OperationPropertyLoader &)
 Assignment not allowed. More...
 
void loadModule (const OperationModule &module)
 

Private Attributes

OperationSerializer serializer_
 Serializer instance. More...
 
ObjectStateCache operations_
 Cache for already read ObjectState trees. More...
 

Detailed Description

Imports the static information contents of an operation from a data file.

Definition at line 51 of file OperationPropertyLoader.hh.

Member Typedef Documentation

◆ MapIter

typedef ObjectStateCache::iterator OperationPropertyLoader::MapIter
private

Iterator for map containing already read ObjectState trees.

Definition at line 64 of file OperationPropertyLoader.hh.

◆ ObjectStateCache

typedef std::map<std::string, std::vector<ObjectState*> > OperationPropertyLoader::ObjectStateCache
private

Container containing already read ObjectState trees.

Definition at line 61 of file OperationPropertyLoader.hh.

◆ ValueType

typedef ObjectStateCache::value_type OperationPropertyLoader::ValueType
private

value_type for map containing already read ObjectState trees.

Definition at line 66 of file OperationPropertyLoader.hh.

Constructor & Destructor Documentation

◆ OperationPropertyLoader() [1/2]

OperationPropertyLoader::OperationPropertyLoader ( )

Constructor.

Definition at line 50 of file OperationPropertyLoader.cc.

50  {
51 }

◆ ~OperationPropertyLoader()

OperationPropertyLoader::~OperationPropertyLoader ( )
virtual

Destructor.

Definition at line 56 of file OperationPropertyLoader.cc.

56  {
57  MapIter it = operations_.begin();
58  while (it != operations_.end()) {
59  SequenceTools::deleteAllItems((*it).second);
60  it++;
61  }
62 }

References SequenceTools::deleteAllItems(), and operations_.

Here is the call graph for this function:

◆ OperationPropertyLoader() [2/2]

OperationPropertyLoader::OperationPropertyLoader ( const OperationPropertyLoader )
private

Copying not allowed.

Member Function Documentation

◆ loadModule()

void OperationPropertyLoader::loadModule ( const OperationModule module)
private

Loads the module.

Saves its operations as an ObjectState objects.

Parameters
moduleThe OperationModule.
Exceptions
InstanceNotFoundIf loading the module fails.

Definition at line 120 of file OperationPropertyLoader.cc.

120  {
122  ObjectState* root = NULL;
123  try {
124  root = serializer_.readState();
125  } catch (const SerializerException& s) {
126  string msg = "Problems when reading the XML file: " + s.errorMessage();
127  throw InstanceNotFound(__FILE__, __LINE__, __func__, msg);
128  }
129  vector<ObjectState*> ops;
130  for (int i = 0; i < root->childCount(); i++) {
131  ObjectState* child = new ObjectState(*root->child(i));
132  ops.push_back(child);
133  }
134  delete root;
135  operations_.insert(ValueType(module.propertiesModule(), ops));
136 }

References __func__, ObjectState::child(), ObjectState::childCount(), Exception::errorMessage(), operations_, OperationModule::propertiesModule(), OperationSerializer::readState(), serializer_, and OperationSerializer::setSourceFile().

Referenced by loadOperationProperties().

Here is the call graph for this function:

◆ loadOperationProperties()

void OperationPropertyLoader::loadOperationProperties ( Operation operation,
const OperationModule module 
)

Loads the properties of an operation.

If operation properties has not yet been loaded, it is done first.

Parameters
operationOperation which properties are loaded and updated.
moduleModule where properties are loaded from.
Exceptions
InstanceNotFoundIf reading of XML fails, if Operation fails to load its state, or if properties are not found at all.

Definition at line 76 of file OperationPropertyLoader.cc.

77  {
78  MapIter it = operations_.find(module.propertiesModule());
79  if (it == operations_.end()) {
80  // properties are not yet read, let's do it first
81  loadModule(module);
82  it = operations_.find(module.propertiesModule());
83  }
84 
85  const vector<ObjectState*> ops = (*it).second;
86  bool operationFound = false;
87 
88  for (unsigned int i = 0; i < ops.size(); i++) {
89  if (ops[i]->stringAttribute(Operation::OPRN_NAME) ==
90  operation.name()) {
91 
92  operationFound = true;
93  try {
94  operation.loadState(ops[i]);
95  } catch (const ObjectStateLoadingException& o) {
96  string msg = "Problems when loading the state of the Object: "
97  + o.errorMessage();
98  throw InstanceNotFound(__FILE__, __LINE__, __func__, msg);
99  }
100  break;
101  }
102  }
103 
104  if (!operationFound) {
105  string msg = string("Properties for operation ") + operation.name() +
106  " not found";
107  throw InstanceNotFound(__FILE__, __LINE__, __func__, msg);
108  }
109 }

References __func__, Exception::errorMessage(), loadModule(), Operation::loadState(), Operation::name(), operations_, Operation::OPRN_NAME, and OperationModule::propertiesModule().

Here is the call graph for this function:

◆ operator=()

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

Assignment not allowed.

Member Data Documentation

◆ operations_

ObjectStateCache OperationPropertyLoader::operations_
private

Cache for already read ObjectState trees.

Definition at line 78 of file OperationPropertyLoader.hh.

Referenced by loadModule(), loadOperationProperties(), and ~OperationPropertyLoader().

◆ serializer_

OperationSerializer OperationPropertyLoader::serializer_
private

Serializer instance.

Definition at line 76 of file OperationPropertyLoader.hh.

Referenced by loadModule().


The documentation for this class was generated from the following files:
OperationPropertyLoader::loadModule
void loadModule(const OperationModule &module)
Definition: OperationPropertyLoader.cc:120
ObjectStateLoadingException
Definition: Exception.hh:551
Operation::OPRN_NAME
static const char * OPRN_NAME
Object state name for name.
Definition: Operation.hh:67
ObjectState
Definition: ObjectState.hh:59
Operation::name
virtual TCEString name() const
Definition: Operation.cc:93
SequenceTools::deleteAllItems
static void deleteAllItems(SequenceType &aSequence)
OperationModule::propertiesModule
virtual std::string propertiesModule() const
Definition: OperationModule.cc:121
OperationPropertyLoader::serializer_
OperationSerializer serializer_
Serializer instance.
Definition: OperationPropertyLoader.hh:76
OperationSerializer::readState
virtual ObjectState * readState()
Definition: OperationSerializer.cc:118
__func__
#define __func__
Definition: Application.hh:67
Operation::loadState
virtual void loadState(const ObjectState *state)
Definition: Operation.cc:480
ObjectState::child
ObjectState * child(int index) const
Definition: ObjectState.cc:471
ObjectState::childCount
int childCount() const
OperationPropertyLoader::MapIter
ObjectStateCache::iterator MapIter
Iterator for map containing already read ObjectState trees.
Definition: OperationPropertyLoader.hh:64
SerializerException
Definition: Exception.hh:675
OperationSerializer::setSourceFile
void setSourceFile(const std::string &filename)
Definition: OperationSerializer.cc:536
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
OperationPropertyLoader::ValueType
ObjectStateCache::value_type ValueType
value_type for map containing already read ObjectState trees.
Definition: OperationPropertyLoader.hh:66
InstanceNotFound
Definition: Exception.hh:304
OperationPropertyLoader::operations_
ObjectStateCache operations_
Cache for already read ObjectState trees.
Definition: OperationPropertyLoader.hh:78