SUAPI-CppWrapper
C++WrapperforSketchUpCAPI
AttributeDictionary.hpp
1 //
2 // AttributeDictionary.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 AttributeDictionary_hpp
29 #define AttributeDictionary_hpp
30 
31 #include <stdio.h>
32 #include <vector>
33 #include <string>
34 
35 #include <SketchUpAPI/model/attribute_dictionary.h>
36 
37 #include "SUAPI-CppWrapper/model/Entity.hpp"
38 
39 namespace CW {
40 
41 class TypedValue;
42 class String;
43 
44 /*
45 * Entity object wrapper
46 */
47 class AttributeDictionary :public Entity {
48  /**
49  * Creates a SUAttributeDictionaryRef object using the given name.
50  * @param name - name of the created AttributeDictionary object.
51  * @since SketchUp 2018, API v6.0
52  * @return SUAttributeDictionaryRef object with the given name.
53  */
54  static SUAttributeDictionaryRef create_attribute_dictionary(const std::string& name);
55 
56  /**
57  * Creates a SUAttributeDictionaryRef derived from an existing AttributeDictionary object.
58  * @param dict - AttributeDictionary object to derive the new SUAttributeDictionaryRef from
59  * @since SketchUp 2018, API v6.0
60  * @return if the AttributeDictionary object is already attached to a model, its SUAttributeDictionaryRef will be returned. If the AttributeDicitonary object has not been attached to a model, a new SUAttributeDictionaryRef object will be created. In the latter case, bear in mind that keys and values will not be copied to the new object - this would have to be done manually.
61  */
62  static SUAttributeDictionaryRef copy_reference(const AttributeDictionary& dict);
63 
64  public:
65  /**
66  * Constructor for null object.
67  */
69 
70  /**
71  * Constructor to create a new object.
72  * @param name - name of the dictionary to create.
73  * @since SketchUp 2018, API v6.0
74  */
75  AttributeDictionary(std::string name);
76 
77  /**
78  * Constructor from existing SUAttributeDictionaryRef object
79  * @param dict - existing SUAttributeDictionaryRef object to wrap with this class.
80  * @param attached - indicates whether the dictionary is attached to an entity or not.
81  */
82  AttributeDictionary(SUAttributeDictionaryRef dict, bool attached = true);
83 
84  /** Copy constructor */
86 
87  /**
88  * Destructor
89  * @since SketchUp 2018, API v6.0
90  */
92 
93  /** Copy assignment operator */
95 
96  /** Cast to native object **/
97  SUAttributeDictionaryRef ref() const;
98  operator SUAttributeDictionaryRef() const;
99  operator SUAttributeDictionaryRef*();
100 
101  /**
102  * Returns the value of the attribute with the specified key.
103  * @param &key - the key of the attribute
104  * @param &default_value - the default value to return if the attribute with the key does not exist.
105  */
106  TypedValue get_attribute(const std::string &key, const TypedValue &default_value) const;
107 
108  /**
109  * Alias of AttributeDictionary::get_attribute().
110  * @return TypedValue object. If the attribute does not exist, a null TypedValue object will be returned.
111  */
112  TypedValue get_value(const std::string &key) const;
113 
114  /**
115  * Sets the specified attribute's value.
116  * @param &key - the key of the attribute to set.
117  * @param &value - the value to set.
118  */
119  bool set_attribute(const std::string &key, const TypedValue &value);
120 
121  /**
122  * Returns a vector array of keys in the Attribute Dictionary.
123  */
124  std::vector<std::string> get_keys() const;
125 
126  /**
127  * Returns the name of the AttributeDictionary.
128  */
129  std::string get_name() const;
130 
131  /**
132  * Returns true if this is a null object.
133  */
134  bool operator!() const;
135 
136 };
137 
138 } /* namespace CW */
139 
140 #endif /* AttributeDictionary_hpp */
SUAttributeDictionaryRef ref() const
std::string get_name() const
AttributeDictionary & operator=(const AttributeDictionary &other)
bool attached() const
Returns true if the entity is attached to another object.
Definition: Entity.cpp:100
TypedValue get_attribute(const std::string &key, const TypedValue &default_value) const
TypedValue get_value(const std::string &key) const
Definition: Color.hpp:34
std::vector< std::string > get_keys() const
bool set_attribute(const std::string &key, const TypedValue &value)