amxmodx/amxmodx/CVault.h

74 lines
1.6 KiB
C
Raw Normal View History

2014-08-04 08:36:20 +00:00
// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
2004-01-31 20:56:22 +00:00
#ifndef VAULT_CUSTOM_H
#define VAULT_CUSTOM_H
#include "CString.h"
2004-01-31 20:56:22 +00:00
#include "CList.h"
// *****************************************************
// class Vault
// *****************************************************
class Vault
{
2005-09-10 00:38:42 +00:00
struct Obj
{
String key;
String value;
2005-09-16 23:48:51 +00:00
2005-09-10 00:38:42 +00:00
int number;
Obj *next;
Obj(const char* k, const char* v);
} *head;
2004-01-31 20:56:22 +00:00
2005-09-10 00:38:42 +00:00
String path;
2004-01-31 20:56:22 +00:00
2005-09-10 00:38:42 +00:00
Obj** find(const char* n);
2004-01-31 20:56:22 +00:00
public:
2005-09-16 23:48:51 +00:00
Vault() { head = 0; }
~Vault() { clear(); }
2004-01-31 20:56:22 +00:00
// Interface
2005-09-10 00:38:42 +00:00
bool exists(const char* k);
2005-09-16 23:48:51 +00:00
2005-09-10 00:38:42 +00:00
void put(const char* k, const char* v);
void remove(const char* k);
2005-09-16 23:48:51 +00:00
2005-09-10 00:38:42 +00:00
const char* get(const char* n);
int get_number(const char* n);
void setSource(const char* n);
2005-09-16 23:48:51 +00:00
2005-09-10 00:38:42 +00:00
bool loadVault();
bool saveVault();
2005-09-16 23:48:51 +00:00
2005-09-10 00:38:42 +00:00
void clear();
class iterator
{
Obj * a;
public:
iterator(Obj* aa) : a(aa) {}
iterator& operator++() { if (a) a = a->next; return *this; }
bool operator==(const iterator& b) const { return a == b.a; }
bool operator!=(const iterator& b) const { return !operator==(b); }
String& key() const { return a->key; }
String& value() const { return a->value; }
};
inline iterator begin() const { return iterator(head); }
inline iterator end() const { return iterator(0); }
2004-01-31 20:56:22 +00:00
};
2005-09-10 00:38:42 +00:00
#endif //VAULT_CUSTOM_H