Added MapReverseIterator implementation.
This commit is contained in:
parent
46381cb15c
commit
de09adcaa9
@ -1186,6 +1186,7 @@ public:
|
||||
virtual unsigned int size(const osg::Object& obj) const { return 0; }
|
||||
|
||||
virtual MapIteratorObject* createIterator(osg::Object& obj) const { return 0; }
|
||||
virtual MapIteratorObject* createReverseIterator(osg::Object& obj) const { return 0; }
|
||||
|
||||
protected:
|
||||
Type _keyType;
|
||||
@ -1204,6 +1205,7 @@ public:
|
||||
typedef typename P::key_type KeyType;
|
||||
typedef typename P::mapped_type ElementType;
|
||||
typedef typename P::iterator Iterator;
|
||||
typedef typename P::reverse_iterator ReverseIterator;
|
||||
typedef typename P::const_iterator ConstIterator;
|
||||
typedef P& (C::*Getter)();
|
||||
typedef const P& (C::*ConstGetter)() const;
|
||||
@ -1270,6 +1272,23 @@ public:
|
||||
virtual void setElement(void* ptr) const { if (valid()) _itr->second = *reinterpret_cast<ElementType*>(ptr); }
|
||||
};
|
||||
|
||||
struct ReverseMapIterator : public MapIteratorObject
|
||||
{
|
||||
ReverseMapIterator(BaseSerializer::Type keyType, unsigned int keySize, BaseSerializer::Type elementType, unsigned int elementSize,
|
||||
ReverseIterator itr, ReverseIterator endItr):
|
||||
MapIteratorObject(keyType, keySize, elementType, elementSize),
|
||||
_itr(itr),_endItr(endItr) {}
|
||||
|
||||
ReverseIterator _itr;
|
||||
ReverseIterator _endItr;
|
||||
|
||||
virtual bool advance() { if (valid()) ++_itr; return valid(); }
|
||||
virtual bool valid() const { return _itr!=_endItr; }
|
||||
virtual const void* getKey() const { return valid() ? &(_itr->first) : 0; }
|
||||
virtual void* getElement() const { return valid() ? &(_itr->second) : 0; }
|
||||
virtual void setElement(void* ptr) const { if (valid()) _itr->second = *reinterpret_cast<ElementType*>(ptr); }
|
||||
};
|
||||
|
||||
virtual MapIteratorObject* createIterator(osg::Object& obj) const
|
||||
{
|
||||
C& object = OBJECT_CAST<C&>(obj);
|
||||
@ -1277,6 +1296,13 @@ public:
|
||||
return new MapIterator(_keyType, _keySize, _elementType, _elementSize, map.begin(), map.end());
|
||||
}
|
||||
|
||||
virtual MapIteratorObject* createReverseIterator(osg::Object& obj) const
|
||||
{
|
||||
C& object = OBJECT_CAST<C&>(obj);
|
||||
P& map = (object.*_getter)();
|
||||
return new ReverseMapIterator(_keyType, _keySize, _elementType, _elementSize, map.rbegin(), map.rend());
|
||||
}
|
||||
|
||||
virtual bool read( InputStream& is, osg::Object& obj )
|
||||
{
|
||||
C& object = OBJECT_CAST<C&>(obj);
|
||||
|
@ -492,6 +492,28 @@ static int createMapIterator(lua_State* _lua)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int createMapReverseIterator(lua_State* _lua)
|
||||
{
|
||||
const LuaScriptEngine* lse = reinterpret_cast<const LuaScriptEngine*>(lua_topointer(_lua, lua_upvalueindex(1)));
|
||||
int n = lua_gettop(_lua); /* number of arguments */
|
||||
if (n<1 || lua_type(_lua, 1)!=LUA_TTABLE) return 0;
|
||||
|
||||
osg::Object* object = lse->getObjectFromTable<osg::Object>(1);
|
||||
std::string containerPropertyName = lse->getStringFromTable(1,"containerPropertyName");
|
||||
|
||||
// check to see if Object "is a" vector
|
||||
osgDB::BaseSerializer::Type type;
|
||||
osgDB::BaseSerializer* bs = lse->getPropertyInterface().getSerializer(object, containerPropertyName, type);
|
||||
osgDB::MapBaseSerializer* ms = dynamic_cast<osgDB::MapBaseSerializer*>(bs);
|
||||
if (ms)
|
||||
{
|
||||
lse->pushObject(ms->createReverseIterator(*object));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// MapIteratorObject support
|
||||
@ -3037,6 +3059,7 @@ void LuaScriptEngine::pushContainer(osg::Object* object, const std::string& prop
|
||||
assignClosure("clear", callMapClear);
|
||||
assignClosure("size", getMapSize);
|
||||
assignClosure("createIterator", createMapIterator);
|
||||
assignClosure("createReverseIterator", createMapReverseIterator);
|
||||
|
||||
luaL_getmetatable(_lua, "LuaScriptEngine.Map");
|
||||
lua_setmetatable(_lua, -2);
|
||||
|
Loading…
Reference in New Issue
Block a user