Merge branch 'develop' into cleanups_and_reworkds

This commit is contained in:
Jason Turner
2016-04-29 10:40:38 -06:00
6 changed files with 91 additions and 1 deletions

View File

@@ -292,6 +292,40 @@ namespace chaiscript
} }
/// Add container resize concept to the given ContainerType
/// http://www.cplusplus.com/reference/stl/
template<typename ContainerType>
void resizable_type(const std::string &/*type*/, Module& m)
{
m.add(fun([](ContainerType *a, typename ContainerType::size_type n, const typename ContainerType::value_type& val) { return a->resize(n, val); } ), "resize");
m.add(fun([](ContainerType *a, typename ContainerType::size_type n) { return a->resize(n); } ), "resize");
}
template<typename ContainerType>
ModulePtr resizable_type(const std::string &type)
{
auto m = std::make_shared<Module>();
resizable_type<ContainerType>(type, *m);
return m;
}
/// Add container reserve concept to the given ContainerType
/// http://www.cplusplus.com/reference/stl/
template<typename ContainerType>
void reservable_type(const std::string &/*type*/, Module& m)
{
m.add(fun([](ContainerType *a, typename ContainerType::size_type n) { return a->reserve(n); } ), "reserve");
m.add(fun([](const ContainerType *a) { return a->capacity(); } ), "capacity");
}
template<typename ContainerType>
ModulePtr reservable_type(const std::string &type)
{
auto m = std::make_shared<Module>();
reservable_type<ContainerType>(type, *m);
return m;
}
/// Add container concept to the given ContainerType /// Add container concept to the given ContainerType
/// http://www.sgi.com/tech/stl/Container.html /// http://www.sgi.com/tech/stl/Container.html
template<typename ContainerType> template<typename ContainerType>
@@ -581,6 +615,7 @@ namespace chaiscript
front_insertion_sequence_type<ListType>(type, m); front_insertion_sequence_type<ListType>(type, m);
back_insertion_sequence_type<ListType>(type, m); back_insertion_sequence_type<ListType>(type, m);
sequence_type<ListType>(type, m); sequence_type<ListType>(type, m);
resizable_type<ListType>(type, m);
container_type<ListType>(type, m); container_type<ListType>(type, m);
default_constructible_type<ListType>(type, m); default_constructible_type<ListType>(type, m);
assignable_type<ListType>(type, m); assignable_type<ListType>(type, m);
@@ -612,6 +647,8 @@ namespace chaiscript
back_insertion_sequence_type<VectorType>(type, m); back_insertion_sequence_type<VectorType>(type, m);
sequence_type<VectorType>(type, m); sequence_type<VectorType>(type, m);
random_access_container_type<VectorType>(type, m); random_access_container_type<VectorType>(type, m);
resizable_type<VectorType>(type, m);
reservable_type<VectorType>(type, m);
container_type<VectorType>(type, m); container_type<VectorType>(type, m);
default_constructible_type<VectorType>(type, m); default_constructible_type<VectorType>(type, m);
assignable_type<VectorType>(type, m); assignable_type<VectorType>(type, m);

View File

@@ -100,6 +100,24 @@ namespace chaiscript
} }
}; };
template<typename Ret>
struct Handle_Return<Ret *&>
{
static Boxed_Value handle(Ret *p)
{
return Boxed_Value(p, true);
}
};
template<typename Ret>
struct Handle_Return<const Ret *&>
{
static Boxed_Value handle(const Ret *p)
{
return Boxed_Value(p, true);
}
};
template<typename Ret> template<typename Ret>
struct Handle_Return<Ret *> struct Handle_Return<Ret *>
{ {

View File

@@ -23,6 +23,7 @@
#include "chaiscript_optimizer.hpp" #include "chaiscript_optimizer.hpp"
#if defined(CHAISCRIPT_MSVC) && defined(max) && defined(min) #if defined(CHAISCRIPT_MSVC) && defined(max) && defined(min)
#define CHAISCRIPT_PUSHED_MIN_MAX
#pragma push_macro("max") // Why Microsoft? why? This is worse than bad #pragma push_macro("max") // Why Microsoft? why? This is worse than bad
#undef max #undef max
#pragma push_macro("min") #pragma push_macro("min")
@@ -2331,7 +2332,8 @@ namespace chaiscript
} }
#ifdef CHAISCRIPT_MSVC #if defined(CHAISCRIPT_MSVC) && defined(CHAISCRIPT_PUSHED_MIN_MAX)
#undef CHAISCRIPT_PUSHED_MIN_MAX
#pragma pop_macro("min") #pragma pop_macro("min")
#pragma pop_macro("max") #pragma pop_macro("max")
#endif #endif

View File

@@ -0,0 +1,13 @@
load_module("stl_extra");
auto list = List();
list.resize(2);
assert_equal(list.size(), 2);
list.resize(6, "AAA");
assert_equal(list.back(), "AAA");
list.resize(0);
assert_equal(list.size(), 0);

View File

@@ -0,0 +1,7 @@
load_module("stl_extra");
auto uint16v = u16vector();
uint16v.reserve(5);
assert_true(uint16v.capacity() >= 5);

View File

@@ -0,0 +1,13 @@
load_module("stl_extra");
auto uint16v = u16vector();
uint16v.resize(2);
assert_equal(uint16v.size(), 2);
uint16v.resize(6, 3);
assert_equal(uint16v[5], 3);
uint16v.resize(0);
assert_equal(uint16v.size(), 0);