OpenASIP  2.0
ToolbarButton.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 ToolbarButton.cc
26  *
27  * Implementation of ToolbarButton class.
28  *
29  * @author Lasse Laasonen 2003 (lasse.laasonen-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include "ToolbarButton.hh"
34 #include "ObjectState.hh"
35 
36 using std::string;
37 
38 // initialization of static data members
39 const string ToolbarButton::OSNAME_TOOLBAR_BUTTON = "tbbutton";
40 const string ToolbarButton::OSKEY_SLOT = "slot";
41 const string ToolbarButton::OSKEY_ACTION = "action";
42 
43 
44 /**
45  * Constructor.
46  *
47  * @param slot Number of the slot in which the button is placed.
48  * @param action Name of the action performed by the button.
49  */
51  int slot,
52  const std::string& action) :
53  slot_(slot), action_(action) {
54 }
55 
56 
57 /**
58  * Constructor.
59  *
60  * Loads the state from the given ObjectsState object.
61  */
63  loadState(state);
64 }
65 
66 
67 /**
68  * Copy constructor.
69  */
71  Serializable() {
72  slot_ = old.slot_;
73  action_ = old.action_;
74 }
75 
76 
77 /**
78  * Destructor.
79  */
81 }
82 
83 
84 /**
85  * Returns the name of the action performed by the button.
86  *
87  * @return Name of the action performed by the button.
88  */
89 std::string
91  return action_;
92 }
93 
94 
95 /**
96  * Returns the position of the slot which contains the button.
97  *
98  * @return Position of the slot which contains the button.
99  */
100 int
102  return slot_;
103 }
104 
105 
106 /**
107  * Loads the state of the object from the given ObjectState object.
108  *
109  * @param state ObjectState from which the state is loaded.
110  * @exception ObjectStateLoadingException If the given ObjectState instance
111  * is invalid.
112  */
113 void
115  string procName = "ToolbarButton::loadState";
116 
117  if (state->name() != OSNAME_TOOLBAR_BUTTON) {
118  throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
119  }
120 
121  try {
122  slot_ = state->intAttribute(OSKEY_SLOT);
124  } catch (...) {
125  throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
126  }
127 }
128 
129 /**
130  * Creates an ObjectState object and saves the state of the object into it.
131  *
132  * @return The created ObjectState object.
133  */
137  state->setAttribute(OSKEY_SLOT, slot_);
139  return state;
140 }
ToolbarButton::slot_
int slot_
Number of the slot in which this toolbar button is.
Definition: ToolbarButton.hh:70
ToolbarButton.hh
ToolbarButton::OSKEY_ACTION
static const std::string OSKEY_ACTION
ObjectState attribute key for action name.
Definition: ToolbarButton.hh:55
ToolbarButton::action
std::string action() const
Definition: ToolbarButton.cc:90
ObjectState::stringAttribute
std::string stringAttribute(const std::string &name) const
Definition: ObjectState.cc:249
ObjectStateLoadingException
Definition: Exception.hh:551
Serializable
Definition: Serializable.hh:44
ObjectState
Definition: ObjectState.hh:59
ToolbarButton
Definition: ToolbarButton.hh:48
ToolbarButton::loadState
void loadState(const ObjectState *state)
Definition: ToolbarButton.cc:114
ToolbarButton::OSNAME_TOOLBAR_BUTTON
static const std::string OSNAME_TOOLBAR_BUTTON
ObjectState name for ToolbarButton.
Definition: ToolbarButton.hh:51
ObjectState.hh
ToolbarButton::slot
int slot() const
Definition: ToolbarButton.cc:101
ObjectState::name
std::string name() const
ToolbarButton::OSKEY_SLOT
static const std::string OSKEY_SLOT
ObjectState attribute key for slot position.
Definition: ToolbarButton.hh:53
ToolbarButton::action_
std::string action_
Name of the action performed by this toolbar button.
Definition: ToolbarButton.hh:72
ToolbarButton::saveState
ObjectState * saveState() const
Definition: ToolbarButton.cc:135
ToolbarButton::~ToolbarButton
virtual ~ToolbarButton()
Definition: ToolbarButton.cc:80
ObjectState::intAttribute
int intAttribute(const std::string &name) const
Definition: ObjectState.cc:276
ToolbarButton::ToolbarButton
ToolbarButton(int slot, const std::string &action)
Definition: ToolbarButton.cc:50
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100