PdCom  5.0
Process data communication client
Variable.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * vim:tw=78
3  *
4  * Copyright (C) 2021 Richard Hacker (lerichi at gmx dot net),
5  * Florian Pose (fp at igh dot de),
6  * Bjarne von Horn (vh at igh dot de).
7  *
8  * This file is part of the PdCom library.
9  *
10  * The PdCom library is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or (at your
13  * option) any later version.
14  *
15  * The PdCom library is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with the PdCom library. If not, see <http://www.gnu.org/licenses/>.
22  *
23  *****************************************************************************/
24 
27 #ifndef PDCOM5_VARIABLE_H
28 #define PDCOM5_VARIABLE_H
29 
30 #include "SizeTypeInfo.h"
31 #include "details.h"
32 #include "visibility.h"
33 
34 #include <istream>
35 #include <memory>
36 #include <ostream>
37 #include <stdint.h>
38 #include <string>
39 #include <vector>
40 
41 namespace PdCom {
42 namespace impl {
43 class Variable;
44 }
45 
56 class PDCOM5_PUBLIC Variable
57 {
58  friend class impl::Variable;
59 
60  explicit Variable(std::shared_ptr<const impl::Variable> pimpl) :
61  pimpl(std::move(pimpl))
62  {}
63 
64  public:
67  Variable() = default;
68 
84  template <typename T>
85  typename std::enable_if<!std::is_arithmetic<T>::value, bool>::type
86  setValue(T const &data, size_t index = 0) const
87  {
88  return setValue(
89  &data[0],
91  index, data.size() - index);
92  }
105  template <typename T>
106  typename std::enable_if<std::is_arithmetic<T>::value, bool>::type
107  setValue(T const &data, size_t index = 0) const
108  {
109  return setValue(
110  &data, details::TypeInfoTraits<T>::type_info.type, index, 1);
111  }
112 
126  bool
127  setValue(const void *src, TypeInfo::DataType src_type, size_t idx, size_t n)
128  const;
129 
134  const TypeInfo &getTypeInfo() const noexcept;
139  const SizeInfo &getSizeInfo() const noexcept;
144  std::string getPath() const;
149  std::string getName() const;
154  std::string getAlias() const;
159  int getTaskId() const;
160 
161 
168  bool empty() const noexcept { return !(pimpl); }
169 
170  private:
171  std::shared_ptr<const impl::Variable> pimpl;
172 };
173 
174 } // namespace PdCom
175 
176 #endif // PDCOM5_VARIABLE_H
Size of a Variable.
Definition: SizeTypeInfo.h:62
Type of a Variable.
Definition: SizeTypeInfo.h:33
Definition: details.h:40
std::enable_if< std::is_arithmetic< T >::value, bool >::type setValue(T const &data, size_t index=0) const
Write to a variable.
Definition: Variable.h:107
PdCom Variable interface.
Definition: Variable.h:56
std::enable_if<!std::is_arithmetic< T >::value, bool >::type setValue(T const &data, size_t index=0) const
Write to a variable.
Definition: Variable.h:86
library version string as "major.minor.patch"
Definition: details.h:37