2012-11-15 00:39:56 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2014-08-25 16:56:13 +02:00
|
|
|
struct vfsStream;
|
|
|
|
|
|
2016-01-07 23:12:33 +01:00
|
|
|
namespace psf
|
2016-01-07 20:22:36 +01:00
|
|
|
{
|
2016-01-07 23:12:33 +01:00
|
|
|
enum class entry_format : u16
|
2015-04-16 01:17:42 +02:00
|
|
|
{
|
2016-01-07 23:12:33 +01:00
|
|
|
unknown = 0,
|
|
|
|
|
string_not_null_term = 0x0004,
|
|
|
|
|
string = 0x0204,
|
|
|
|
|
integer = 0x0404,
|
|
|
|
|
};
|
2015-04-16 01:17:42 +02:00
|
|
|
|
2016-01-07 23:12:33 +01:00
|
|
|
struct header
|
2016-01-07 20:22:36 +01:00
|
|
|
{
|
2016-01-07 23:12:33 +01:00
|
|
|
u32 magic;
|
|
|
|
|
u32 version;
|
|
|
|
|
u32 off_key_table;
|
|
|
|
|
u32 off_data_table;
|
|
|
|
|
u32 entries_num;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct def_table
|
2016-01-07 20:22:36 +01:00
|
|
|
{
|
2016-01-07 23:12:33 +01:00
|
|
|
u16 key_off;
|
|
|
|
|
entry_format param_fmt;
|
|
|
|
|
u32 param_len;
|
|
|
|
|
u32 param_max;
|
|
|
|
|
u32 data_off;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class entry
|
2016-01-07 20:22:36 +01:00
|
|
|
{
|
2016-01-07 23:12:33 +01:00
|
|
|
entry_format m_format = entry_format::unknown;
|
|
|
|
|
u32 m_max_size = 0;
|
|
|
|
|
|
|
|
|
|
u32 m_value_integer;
|
|
|
|
|
std::string m_value_string;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
u32 max_size() const;
|
|
|
|
|
entry& max_size(u32 value);
|
|
|
|
|
entry_format format() const;
|
|
|
|
|
entry& format(entry_format value);
|
|
|
|
|
std::string as_string() const;
|
|
|
|
|
u32 as_integer() const;
|
|
|
|
|
std::string to_string() const;
|
|
|
|
|
u32 to_integer() const;
|
|
|
|
|
entry& value(const std::string &value_);
|
|
|
|
|
entry& value(u32 value_);
|
|
|
|
|
entry& operator = (const std::string &value_);
|
|
|
|
|
entry& operator = (u32 value_);
|
|
|
|
|
|
|
|
|
|
std::size_t size() const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class object
|
2016-01-07 20:22:36 +01:00
|
|
|
{
|
2016-01-07 23:12:33 +01:00
|
|
|
std::unordered_map<std::string, entry> m_entries;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
object() = default;
|
|
|
|
|
|
|
|
|
|
object(vfsStream& stream)
|
|
|
|
|
{
|
|
|
|
|
load(stream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual ~object() = default;
|
|
|
|
|
|
|
|
|
|
bool load(vfsStream& stream);
|
|
|
|
|
bool save(vfsStream& stream) const;
|
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
|
|
explicit operator bool() const
|
|
|
|
|
{
|
|
|
|
|
return !m_entries.empty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entry& operator[](const std::string &key);
|
|
|
|
|
const entry& operator[](const std::string &key) const;
|
|
|
|
|
|
2016-01-08 00:07:55 +01:00
|
|
|
//returns pointer to entry or null, if not exists
|
|
|
|
|
const entry *get(const std::string &key) const;
|
|
|
|
|
|
2016-01-07 23:12:33 +01:00
|
|
|
bool exists(const std::string &key) const
|
|
|
|
|
{
|
|
|
|
|
return m_entries.find(key) != m_entries.end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unordered_map<std::string, entry>& entries()
|
|
|
|
|
{
|
|
|
|
|
return m_entries;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::unordered_map<std::string, entry>& entries() const
|
|
|
|
|
{
|
|
|
|
|
return m_entries;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unordered_map<std::string, entry>::iterator begin()
|
|
|
|
|
{
|
|
|
|
|
return m_entries.begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unordered_map<std::string, entry>::iterator end()
|
|
|
|
|
{
|
|
|
|
|
return m_entries.end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unordered_map<std::string, entry>::const_iterator begin() const
|
|
|
|
|
{
|
|
|
|
|
return m_entries.begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unordered_map<std::string, entry>::const_iterator end() const
|
|
|
|
|
{
|
|
|
|
|
return m_entries.end();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|