torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BundleFlattener.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_BUNDLEFLATTENER_HPP
17 #define TORC_GENERIC_BUNDLEFLATTENER_HPP
18 
20 #include "torc/generic/Bundle.hpp"
25 
26 namespace torc {
27 namespace generic {
28 
29 /**
30  * @brief Flatten a bundle to bits
31  *
32  * The BundleFlattener class is used to flatten a bundle,
33  */
34 template <typename _BaseType, typename _Scalar, typename _Vector, typename _VectorBit,
35  typename _Bundle> class BundleFlattener : public _Scalar::Visitor, public _Vector::Visitor,
36  public _VectorBit::Visitor, public _Bundle::Visitor {
37 public:
38 
39  typedef typename _BaseType::List List;
40 
41  void visit(_Scalar& scalar) throw (Error);
42 
43  void visit(_Vector& vector) throw (Error);
44 
45  void visit(_VectorBit& vectorBit) throw (Error);
46 
47  void visit(_Bundle& bundle) throw (Error);
48 
49  inline void getChildren(typename Bundle<_BaseType>::List& outChildren) const throw (Error);
50 
52 
53  ~BundleFlattener() throw ();
54 
55 private:
56  typename Bundle<_BaseType>::List mChildren;
57 };
58 
59 /**
60  * Get children of this composition.
61  *
62  * @param[out] outChildren A list of all children for this composition
63  */
64 template <typename _BaseType, typename _Scalar, typename _Vector, typename _VectorBit,
65  typename _Bundle> void BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit,
66  _Bundle>::getChildren(typename Bundle<_BaseType>::List& outChildren) const throw (Error) {
67  outChildren.insert(outChildren.end(), mChildren.begin(), mChildren.end());
68  return;
69 }
70 
71 template <typename _BaseType, typename _Scalar, typename _Vector, typename _VectorBit,
72  typename _Bundle> void BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit,
73  _Bundle>::visit(_Scalar& scalar) throw (Error) {
74  mChildren.push_back(scalar.getSharedThis());
75 }
76 
77 template <typename _BaseType, typename _Scalar, typename _Vector, typename _VectorBit,
78  typename _Bundle> void BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit,
79  _Bundle>::visit(_Vector& vector) throw (Error) {
80  try {
81  typename _Vector::List children;
82  vector.getChildren(children);
85  flattener);
86  for_each(children.begin(), children.end(), applier);
87  } catch(Error& e) {
88  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
89  throw;
90  }
91 }
92 
93 template <typename _BaseType, typename _Scalar, typename _Vector, typename _VectorBit,
94  typename _Bundle> void BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit,
95  _Bundle>::visit(_VectorBit& vectorBit) throw (Error) {
96  mChildren.push_back(vectorBit.getSharedThis());
97 
98 }
99 
100 template <typename _BaseType, typename _Scalar, typename _Vector, typename _VectorBit,
101  typename _Bundle> void BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit,
102  _Bundle>::visit(_Bundle& bundle) throw (Error) {
103  try {
106  applier(flattener);
107  bundle.applyOnAllChildren(applier);
108 
109  } catch(Error& e) {
110  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
111  throw;
112  }
113 }
114 
115 template <typename _BaseType, typename _Scalar, typename _Vector, typename _VectorBit,
116  typename _Bundle> BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit,
117  _Bundle>::BundleFlattener() :
118  mChildren() {}
119 
120 template <typename _BaseType, typename _Scalar, typename _Vector, typename _VectorBit,
121  typename _Bundle> BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit,
122  _Bundle>::~BundleFlattener() throw () {}
123 
124 } // namespace generic
125 } // namespace torc
126 
127 #endif // TORC_GENERIC_BUNDLEFLATTENER_HPP
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
void getChildren(typename Bundle< _BaseType >::List &outChildren) const
Bundle< _BaseType >::List mChildren
Represents a "bundle" in the EDIF sense.
Definition: Bundle.hpp:43
Flatten a bundle to bits.
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
Definition: Error.cpp:73