Orocos Real-Time Toolkit  2.9.0
carray.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:55:18 CEST 2010 carray.hpp
3 
4  carray.hpp - description
5  -------------------
6  begin : Tue September 07 2010
7  copyright : (C) 2010 The SourceWorks
8  email : peter@thesourceworks.com
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 #ifndef ORO_CARRAY_HPP_
40 #define ORO_CARRAY_HPP_
41 
42 #include <boost/version.hpp>
43 #include <boost/serialization/array.hpp>
44 #include <boost/array.hpp>
45 
46 namespace RTT
47 {
48  namespace types {
49 
69  template<class T>
70  class carray
71  {
72  public:
73  typedef T value_type;
74 
81  carray(value_type* t, std::size_t s) :
82  m_t( s ? t : 0),
83  m_element_count(s)
84  {}
85 
92  carray() : m_t(0), m_element_count(0) {}
93 
100 #if BOOST_VERSION >= 106100
101  carray( boost::serialization::array_wrapper<T> const& orig)
102 #else
103  carray( boost::serialization::array<T> const& orig)
104 #endif
105  : m_t( orig.address() ), m_element_count( orig.count() ) {
106  if (m_element_count == 0)
107  m_t = 0;
108  }
109 
116  template<std::size_t N>
117  carray( boost::array<T,N> & orig)
118  : m_t( orig.c_array() ), m_element_count( N ) {
119  if (m_element_count == 0)
120  m_t = 0;
121  }
122 
126  void init(value_type* t, std::size_t s) {
127  m_t = s ? t : 0;
128  m_element_count = s;
129  }
130 
135  value_type* address() const
136  {
137  return m_t;
138  }
139 
143  std::size_t count() const
144  {
145  return m_element_count;
146  }
147 
154  template <class OtherT>
155  const carray<T>& operator=( const carray<OtherT>& orig ) {
156  if (&orig != this)
157  for(std::size_t i = 0; i != orig.count() && i != count(); ++i)
158  m_t[i] = orig.address()[i];
159  return *this;
160  }
161 
169  template <class OtherT>
170 #if BOOST_VERSION >= 106100
171  const carray<T>& operator=( boost::serialization::array_wrapper<OtherT> const& orig ) {
172 #else
173  const carray<T>& operator=( boost::serialization::array<OtherT> const& orig ) {
174 #endif
175  if (orig.address() != m_t)
176  for(std::size_t i = 0; i != orig.count() && i != count(); ++i)
177  m_t[i] = orig.address()[i];
178  return *this;
179  }
180 
188  template <class OtherT, std::size_t OtherN>
189  const carray<T>& operator=( const boost::array<OtherT,OtherN>& orig ) {
190  if (orig.data() != m_t)
191  for(std::size_t i = 0; i != orig.size() && i != count(); ++i)
192  m_t[i] = orig[i];
193  return *this;
194  }
195 
196  private:
197  value_type* m_t;
198  std::size_t m_element_count;
199  };
200  }
201 }
202 
203 #endif /* ORO_CARRAY_HPP_ */
const carray< T > & operator=(boost::serialization::array< OtherT > const &orig)
Assignment only copies max(this->count(), orig.count()) elements from orig to this object...
Definition: carray.hpp:173
carray(boost::serialization::array< T > const &orig)
We are constructible from boost::serialization::array<T> Makes a shallow copy in order to keep the re...
Definition: carray.hpp:103
void init(value_type *t, std::size_t s)
(Re-)initialize this carray to a new address and size.
Definition: carray.hpp:126
value_type * address() const
The address of the first element of the array.
Definition: carray.hpp:135
Wraps a C array such that we can return a C array from a DataSource.
Definition: carray.hpp:70
std::size_t count() const
Definition: carray.hpp:143
carray()
Creates an empty carray.
Definition: carray.hpp:92
const carray< T > & operator=(const carray< OtherT > &orig)
Assignment only copies max(this->count(), orig.count()) elements from orig to this object...
Definition: carray.hpp:155
carray(boost::array< T, N > &orig)
We are constructible from boost::array<T,N> Makes a shallow copy in order to keep the reference to th...
Definition: carray.hpp:117
carray(value_type *t, std::size_t s)
Create an C array wrapper.
Definition: carray.hpp:81
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52
const carray< T > & operator=(const boost::array< OtherT, OtherN > &orig)
Assignment only copies max(this->count(), orig.size()) elements from orig to this object...
Definition: carray.hpp:189