@@ -87,6 +87,11 @@ class value : public value_base
8787 throw std::runtime_error (" Unsupported MetaCall value" );
8888 }
8989
90+ T to_value ()
91+ {
92+ throw std::runtime_error (" Unsupported MetaCall value" );
93+ }
94+
9095 // Type-specific creation (calls specialized version below)
9196 static void *create (const T &v);
9297
@@ -109,7 +114,7 @@ inline enum metacall_value_id value<bool>::id()
109114template <>
110115inline bool value<bool >::to_value() const
111116{
112- return metacall_value_to_bool (value_ptr. get ());
117+ return metacall_value_to_bool (to_raw ());
113118}
114119
115120template <>
@@ -127,7 +132,7 @@ inline enum metacall_value_id value<char>::id()
127132template <>
128133inline char value<char >::to_value() const
129134{
130- return metacall_value_to_char (value_ptr. get ());
135+ return metacall_value_to_char (to_raw ());
131136}
132137
133138template <>
@@ -145,7 +150,7 @@ inline enum metacall_value_id value<short>::id()
145150template <>
146151inline short value<short >::to_value() const
147152{
148- return metacall_value_to_short (value_ptr. get ());
153+ return metacall_value_to_short (to_raw ());
149154}
150155
151156template <>
@@ -163,7 +168,7 @@ inline enum metacall_value_id value<int>::id()
163168template <>
164169inline int value<int >::to_value() const
165170{
166- return metacall_value_to_int (value_ptr. get ());
171+ return metacall_value_to_int (to_raw ());
167172}
168173
169174template <>
@@ -181,7 +186,7 @@ inline enum metacall_value_id value<long>::id()
181186template <>
182187inline long value<long >::to_value() const
183188{
184- return metacall_value_to_long (value_ptr. get ());
189+ return metacall_value_to_long (to_raw ());
185190}
186191
187192template <>
@@ -199,7 +204,7 @@ inline enum metacall_value_id value<float>::id()
199204template <>
200205inline float value<float >::to_value() const
201206{
202- return metacall_value_to_float (value_ptr. get ());
207+ return metacall_value_to_float (to_raw ());
203208}
204209
205210template <>
@@ -217,7 +222,7 @@ inline enum metacall_value_id value<double>::id()
217222template <>
218223inline double value<double >::to_value() const
219224{
220- return metacall_value_to_double (value_ptr. get ());
225+ return metacall_value_to_double (to_raw ());
221226}
222227
223228template <>
@@ -235,7 +240,7 @@ inline enum metacall_value_id value<std::string>::id()
235240template <>
236241inline std::string value<std::string>::to_value() const
237242{
238- return metacall_value_to_string (value_ptr. get ());
243+ return metacall_value_to_string (to_raw ());
239244}
240245
241246template <>
@@ -253,7 +258,7 @@ inline enum metacall_value_id value<const char *>::id()
253258template <>
254259inline const char *value<const char *>::to_value() const
255260{
256- return metacall_value_to_string (value_ptr. get ());
261+ return metacall_value_to_string (to_raw ());
257262}
258263
259264template <>
@@ -271,7 +276,7 @@ inline enum metacall_value_id value<std::vector<char>>::id()
271276template <>
272277inline std::vector<char > value<std::vector<char >>::to_value() const
273278{
274- void *ptr = value_ptr. get ();
279+ void *ptr = to_raw ();
275280 char *buffer = static_cast <char *>(metacall_value_to_buffer (ptr));
276281 std::vector<char > buffer_vector (buffer, buffer + metacall_value_count (ptr));
277282
@@ -293,7 +298,7 @@ inline enum metacall_value_id value<std::vector<unsigned char>>::id()
293298template <>
294299inline std::vector<unsigned char > value<std::vector<unsigned char >>::to_value() const
295300{
296- void *ptr = value_ptr. get ();
301+ void *ptr = to_raw ();
297302 unsigned char *buffer = static_cast <unsigned char *>(metacall_value_to_buffer (ptr));
298303 std::vector<unsigned char > buffer_vector (buffer, buffer + metacall_value_count (ptr));
299304
@@ -315,7 +320,7 @@ inline enum metacall_value_id value<void *>::id()
315320template <>
316321inline void *value<void *>::to_value() const
317322{
318- return metacall_value_to_ptr (value_ptr. get ());
323+ return metacall_value_to_ptr (to_raw ());
319324}
320325
321326template <>
@@ -370,29 +375,25 @@ class array : public value_base
370375 explicit array (void *array_value) :
371376 value_base(array_value, &value_base::noop_destructor) {}
372377
373- void **to_value () const
374- {
375- void **array_ptr = metacall_value_to_array (value_ptr.get ());
376-
377- if (array_ptr == NULL )
378- {
379- throw std::runtime_error (" Invalid MetaCall array" );
380- }
378+ array (array &arr) :
379+ value_base (arr.to_raw(), &value_base::noop_destructor) {}
381380
382- return array_ptr;
381+ array &to_value ()
382+ {
383+ return *this ;
383384 }
384385
385386 template <typename T>
386387 T get (std::size_t index) const
387388 {
388- void **array_ptr = to_value ();
389+ void **array_ptr = to_array ();
389390
390391 return value<T>(array_ptr[index]).to_value ();
391392 }
392393
393394 value_ref operator [](std::size_t index) const
394395 {
395- void **array_ptr = to_value ();
396+ void **array_ptr = to_array ();
396397
397398 return value_ref (array_ptr[index]);
398399 }
@@ -403,6 +404,18 @@ class array : public value_base
403404 }
404405
405406private:
407+ void **to_array () const
408+ {
409+ void **array_ptr = metacall_value_to_array (to_raw ());
410+
411+ if (array_ptr == NULL )
412+ {
413+ throw std::runtime_error (" Invalid MetaCall array" );
414+ }
415+
416+ return array_ptr;
417+ }
418+
406419 // Recursive function to create and fill the MetaCall array
407420 template <typename ... Args>
408421 static void *create (Args &&...args)
@@ -449,6 +462,12 @@ inline enum metacall_value_id value<array>::id()
449462 return METACALL_ARRAY;
450463}
451464
465+ template <>
466+ inline enum metacall_value_id value<array &>::id()
467+ {
468+ return METACALL_ARRAY;
469+ }
470+
452471template <>
453472inline array value<array>::to_value() const
454473{
@@ -470,7 +489,7 @@ class map : public value_base
470489 throw std::runtime_error (" Failed to create MetaCall map value" );
471490 }
472491
473- void **map_array = metacall_value_to_map (value_ptr. get ());
492+ void **map_array = metacall_value_to_map (to_raw ());
474493 size_t index = 0 ;
475494
476495 for (const auto &pair : list)
@@ -516,7 +535,7 @@ class map : public value_base
516535protected:
517536 void rehash ()
518537 {
519- void *ptr = value_ptr. get ();
538+ void *ptr = to_raw ();
520539 void **map_array = metacall_value_to_map (ptr);
521540 const size_t size = metacall_value_count (ptr);
522541
0 commit comments