69 lines
1.2 KiB
C
69 lines
1.2 KiB
C
|
#pragma once
|
|||
|
|
|||
|
#ifdef WIN32
|
|||
|
#include <Windows.h>
|
|||
|
#else
|
|||
|
#include <string.h>
|
|||
|
#define stricmp strcasecmp
|
|||
|
#endif
|
|||
|
|
|||
|
#include <vector>
|
|||
|
#include <string>
|
|||
|
#include <algorithm>
|
|||
|
|
|||
|
class simple_ini
|
|||
|
{
|
|||
|
typedef struct _key_val
|
|||
|
{
|
|||
|
std::string key;
|
|||
|
std::string val;
|
|||
|
|
|||
|
bool operator==(const char* k)
|
|||
|
{
|
|||
|
return key == k;
|
|||
|
}
|
|||
|
bool operator<(const struct _key_val& r)
|
|||
|
{
|
|||
|
return key.compare(r.key) < 0;
|
|||
|
}
|
|||
|
}KEYVAL;
|
|||
|
typedef struct _sec_key
|
|||
|
{
|
|||
|
std::string sec;
|
|||
|
std::vector<KEYVAL> vals;
|
|||
|
bool operator==(const char* s)
|
|||
|
{
|
|||
|
return sec == s;
|
|||
|
}
|
|||
|
bool operator<(const struct _sec_key& r)
|
|||
|
{
|
|||
|
return sec.compare(r.sec) < 0;
|
|||
|
}
|
|||
|
}SECKEY;
|
|||
|
std::vector<SECKEY> values_;
|
|||
|
|
|||
|
#ifdef WIN32
|
|||
|
std::string file_;
|
|||
|
#endif
|
|||
|
|
|||
|
public:
|
|||
|
simple_ini();
|
|||
|
~simple_ini();
|
|||
|
|
|||
|
static std::string temporary_path(void);
|
|||
|
static bool skip_empty(char*& ptr);
|
|||
|
static void trime(char*& ptr);
|
|||
|
|
|||
|
public:
|
|||
|
int load(const char* local_file);
|
|||
|
#ifndef WIN32
|
|||
|
int save(const char* local_file);
|
|||
|
#endif
|
|||
|
|
|||
|
std::string get(const char* sec, const char* key, const char* default_val = "");
|
|||
|
void set(const char* sec, const char* key, const char* val);
|
|||
|
void remove(const char* sec, const char* key);
|
|||
|
void remove(const char* sec);
|
|||
|
void clear(void);
|
|||
|
};
|