SUAPI-CppWrapper
C++WrapperforSketchUpCAPI
Layer.hpp
1 //
2 // Layer.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 Layer_hpp
29 #define Layer_hpp
30 
31 #include <stdio.h>
32 #include "SUAPI-CppWrapper/model/Entity.hpp"
33 
34 #include <SketchUpAPI/model/layer.h>
35 
36 namespace CW {
37 // Forward declarations
38 class String;
39 
40 class Layer :public Entity {
41  private:
42  static SULayerRef create_layer();
43  /**
44  * Creates a SULayerRef derived from an existing Layer object.
45  * @param other - Layer object to derive the new SULayerRef object from
46  * @return if the Layer object is already attached to a model, its SULayerRef object will be returned. If the Material object has not been attached to a model, a new SULayerRef object will be created. Bear in mind all properties will not be copied in the latter case
47  */
48  static SULayerRef copy_reference(const Layer& other);
49 
50  public:
51  /**
52  * Constructs a NULL layer.
53  */
54  Layer();
55 
56  /**
57  * Constructs a Layer object from a pre existing SULayerRef object.
58  */
59  Layer(SULayerRef layer_ref, bool attached = true);
60 
61  /** Copy Constructor */
62  Layer(const Layer& other);
63 
64  /** Destructor */
65  ~Layer();
66 
67  /** Copy assignment operator */
68  Layer& operator=(const Layer& other);
69 
70  /**
71  * Returns the SULayerRef object that this class wraps
72  */
73  SULayerRef ref() const;
74  operator SULayerRef() const;
75  operator SULayerRef*();
76 
77  /**
78  * Returns whether this is a NULL layer or not.
79  */
80  bool operator!() const;
81 
82  /**
83  * Returns a copy of the Layer object, which is not attached to a model.
84  */
85  Layer copy() const;
86 
87  /**
88  * Get the name of the layer.
89  */
90  String name() const;
91 
92  /**
93  * Set the name of the layer.
94  */
95  void name(const String& string);
96  void name(const std::string& string);
97 
98  /**
99  * Hash function for use with unordered_map
100  */
101  friend std::hash<CW::Layer>;
102 };
103 
104 } /* namespace CW */
105 
106 namespace std {
107  template <> struct hash<CW::Layer>
108  {
109  size_t operator()(const CW::Layer& k) const
110  {
111  static const size_t shift = (size_t)log2(1 + sizeof(CW::Layer));
112  return (size_t)(k.m_entity.ptr) >> shift;
113  }
114  };
115 
116 }
117 
118 #endif /* Layer_hpp */
~Layer()
Definition: Layer.cpp:81
String name() const
Definition: Layer.cpp:141
bool attached() const
Returns true if the entity is attached to another object.
Definition: Entity.cpp:100
STL namespace.
Layer copy() const
Definition: Layer.cpp:131
Layer()
Definition: Layer.cpp:61
bool operator!() const
Definition: Layer.cpp:118
SUEntityRef m_entity
The C SUEntityRef that this class wraps.
Definition: Entity.hpp:59
SULayerRef ref() const
Definition: Layer.cpp:109
Layer & operator=(const Layer &other)
Definition: Layer.cpp:93
Definition: Color.hpp:34