stromx  0.8.0
List.h
1 /*
2 * Copyright 2015 Matthias Fuchs
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17 #ifndef STROMX_RUNTIME_LIST_H
18 #define STROMX_RUNTIME_LIST_H
19 
20 #include <vector>
21 #include "stromx/runtime/Data.h"
22 
23 namespace stromx
24 {
25  namespace runtime
26  {
28  class STROMX_RUNTIME_API List : public Data
29  {
30  public:
32  List() {}
33  explicit List(const std::vector<Data*> & content) : m_content(content) {}
34  ~List();
35 
36  virtual const std::string & type() const { return TYPE; }
37  virtual const Version & version() const { return VERSION; }
38  virtual const std::string & package() const { return PACKAGE; }
39 
40  virtual const VariantHandle & variant() const;
41 
42  virtual Data* clone() const;
43 
45  std::vector<Data*> & content() { return m_content; }
46 
48  std::vector<const Data*> content() const
49  {
50  return std::vector<const Data*>(m_content.begin(), m_content.end());
51  }
52 
53  private:
54  static const std::string TYPE;
55  static const std::string PACKAGE;
56  static const Version VERSION;
57 
58  std::vector<Data*> m_content;
59  };
60 
62  template <>
63  class STROMX_RUNTIME_API data_traits<List>
64  {
65  public:
66  static const VariantHandle & variant();
67  };
70  template <class T>
71  class TypedList : public List
72  {
73  public:
74  template <class src_t>
75  TypedList(const std::vector<src_t> & srcContent) : List()
76  {
77  content().reserve(srcContent.size());
78  for (typename std::vector<src_t>::const_iterator iter = srcContent.begin();
79  iter != srcContent.end(); ++iter)
80  {
81  src_t & src = const_cast<src_t&>(*iter);
82  content().push_back(new T(src));
83  }
84  }
85  };
86  }
87 }
88 
89 
90 
91 #endif // STROMX_RUNTIME_LIST_H
A version of an operator or data type.
Definition: Version.h:46
Abstract data object.
Definition: Data.h:53
Definition: List.h:71
Definition: VariantHandle.h:34
The stromx class library.
Definition: AdjustRgbChannels.cpp:29
virtual const std::string & type() const
Definition: List.h:36
virtual const Version & version() const
Definition: List.h:37
List()
Definition: List.h:32
List of data values.
Definition: List.h:28
std::vector< const Data * > content() const
Definition: List.h:48
virtual const std::string & package() const
Definition: List.h:38
std::vector< Data * > & content()
Definition: List.h:45