1 //******************************************************************
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
11 OC::OCReflect::entity OC::OCReflect::remote_resource::operator()(const std::string& name)
13 return OC::OCReflect::entity();
16 namespace OC { namespace OCReflect { namespace to_OCStack {
18 // Free a C array of char *:
19 void release(char **in)
24 for(char **cursor = in; nullptr != *cursor; ++cursor)
26 if(nullptr != *cursor)
33 char *strdup(const char *s)
38 char *ret = static_cast<char *>(malloc(1 + strlen(s)));
43 return strcpy(ret, s);
46 char *strdup(const std::string& s)
48 char *ret = static_cast<char *>(malloc(1 + s.length()));
53 return strcpy(ret, s.c_str());
56 // Count the number of elements in a NULL-terminated C array of char*:
57 size_t length(char **in)
64 for(char **cursor = in; nullptr != *cursor; ++cursor)
70 // Note: caller is responsible for the returned memory:
71 char **convert(const std::vector<std::string>& vs)
77 out = (char **)malloc(vs.size()*sizeof(char *));
83 for(; vs.size() != i; ++i)
85 out[i] = to_OCStack::strdup(vs[i]);
104 std::string convert(const OC::OCReflect::named_property_binding& npb)
106 const std::string& name = std::get<0>(npb);
107 const OC::OCReflect::property_signature ps = std::get<1>(npb);
109 std::ostringstream os;
111 os << name << ':' << "oc.";
113 using OC::OCReflect::property_type;
117 case property_type::nil:
118 case property_type::rational:
119 case property_type::string:
120 case property_type::list:
121 case property_type::INVALID:
122 throw std::runtime_error("not implemented");
125 case property_type::boolean: os << "bt." << 'b';
128 case property_type::integer: os << "bt." << 'i';
135 std::vector<std::string> convert(const OC::OCReflect::named_property_binding_vector& psv)
137 std::vector<std::string> out;
139 for(const auto& ps : psv)
140 out.emplace_back(convert(ps));
145 char *flatten(const std::vector<std::string>& input, const std::string& delim)
149 for(size_t i = 0; input.size() != i; ++i)
153 if(i < input.size() - 1)
157 return OC::OCReflect::to_OCStack::strdup(out);
160 }}} // namespace OC::OCReflect::to_OCStack