1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-07 12:54:00 +00:00
OpenMW/components/lua_ui/content.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.6 KiB
C++
Raw Normal View History

2021-11-18 15:19:54 +00:00
#ifndef COMPONENTS_LUAUI_CONTENT
#define COMPONENTS_LUAUI_CONTENT
#include <map>
#include <string>
#include <sol/sol.hpp>
namespace LuaUi
{
class Content
{
public:
using iterator = std::vector<sol::table>::iterator;
2023-01-13 20:14:23 +00:00
Content() { sInstanceCount++; }
~Content() { sInstanceCount--; }
Content(const Content& c)
{
this->mNamed = c.mNamed;
this->mOrdered = c.mOrdered;
sInstanceCount++;
}
Content(Content&& c)
{
this->mNamed = std::move(c.mNamed);
this->mOrdered = std::move(c.mOrdered);
sInstanceCount++;
}
2021-11-18 15:19:54 +00:00
// expects a Lua array - a table with keys from 1 to n without any nil values in between
// any other keys are ignored
explicit Content(const sol::table&);
size_t size() const { return mOrdered.size(); }
void assign(std::string_view name, const sol::table& table);
void assign(size_t index, const sol::table& table);
void insert(size_t index, const sol::table& table);
sol::table at(size_t index) const;
sol::table at(std::string_view name) const;
size_t remove(size_t index);
size_t remove(std::string_view name);
2023-01-13 20:14:23 +00:00
size_t indexOf(const sol::table& table) const;
static int64_t getInstanceCount() { return sInstanceCount; }
2021-11-18 15:19:54 +00:00
private:
std::map<std::string, size_t, std::less<>> mNamed;
std::vector<sol::table> mOrdered;
2023-01-13 20:14:23 +00:00
static int64_t sInstanceCount; // debug information, shown in Lua profiler
2021-11-18 15:19:54 +00:00
};
}
#endif // COMPONENTS_LUAUI_CONTENT