Skip to content

Commit f343311

Browse files
committed
Improve cxx port.
1 parent 5d7c589 commit f343311

File tree

2 files changed

+20
-31
lines changed

2 files changed

+20
-31
lines changed

source/ports/cxx_port/include/metacall/metacall.hpp

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ inline std::nullptr_t value<std::nullptr_t>::to_value() const
336336
return nullptr;
337337
}
338338

339-
// TODO: Array, Map, Future, Function, Class, Object, Exception, Throwable...
339+
// TODO: Future, Function, Class, Object, Exception, Throwable...
340340

341341
template <typename K, typename V>
342342
class METACALL_API map : public value_base
@@ -386,6 +386,17 @@ class METACALL_API map : public value_base
386386
rehash();
387387
}
388388

389+
V operator[](const K &key) const
390+
{
391+
return m.at(key).second.to_value();
392+
}
393+
394+
static enum metacall_value_id id()
395+
{
396+
return METACALL_MAP;
397+
}
398+
399+
protected:
389400
void rehash()
390401
{
391402
void *ptr = value_ptr.get();
@@ -406,31 +417,7 @@ class METACALL_API map : public value_base
406417
}
407418
}
408419

409-
V operator[](const K &key) const
410-
{
411-
return m.at(key).second.to_value();
412-
}
413-
414420
private:
415-
/*
416-
// Case 1: value is value_base (e.g. nested metacall map value)
417-
template <typename T>
418-
static typename std::enable_if<std::is_base_of<value_base, T>::value, value<T>>::type
419-
wrap_value(const T &v)
420-
{
421-
return const_cast<T &>(v);
422-
}
423-
424-
// Case 2: value is a plain type
425-
template <typename T>
426-
static typename std::enable_if<!std::is_base_of<value_base, T>::value, value<T>>::type
427-
wrap_value(const T &v)
428-
{
429-
value<T> val(v);
430-
return val;
431-
}
432-
*/
433-
434421
std::unordered_map<K, pair_value_type> m;
435422
};
436423

source/tests/metacall_cxx_port_test/source/metacall_cxx_port_test.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,23 @@ void *cxx_map_test(size_t argc, void *args[], void *data)
4646
return metacall_value_create_null();
4747
}
4848

49+
// TODO:
50+
/*
4951
void *cxx_recursive_map_test(size_t argc, void *args[], void *data)
5052
{
51-
map<std::string, float> m(args[0]);
53+
map<std::string, map<std::string, float>> m(args[0]);
5254
5355
(void)argc;
5456
(void)data;
5557
56-
EXPECT_EQ((float)m["hello"], (float)3.0f);
57-
EXPECT_EQ((float)m["world"], (float)4.0f);
58+
EXPECT_EQ((float)m["hello"]["world"], (float)4.0f);
5859
59-
printf("hello => %f\n", m["hello"]);
60-
printf("world => %f\n", m["world"]);
60+
printf("hello => %f\n", m["hello"]["world"]);
6161
fflush(stdout);
6262
6363
return metacall_value_create_null();
6464
}
65+
*/
6566

6667
TEST_F(metacall_cxx_port_test, DefaultConstructor)
6768
{
@@ -88,10 +89,11 @@ TEST_F(metacall_cxx_port_test, DefaultConstructor)
8889
metacall_value_destroy(ret);
8990
}
9091

92+
// TODO:
9193
/*
9294
{
9395
map<std::string, map<std::string, float>> m = {
94-
{ "hello", { "world", 4.0f } },
96+
{ "hello", { "world", 4.0f } }
9597
};
9698
9799
void *args[] = {

0 commit comments

Comments
 (0)