torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VectorBit.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_VECTORBIT_HPP
17 #define TORC_GENERIC_VECTORBIT_HPP
18 
19 #include <vector>
20 
21 #ifdef GENOM_SERIALIZATION
22 #include <boost/serialization/access.hpp>
23 #include <boost/serialization/base_object.hpp>
24 #include <boost/serialization/vector.hpp>
25 #endif //GENOM_SERIALIZATION
28 #include "torc/generic/Error.hpp"
29 
30 namespace torc {
31 namespace generic {
32 
33 /**
34  * @brief Represents a single element of a vector composition
35  *
36  * A VectorBit is used to represent a bit of a vector. It contains a pointer to the vector and the
37  * particular index where it was stored. For a Vector where the _PRESERVE parameter is true, this
38  * is setup during the blast operation. Otherwise, this is moreor less similar to the Scalar
39  * composition.
40  */
41 template <typename _Type> class VectorBit : public virtual Composite<_Type> {
42 #ifdef GENOM_SERIALIZATION
43  friend class boost::serialization::access;
44 #endif //GENOM_SERIALIZATION
45 public:
46  typedef _Type Type;
48  typedef typename BaseType::List List;
49  typedef typename BaseType::Pointer Pointer;
50  typedef typename BaseType::SizeType SizeType;
51 
52  /**
53  * Get composition type for this object
54  *
55  * @return The CompositionType inSource eCompositionTypeVectorBit is returned
56  */
57  virtual CompositionType getCompositionType() const;
58 
59  /**
60  * Get the total number of bits of the composition
61  * @return Number of bits
62  */
63  virtual SizeType getSize() const;
64 
65  /**
66  * Get children of this composition.
67  * @param[out] outChildren A list of all children for this composition
68  * @note This wil return empty list for scalar
69  */
70  virtual void getChildren(List& outChildren) const throw (Error);
71 
72  /**
73  * Get a specific member of this composition.
74  *
75  * @param[in] inIndices A list of indices to be accessed. The number of indices must be equal
76  * to the number of dimensions.
77  *
78  * @return An empty pointer is returned
79  */
80  virtual const Pointer get(const std::vector<SizeType>& inIndices) const throw (Error);
81 
82  /**
83  * Get the index of this bit in the vector.
84  *
85  * @return A vector containing the indices to which this element belonged.
86  */
87  inline const std::vector<SizeType>& getIndices() const;
88 
89  /**
90  * Set the index of this bit in the vector.
91  *
92  * @param[in] inSource A vector of indices for this element
93  */
94  void setIndices(const std::vector<SizeType>& inSource);
95 
96  //TBD::BLOCK FROM DOC
97  inline SizeType getAbsoluteIndex() const;
98 
99  void setAbsoluteIndex(SizeType inSource);
100 
101 protected:
102  VectorBit();
103 
104 public:
105  virtual ~VectorBit() throw ();
106 
107 private:
108 #ifdef GENOM_SERIALIZATION
109  template <class Archive> void serialize(Archive& ar, unsigned int);
110 #endif //GENOM_SERIALIZATION
111  std::vector<SizeType> mIndices;
113 
114  VectorBit(const VectorBit<_Type>& source);
116 
117 };
118 /**
119  * Get composition type for this object
120  *
121  * @return The CompositionType inSource eCompositionTypeScalar is returned
122  */
123 template <typename _Type> CompositionType VectorBit<_Type>::getCompositionType() const {
125 }
126 
127 /**
128  * Get the total number of bits of the composition
129  * @return Number of bits
130  */
131 template <typename _Type> typename VectorBit<_Type>::SizeType VectorBit<_Type>::getSize() const {
132  return 1;
133 }
134 
135 /**
136  * Get children of this composition.
137  *
138  * @param[out] outChildren A list of all children for this composition
139  */
140 template <typename _Type> void VectorBit<_Type>::getChildren(
141  typename VectorBit<_Type>::List& outChildren) const throw (Error) {
142  return;
143 }
144 
145 /**
146  * Get a specific member of this composition.
147  *
148  * @param[in] indices A list of indices to be accessed. The number of indices must be equal to the number of dimensions.
149  *
150  * @return An empty pointer is returned
151  */
152 template <typename _Type> const typename VectorBit<_Type>::Pointer VectorBit<_Type>::get(
153  const std::vector<typename VectorBit<_Type>::SizeType>& indices) const throw (Error) {
154  return Pointer();
155 }
156 
157 /**
158  * Get the index of this bit in the vector.
159  *
160  * @return A vector containing the indices to which this element belonged.
161  */
162 template <typename _Type> inline const std::vector<typename VectorBit<_Type>::SizeType>&
164  return mIndices;
165 }
166 
167 /**
168  * Set the index of this bit in the vector.
169  *
170  * @param[in] inSource A vector of indices for this element
171  */
172 template <typename _Type> void VectorBit<_Type>::setIndices(const std::vector<SizeType>& inSource) {
173  mIndices = inSource;
174 }
175 
176 template <typename _Type> inline typename VectorBit<_Type>::SizeType
178  return mAbsoluteIndex;
179 }
180 
181 template <typename _Type> void VectorBit<_Type>::setAbsoluteIndex(SizeType inSource) {
182  mAbsoluteIndex = inSource;
183 }
184 
185 template <typename _Type> VectorBit<_Type>::VectorBit() : BaseType(), mIndices() {}
186 
187 template <typename _Type> VectorBit<_Type>::~VectorBit() throw () {}
188 #ifdef GENOM_SERIALIZATION
189 template <typename _Type> template <class Archive> void VectorBit<_Type>::serialize(Archive& ar,
190  unsigned int) {
191  ar & boost::serialization::base_object<Composite<_Type> >(*this);
192  ar & mIndices;
193  ar & mAbsoluteIndex;
194 }
195 #endif //GENOM_SERIALIZATION
196 
197 } // namespace generic
198 } // namespace torc
199 
200 #endif // TORC_GENERIC_VECTORBIT_HPP
virtual void getChildren(List &outChildren) const
Definition: VectorBit.hpp:140
BaseType::List List
Definition: VectorBit.hpp:48
Composite< Type > BaseType
Definition: VectorBit.hpp:47
SizeType getAbsoluteIndex() const
Definition: VectorBit.hpp:177
virtual SizeType getSize() const
Definition: VectorBit.hpp:131
void setIndices(const std::vector< SizeType > &inSource)
Definition: VectorBit.hpp:172
Interface for objects that can be composed within each other.
Definition: Composite.hpp:45
boost::shared_ptr< Type > Pointer
Definition: Composite.hpp:55
CompositionType
Defines possible Composition types.
void setAbsoluteIndex(SizeType inSource)
Definition: VectorBit.hpp:181
BaseType::SizeType SizeType
Definition: VectorBit.hpp:50
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
Contains definition for CompositionType.
std::vector< SizeType > mIndices
Definition: VectorBit.hpp:111
virtual const Pointer get(const std::vector< SizeType > &inIndices) const
Definition: VectorBit.hpp:152
const std::vector< SizeType > & getIndices() const
Definition: VectorBit.hpp:163
VectorBit< _Type > & operator=(const VectorBit< _Type > &source)
Represents a single element of a vector composition.
Definition: VectorBit.hpp:41
virtual CompositionType getCompositionType() const
Definition: VectorBit.hpp:123
BaseType::Pointer Pointer
Definition: VectorBit.hpp:49
std::vector< Pointer > List
Definition: Composite.hpp:61