OpenASIP  2.0
ProDeOptionsSerializer.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 ProDeOptionsSerializer.cc
26  *
27  * Implementation of ProDeOptionsSerializer class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
34 #include "Application.hh"
35 #include "Conversion.hh"
36 #include "ObjectState.hh"
37 #include "ProDeOptions.hh"
38 
39 using std::string;
40 
41 /// Name of the element declaring the size of the undo stack.
42 const string UNDO = "undo-stack";
43 /// Name of the attribute of the undo element.
44 const string UNDO_SIZE = "size";
45 
46 /// Default undo stack size.
47 const int DEFAULT_UNDO_SIZE = 10;
48 
49 
50 /**
51  * Constructor.
52  */
54  GUIOptionsSerializer(ProDeOptions::CONFIGURATION_NAME) {
55 }
56 
57 
58 /**
59  * Destructor.
60  */
62 }
63 
64 
65 /**
66  * Converts the given ObjectState tree created by ProDeOptions::saveState
67  * to the format of configuration file.
68  *
69  * @param options ObjectState tree to be converted.
70  * @return The newly created ObjectState tree which matches with
71  * configuration file format.
72  */
75  const ObjectState* options) const {
76 
77  ObjectState* root =
79 
80  // add undo stack size
81  ObjectState* undoStack = new ObjectState(UNDO);
82  root->addChild(undoStack);
83  undoStack->setAttribute(
84  UNDO_SIZE, options->stringAttribute(
86 
87  return root;
88 }
89 
90 
91 /**
92  * Creates a new ObjectState tree which can be given to ProDeOptions
93  * constructor. The tree is created according to the given tree which matches
94  * with the syntax of the options file.
95  *
96  * @param root Root node of the ObjectState tree to be converted.
97  */
100  const ObjectState* root) const {
101 
104 
105  // set undo stack size
106  if (root->hasChild(UNDO)) {
107  ObjectState* undo = root->childByName(UNDO);
108  options->setAttribute(
110  undo->stringAttribute(UNDO_SIZE));
111  } else {
112  options->setAttribute(
114  }
115 
116  return options;
117 }
ProDeOptions
Definition: ProDeOptions.hh:44
ObjectState::stringAttribute
std::string stringAttribute(const std::string &name) const
Definition: ObjectState.cc:249
ObjectState
Definition: ObjectState.hh:59
ProDeOptionsSerializer::~ProDeOptionsSerializer
virtual ~ProDeOptionsSerializer()
Definition: ProDeOptionsSerializer.cc:61
ProDeOptionsSerializer::convertToConfigFileFormat
ObjectState * convertToConfigFileFormat(const ObjectState *options) const
Definition: ProDeOptionsSerializer.cc:74
ProDeOptionsSerializer.hh
ObjectState::childByName
ObjectState * childByName(const std::string &name) const
Definition: ObjectState.cc:443
GUIOptionsSerializer::convertToConfigFileFormat
virtual ObjectState * convertToConfigFileFormat(const ObjectState *options) const
Definition: GUIOptionsSerializer.cc:194
UNDO
const string UNDO
Name of the element declaring the size of the undo stack.
Definition: ProDeOptionsSerializer.cc:42
Conversion.hh
ProDeOptionsSerializer::convertToOptionsObjectFormat
ObjectState * convertToOptionsObjectFormat(const ObjectState *root) const
Definition: ProDeOptionsSerializer.cc:99
Application.hh
ObjectState.hh
ProDeOptions::OSKEY_UNDO_STACK_SIZE
static const std::string OSKEY_UNDO_STACK_SIZE
ObjectState attribute key for the size of the undo stack.
Definition: ProDeOptions.hh:61
ObjectState::addChild
void addChild(ObjectState *child)
Definition: ObjectState.cc:376
ProDeOptionsSerializer::ProDeOptionsSerializer
ProDeOptionsSerializer()
Definition: ProDeOptionsSerializer.cc:53
ObjectState::hasChild
bool hasChild(const std::string &name) const
Definition: ObjectState.cc:358
options
static MachInfoCmdLineOptions options
Definition: MachInfo.cc:46
ProDeOptions.hh
GUIOptionsSerializer::convertToOptionsObjectFormat
virtual ObjectState * convertToOptionsObjectFormat(const ObjectState *root) const
Definition: GUIOptionsSerializer.cc:343
DEFAULT_UNDO_SIZE
const int DEFAULT_UNDO_SIZE
Default undo stack size.
Definition: ProDeOptionsSerializer.cc:47
UNDO_SIZE
const string UNDO_SIZE
Name of the attribute of the undo element.
Definition: ProDeOptionsSerializer.cc:44
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100
GUIOptionsSerializer
Definition: GUIOptionsSerializer.hh:52