torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StatusContainer.hpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef TORC_GENERIC_STATUSCONTAINER_HPP
17 #define TORC_GENERIC_STATUSCONTAINER_HPP
18 
19 #include <iostream>
20 #include <vector>
21 
23 #include "torc/generic/Error.hpp"
24 
25 namespace torc { namespace generic { class Status; } }
26 
27 namespace torc {
28 namespace generic {
29 
30 /**
31  * @brief Represents objects that have status
32  *
33  * The StatusContainer interface is generalized by classes that need to hold status.
34  */
36 public:
37  /**
38  * Get a vector of pointer to Status object
39  *
40  * @param[out] outStatus The vector of pointer to Status object
41  */
42  inline void getStatuses(std::vector<StatusSharedPtr>& outStatus) const;
43 
44  /**
45  * Set a vector of pointer to Status object
46  *
47  * @param[in] inStatus The vector of pointer to Status object
48  */
49  void setStatuses(const std::vector<StatusSharedPtr>& inStatus);
50 
51  /**
52  * Add a status to the vector of statuses. If an empty pointer is supplied,
53  * it returns without doing anything.
54  *
55  * @param[in] inStatus A pointer to a status object.
56  *
57  * @exception Error Status could not be added.
58  */
59  void addStatus(const StatusSharedPtr& inStatus) throw (Error);
60 
61  /**
62  * Apply action on all statuses.
63  * @param[in] action Action to be applied
64  *
65  */
66  template <typename _Action> inline void applyOnAllStatuses(const _Action& action) throw (Error);
67 
68  ~StatusContainer() throw ();
69 
70 protected:
72 
73 private:
74  StatusContainer(const StatusContainer& source);
75 
77 
78  std::vector<StatusSharedPtr> mStatuses;
79 
80 };
81 /**
82  * Get a vector of pointer to Status object
83  *
84  * @param[out] outStatus The vector of pointer to Status object
85  */
86 inline void StatusContainer::getStatuses(std::vector<StatusSharedPtr>& outStatus) const {
87  outStatus.insert(outStatus.end(), mStatuses.begin(), mStatuses.end());
88 }
89 
90 /**
91  * Apply action on all statuses.
92  * @param[in] action Action to be applied
93  *
94  */
95 template <typename _Action> inline void StatusContainer::applyOnAllStatuses(const _Action& action)
96  throw (Error) {
97  try {
98  std::vector<StatusSharedPtr>::iterator it = mStatuses.begin();
99  for(; it != mStatuses.end(); ++it) {
100  action(*it);
101  }
102  } catch(Error& e) {
103  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
104  throw;
105  }
106 }
107 
108 } // namespace generic
109 } // namespace torc
110 
111 #endif // TORC_GENERIC_STATUSCONTAINER_HPP
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
void setStatuses(const std::vector< StatusSharedPtr > &inStatus)
void addStatus(const StatusSharedPtr &inStatus)
StatusContainer & operator=(const StatusContainer &source)
std::vector< StatusSharedPtr > mStatuses
Represents objects that have status.
boost::shared_ptr< Status > StatusSharedPtr
void getStatuses(std::vector< StatusSharedPtr > &outStatus) const
void applyOnAllStatuses(const _Action &action)
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
Definition: Error.cpp:73