SUAPI-CppWrapper
C++WrapperforSketchUpCAPI
TypedValue.hpp
1 //
2 // TypedValue.hpp
3 //
4 // Sketchup C++ Wrapper for C API
5 // MIT License
6 //
7 // Copyright (c) 2017 Tom Kaneko
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
15 
16 // The above copyright notice and this permission notice shall be included in all
17 // copies or substantial portions of the Software.
18 
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 // SOFTWARE.
26 //
27 
28 #ifndef TypedValue_hpp
29 #define TypedValue_hpp
30 
31 #include <stdio.h>
32 #include <string>
33 #include <vector>
34 
35 #include <SketchUpAPI/model/typed_value.h>
36 
37 
38 namespace CW {
39 
40 // Forward Declarations
41 class Color;
42 class String;
43 class Vector3D;
44 
45 class TypedValue {
46  private:
47  SUTypedValueRef m_typed_value;
48  /**
49  * Indicates whether the TypedValue is attached to another TypedValue
50  */
51  bool m_attached;
52 
53  static SUTypedValueRef create_typed_value();
54 
55  public:
56  TypedValue();
57  TypedValue(SUTypedValueRef typed_val, bool attached = false);
58 
59  /** Copy constructor */
60  TypedValue(const TypedValue& other);
61 
62  /** Copy Assignment Operator */
63  TypedValue& operator= (const TypedValue& other);
64 
65  ~TypedValue();
66 
67  SUTypedValueRef ref() const;
68  operator SUTypedValueRef();
69  operator SUTypedValueRef*();
70 
71  /**
72  * Checks whether TypedValue has been initialised.
73  */
74  bool operator!() const;
75 
76 
77  /**
78  * Checks whether TypedValue is empty.
79  */
80  bool empty() const;
81 
82  /**
83  * Retrieves the type information of a typed value object.
84  * @see enum SUTypedValueType for values
85  */
86  SUTypedValueType get_type() const;
87 
88  /**
89  * Retrieves/ Set the byte value of a typed value object.
90  */
91  char byte_value() const;
92  TypedValue& byte_value(const char byte_val);
93  operator char() const;
94 
95  TypedValue(const char byte_val);
96 
97  /**
98  * Retrieves/Sets the int16 value of a typed value object.
99  */
100  int16_t int16_value() const;
101  TypedValue& int16_value(const int16_t int16_val);
102  operator int16_t() const;
103 
104  TypedValue(const int16_t int16_val);
105 
106  /**
107  * Retrieves/Sets the int32 value of a typed value object.
108  */
109  int32_t int32_value() const;
110  TypedValue& int32_value(const int32_t int32_val);
111  operator int32_t() const;
112 
113  TypedValue(const int32_t int32_val);
114 
115  /**
116  * Retrieves/Sets the float value of a typed value object.
117  */
118  float float_value() const;
119  TypedValue& float_value(const float float_val);
120  operator float() const;
121 
122  TypedValue(const float float_val);
123 
124  /**
125  * Retrieves/Sets the double value of a typed value object.
126  */
127  double double_value() const;
128  TypedValue& double_value(const double double_val);
129  operator double() const;
130 
131  TypedValue(const double double_val);
132 
133  /**
134  * Retrieves the boolean value of a typed value object.
135  */
136  bool bool_value() const;
137  TypedValue& bool_value(bool bool_val);
138  operator bool() const;
139 
140  TypedValue(const bool bool_val);
141 
142  /**
143  * Retrieves the color value of a typed value object.
144  */
145  Color color_value() const;
146  TypedValue& color_value(const Color &color_val);
147  operator Color() const;
148 
149  TypedValue(const Color &color_val);
150 
151  /**
152  * Retrieves/Sets the time value of a typed value object. The time value is in seconds since January 1, 1970.
153  */
154  int64_t time_value() const;
155  TypedValue& time_value(int64_t time_val);
156  operator int64_t() const;
157 
158  TypedValue(const int64_t time_value);
159 
160  /**
161  * Retrieves/Sets the string value of a typed value object.
162  */
163  String string_value() const;
164  TypedValue& string_value(const String &string_val);
165  TypedValue& string_value(const std::string &string_val);
166  operator String() const;
167  operator std::string() const;
168 
169  explicit TypedValue(const char chars[]);
170  TypedValue(const std::string& string);
171  TypedValue(const String& string);
172 
173  /**
174  * Retrieves/Sets the 3-element vector value of a typed value object
175  */
176  Vector3D vector_value() const;
177  TypedValue& vector_value(const Vector3D &vector_val);
178  operator Vector3D() const;
179 
180  TypedValue(const Vector3D& vector);
181 
182  /**
183  * Retrieve/Set the array of typed value objects of a type value object.
184  */
185  std::vector<TypedValue> typed_value_array() const;
186  TypedValue& typed_value_array(std::vector<TypedValue> &typed_val_array);
187  operator std::vector<TypedValue>() const;
188 
189  TypedValue(std::vector<TypedValue>& array);
190 
191  /**
192  * Comparison operator overloads
193  */
194  friend bool operator== (const TypedValue &val1, const TypedValue &val2);
195  friend bool operator!= (const TypedValue &val1, const TypedValue &val2);
196 
197 };
198 
199 } /* namespace CW */
200 #endif /* TypedValue_hpp */
TypedValue & operator=(const TypedValue &other)
Definition: TypedValue.cpp:62
double double_value() const
Definition: TypedValue.cpp:316
float float_value() const
Definition: TypedValue.cpp:280
int64_t time_value() const
Definition: TypedValue.cpp:425
std::vector< TypedValue > typed_value_array() const
Definition: TypedValue.cpp:557
Color color_value() const
Definition: TypedValue.cpp:388
char byte_value() const
Definition: TypedValue.cpp:171
bool operator!() const
Definition: TypedValue.cpp:124
int32_t int32_value() const
Definition: TypedValue.cpp:244
friend bool operator==(const TypedValue &val1, const TypedValue &val2)
Definition: TypedValue.cpp:611
SUTypedValueType get_type() const
Definition: TypedValue.cpp:160
Vector3D vector_value() const
Definition: TypedValue.cpp:520
String string_value() const
Definition: TypedValue.cpp:461
Definition: Color.hpp:34
bool bool_value() const
Definition: TypedValue.cpp:352
bool empty() const
Definition: TypedValue.cpp:132
int16_t int16_value() const
Definition: TypedValue.cpp:207