stromx  0.8.0
Tribool.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_TRIBOOL_H
18 #define STROMX_RUNTIME_TRIBOOL_H
19 
20 #ifdef __GNUG__
21  #include <tr1/cstdint>
22 #else
23  #include <cstdint>
24 #endif
25 
26 #include "stromx/runtime/Config.h"
27 #include "stromx/runtime/Data.h"
28 
29 namespace stromx
30 {
31  namespace runtime
32  {
34  class STROMX_RUNTIME_API Tribool : public Data
35  {
36  friend STROMX_RUNTIME_API bool operator==(const Tribool & lhs, const Tribool & rhs);
37  friend STROMX_RUNTIME_API bool operator!=(const Tribool & lhs, const Tribool & rhs);
38  friend STROMX_RUNTIME_API std::ostream& operator<<(std::ostream& out, const Tribool& value);
39 
40  public:
41 
43  explicit Tribool() : m_value(-1) {}
44 
46  explicit Tribool(const bool value) : m_value(value) {}
47 
48  bool undefined() const { return m_value == UNDEFINED; }
49  operator bool() const { return m_value == TRUE; }
50 
51  virtual const std::string & type() const { return TYPE; }
52  virtual const Version & version() const { return VERSION; }
53  virtual const std::string & package() const { return PACKAGE; }
54 
55  virtual const VariantHandle & variant() const;
56 
57  virtual Data* clone() const { return new Tribool(*this); }
58 
59  virtual void serialize(OutputProvider & out) const;
60  virtual void deserialize(InputProvider & in, const Version & version);
61 
62  private:
63  enum Value
64  {
65  UNDEFINED = -1,
66  TRUE = 1,
67  FALSE = 0
68  };
69 
70  static const std::string TYPE;
71  static const std::string PACKAGE;
72  static const Version VERSION;
73 
74  int8_t m_value;
75  };
76 
78  STROMX_RUNTIME_API bool operator==(const Tribool & lhs, const Tribool & rhs);
79 
81  STROMX_RUNTIME_API bool operator!=(const Tribool & lhs, const Tribool & rhs);
82 
83  STROMX_RUNTIME_API std::ostream& operator<<(std::ostream& out, const Tribool& string);
84 
86  template <>
87  class STROMX_RUNTIME_API data_traits<Tribool>
88  {
89  public:
90  static const VariantHandle & variant();
91  };
93  }
94 }
95 
96 
97 
98 #endif // STROMX_RUNTIME_STRING_H
A version of an operator or data type.
Definition: Version.h:46
Abstract data object.
Definition: Data.h:53
Tribool(const bool value)
Definition: Tribool.h:46
Tribool()
Definition: Tribool.h:43
Definition: VariantHandle.h:34
virtual const std::string & package() const
Definition: Tribool.h:53
virtual Data * clone() const
Definition: Tribool.h:57
Provides functions to serialize data to strings and files.
Definition: OutputProvider.h:27
Provides functions to deserialize data from strings and files.
Definition: InputProvider.h:27
Version version()
Returns the version of the stromx runtime library.
Definition: Runtime.cpp:54
The stromx class library.
Definition: AdjustRgbChannels.cpp:29
String data value.
Definition: Tribool.h:34
bool operator!=(const runtime::DataContainer &lhs, const runtime::DataContainer &rhs)
Definition: DataContainer.cpp:46
virtual const std::string & type() const
Definition: Tribool.h:51
virtual const Version & version() const
Definition: Tribool.h:52