OpenASIP 2.2
Loading...
Searching...
No Matches
OperationPropertyLoader.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file OperationPropertyLoader.cc
26 *
27 * Definition of OperationPropertyLoader class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @note rating: yellow
31 * @note reviewed 7 September 2004 by pj, jn, jm, ao
32 */
33
34#include <string>
35#include <vector>
36
38#include "SequenceTools.hh"
39#include "OperationModule.hh"
40#include "Operation.hh"
41#include "TCEString.hh"
42#include "ObjectState.hh"
43
44using std::string;
45using std::vector;
46
47/**
48 * Constructor.
49 */
52
53/**
54 * Destructor.
55 */
57 MapIter it = operations_.begin();
58 while (it != operations_.end()) {
60 it++;
61 }
62}
63
64/**
65 * Loads the properties of an operation.
66 *
67 * If operation properties has not yet been loaded, it is done first.
68 *
69 * @param operation Operation which properties are loaded and updated.
70 * @param module Module where properties are loaded from.
71 * @exception InstanceNotFound If reading of XML fails, if Operation fails to
72 * load its state, or if properties are not found
73 * at all.
74 */
75void
77 Operation& operation, const OperationModule& module) {
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}
110
111/**
112 * Loads the module.
113 *
114 * Saves its operations as an ObjectState objects.
115 *
116 * @param module The OperationModule.
117 * @exception InstanceNotFound If loading the module fails.
118 */
119void
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}
#define __func__
std::string errorMessage() const
Definition Exception.cc:123
ObjectState * child(int index) const
int childCount() const
virtual std::string propertiesModule() const
ObjectStateCache::iterator MapIter
Iterator for map containing already read ObjectState trees.
ObjectStateCache operations_
Cache for already read ObjectState trees.
void loadModule(const OperationModule &module)
void loadOperationProperties(Operation &operation, const OperationModule &module)
ObjectStateCache::value_type ValueType
value_type for map containing already read ObjectState trees.
OperationSerializer serializer_
Serializer instance.
void setSourceFile(const std::string &filename)
virtual ObjectState * readState()
virtual TCEString name() const
Definition Operation.cc:93
static const char * OPRN_NAME
Object state name for name.
Definition Operation.hh:67
virtual void loadState(const ObjectState *state)
Definition Operation.cc:480
static void deleteAllItems(SequenceType &aSequence)