cppbind: convert maps from nasal.
This commit is contained in:
@@ -54,6 +54,14 @@ namespace nasal
|
|||||||
: naNil();
|
: naNil();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
std::vector<std::string> Hash::keys() const
|
||||||
|
{
|
||||||
|
naRef keys = naNewVector(_context);
|
||||||
|
naHash_keys(keys, _hash);
|
||||||
|
return from_nasal<std::vector<std::string> >(_context, keys);
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
Hash Hash::createHash(const std::string& name)
|
Hash Hash::createHash(const std::string& name)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
#include "from_nasal.hxx"
|
#include "from_nasal.hxx"
|
||||||
#include "to_nasal.hxx"
|
#include "to_nasal.hxx"
|
||||||
|
|
||||||
|
#include <simgear/structure/map.hxx>
|
||||||
|
|
||||||
namespace nasal
|
namespace nasal
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -101,6 +103,11 @@ namespace nasal
|
|||||||
return from_nasal_helper(_context, get(name), static_cast<Sig*>(0));
|
return from_nasal_helper(_context, get(name), static_cast<Sig*>(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of all keys
|
||||||
|
*/
|
||||||
|
std::vector<std::string> keys() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new child hash (module)
|
* Create a new child hash (module)
|
||||||
*
|
*
|
||||||
@@ -129,4 +136,21 @@ namespace nasal
|
|||||||
|
|
||||||
} // namespace nasal
|
} // namespace nasal
|
||||||
|
|
||||||
|
template<class Value>
|
||||||
|
simgear::Map<std::string, Value>
|
||||||
|
from_nasal_helper( naContext c,
|
||||||
|
naRef ref,
|
||||||
|
const simgear::Map<std::string, Value>* )
|
||||||
|
{
|
||||||
|
|
||||||
|
nasal::Hash hash = from_nasal_helper(c, ref, static_cast<nasal::Hash*>(0));
|
||||||
|
std::vector<std::string> const& keys = hash.keys();
|
||||||
|
|
||||||
|
simgear::Map<std::string, Value> map;
|
||||||
|
for(size_t i = 0; i < keys.size(); ++i)
|
||||||
|
map[ keys[i] ] = hash.get<Value>(keys[i]);
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* SG_NASAL_HASH_HXX_ */
|
#endif /* SG_NASAL_HASH_HXX_ */
|
||||||
|
|||||||
@@ -168,6 +168,11 @@ int main(int argc, char* argv[])
|
|||||||
r = to_nasal(c, hash);
|
r = to_nasal(c, hash);
|
||||||
VERIFY( naIsHash(r) );
|
VERIFY( naIsHash(r) );
|
||||||
|
|
||||||
|
simgear::StringMap string_map = from_nasal<simgear::StringMap>(c, r);
|
||||||
|
VERIFY( string_map.at("vec") == "string" )
|
||||||
|
VERIFY( string_map.at("name") == "my-name" )
|
||||||
|
VERIFY( string_map.at("string") == "blub" )
|
||||||
|
|
||||||
VERIFY( hash.get<std::string>("name") == "my-name" );
|
VERIFY( hash.get<std::string>("name") == "my-name" );
|
||||||
VERIFY( naIsString(hash.get("name")) );
|
VERIFY( naIsString(hash.get("name")) );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user