SUAPI-CppWrapper
C++WrapperforSketchUpCAPI
ShadowInfo.cpp
1 //
2 // ShadowInfo.cpp
3 //
4 // Sketchup C++ Wrapper for C API
5 // MIT License
6 //
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 //
26 
27 // Macro for getting rid of unused variables commonly for assert checking
28 #define _unused(x) ((void)(x))
29 
30 #include "SUAPI-CppWrapper/model/ShadowInfo.hpp"
31 #include "SUAPI-CppWrapper/String.hpp"
32 #include "SUAPI-CppWrapper/model/TypedValue.hpp"
33 #include <cassert>
34 
35 
36 namespace CW {
37 
38 /// @private
39 ShadowInfo::ShadowInfo()
40  : m_shadow_info(SU_INVALID)
41 {
42 }
43 
44 /// @private
45 CW::ShadowInfo::ShadowInfo(SUShadowInfoRef ref)
46  : m_shadow_info(ref)
47 {
48 }
49 
50 ShadowInfo::~ShadowInfo()
51 {
52 }
53 
54 
55 std::vector<std::string> ShadowInfo::get_keys()
56 {
57  size_t len = 0, count = 0;
58  SUResult res = SU_ERROR_NONE;
59 
60  res = SUShadowInfoGetNumKeys(m_shadow_info, &len);
61  assert(res == SU_ERROR_NONE);
62  assert(len > 0);
63 
64  std::vector<SUStringRef> refs(len, SU_INVALID);
65  for(auto i = 0; i < len; i++) {
66  res = SUStringCreate(&refs[i]);
67  assert(res == SU_ERROR_NONE);
68  }
69  res = SUShadowInfoGetKeys(m_shadow_info, len, &refs[0], &count);
70  assert(res == SU_ERROR_NONE); _unused(res);
71  std::vector<std::string> keys;
72  for(auto ref : refs) {
73  keys.push_back(String(ref).std_string());
74  }
75  return keys;
76 }
77 
78 TypedValue ShadowInfo::get_value(const std::string& key)
79 {
80  SUResult res = SU_ERROR_NONE;
81  SUTypedValueRef tval = SU_INVALID;
82  SUTypedValueRef* pTval = &tval;
83  res = SUTypedValueCreate(pTval);
84  assert(res == SU_ERROR_NONE);
85  res = SUShadowInfoGetValue(m_shadow_info, key.c_str(), pTval);
86  assert(res == SU_ERROR_NONE); _unused(res);
87  return TypedValue(*pTval);
88 }
89 
90 bool ShadowInfo::set_value(const std::string& key, const TypedValue& tval)
91 {
92  SUResult res = SU_ERROR_NONE;
93  SUTypedValueRef tref = tval.ref();
94  res = SUShadowInfoSetValue(m_shadow_info, key.c_str(), tref);
95  if(res == SU_ERROR_NONE)
96  return true;
97  else
98  return false;
99 }
100 
101 } // namespace CW
Definition: Color.hpp:34