mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 02:27:40 -04:00
Fix line endings and tabs
This commit is contained in:
@ -1,20 +1,20 @@
|
||||
include_directories("../../CoreLib")
|
||||
|
||||
set(plContainer_SOURCES
|
||||
hsStringTable.cpp
|
||||
plConfigInfo.cpp
|
||||
plConfigInfoLogging.cpp
|
||||
plKeysAndValues.cpp
|
||||
)
|
||||
|
||||
set(plContainer_HEADERS
|
||||
hsStringTable.h
|
||||
plConfigInfo.h
|
||||
plContainer.h
|
||||
plKeysAndValues.h
|
||||
)
|
||||
|
||||
add_library(plContainer STATIC ${plContainer_SOURCES} ${plContainer_HEADERS})
|
||||
|
||||
source_group("Source Files" FILES ${plContainer_SOURCES})
|
||||
source_group("Header Files" FILES ${plContainer_HEADERS})
|
||||
include_directories("../../CoreLib")
|
||||
|
||||
set(plContainer_SOURCES
|
||||
hsStringTable.cpp
|
||||
plConfigInfo.cpp
|
||||
plConfigInfoLogging.cpp
|
||||
plKeysAndValues.cpp
|
||||
)
|
||||
|
||||
set(plContainer_HEADERS
|
||||
hsStringTable.h
|
||||
plConfigInfo.h
|
||||
plContainer.h
|
||||
plKeysAndValues.h
|
||||
)
|
||||
|
||||
add_library(plContainer STATIC ${plContainer_SOURCES} ${plContainer_HEADERS})
|
||||
|
||||
source_group("Source Files" FILES ${plContainer_SOURCES})
|
||||
source_group("Header Files" FILES ${plContainer_HEADERS})
|
||||
|
@ -1,223 +1,223 @@
|
||||
/*==LICENSE==*
|
||||
|
||||
CyanWorlds.com Engine - MMOG client, server and tools
|
||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
or by snail mail at:
|
||||
Cyan Worlds, Inc.
|
||||
14617 N Newport Hwy
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#include "hsStringTable.h"
|
||||
#include <stdlib.h>
|
||||
#if HS_BUILD_FOR_PS2 || __MWERKS__ || HS_BUILD_FOR_UNIX
|
||||
#include <ctype.h>
|
||||
#endif
|
||||
//
|
||||
// hsStringTable
|
||||
//
|
||||
|
||||
hsStringTable::Node::Node(char c) : sib(0), kid(0), chr(c), data(0) {};
|
||||
hsStringTable::Node::~Node() { };
|
||||
void* hsStringTable::Node::GetData() { return data; }
|
||||
void hsStringTable::Node::SetData(void* v) { data = v; }
|
||||
|
||||
hsStringTable::~hsStringTable()
|
||||
{
|
||||
RemoveNode(root.kid);
|
||||
}
|
||||
|
||||
void hsStringTable::Reset()
|
||||
{
|
||||
RemoveNode(root.kid);
|
||||
root.kid = nil;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Find a the Node associated with a given string
|
||||
//
|
||||
hsStringTable::Node* hsStringTable::Find(const char* str)
|
||||
{
|
||||
return (str && *str) ? FindRecur(root.kid, str) : nil;
|
||||
}
|
||||
|
||||
//
|
||||
// Find the unique node matching the given prefix. Returns the node
|
||||
// at the first point where a unique path can not be determined
|
||||
// char* str is filled out with the matching path
|
||||
//
|
||||
hsStringTable::Node* hsStringTable::FindPartial(char* str, Int32 len) const
|
||||
{
|
||||
return (str && *str) ? FindPartialRecur(root.kid, str, len) : nil;
|
||||
}
|
||||
|
||||
//
|
||||
// Find and Add if needs a node for str and register it with data
|
||||
//
|
||||
void hsStringTable::Register(const char* str, void* data)
|
||||
{
|
||||
Node* node = FindRecur(root.kid, str, true);
|
||||
if (!node)
|
||||
{
|
||||
node = AddRecur(&root, str);
|
||||
}
|
||||
node->SetData(data);
|
||||
}
|
||||
|
||||
//
|
||||
// Iterate through the tree and call the callback function on each child node
|
||||
// of the fromNode (or the root if fromNode is nil)
|
||||
//
|
||||
hsBool hsStringTable::Iterate(hsStringTableCallback* callback, Node* fromNode)
|
||||
{
|
||||
if (!fromNode)
|
||||
fromNode = &root;
|
||||
return IterateRecur(fromNode->kid,callback);
|
||||
}
|
||||
|
||||
//
|
||||
// Recursively find node, create if needed?
|
||||
//
|
||||
hsStringTable::Node* hsStringTable::FindRecur(Node* root, const char* str, hsBool createIfNeeded)
|
||||
{
|
||||
if (!root || !str) return nil;
|
||||
if (tolower(root->chr)==tolower(*str))
|
||||
{
|
||||
if (*(str+1))
|
||||
{
|
||||
Node* node = FindRecur(root->kid, str+1, createIfNeeded);
|
||||
if (!node && createIfNeeded) node = AddRecur(root, str+1);
|
||||
return node;
|
||||
}
|
||||
else
|
||||
{
|
||||
return root;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return FindRecur(root->sib,str,createIfNeeded);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Recursively find the unique partial match
|
||||
//
|
||||
hsStringTable::Node* hsStringTable::FindPartialRecur(Node* root, char* str, Int32 len) const
|
||||
{
|
||||
if (!root || !str)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (tolower(root->chr)==tolower(*str))
|
||||
{
|
||||
if (len)
|
||||
{
|
||||
*str = root->chr;
|
||||
}
|
||||
|
||||
if (*(str+1))
|
||||
{
|
||||
Node* node = FindPartialRecur(root->kid,str+1,len-1);
|
||||
//if (!node) node = AddRecur(root,str+1);
|
||||
return node;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FindLeafRecur(root, str, len);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return FindPartialRecur(root->sib, str, len);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Follow the current node as far as possible towards a unique leaf
|
||||
//
|
||||
hsStringTable::Node* hsStringTable::FindLeafRecur(Node* root, char* str, Int32 len) const
|
||||
{
|
||||
if (root->data || !root->kid || root->kid->sib)
|
||||
{
|
||||
if (len)
|
||||
{
|
||||
*(str+1) = 0;
|
||||
}
|
||||
return root;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (len)
|
||||
{
|
||||
*(str+1) = len>1 ? root->kid->chr : 0;
|
||||
}
|
||||
return FindLeafRecur(root->kid,str+1,len-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Add a string to the tree
|
||||
//
|
||||
hsStringTable::Node* hsStringTable::AddRecur(Node* root, const char* str)
|
||||
{
|
||||
Node* node = TRACKED_NEW Node(*str);
|
||||
node->sib = root->kid;
|
||||
root->kid = node;
|
||||
if (*(str+1)) return AddRecur(node,str+1);
|
||||
else return node;
|
||||
}
|
||||
|
||||
//
|
||||
// Remove a node recursive from the tree
|
||||
//
|
||||
void hsStringTable::RemoveNode(Node* root)
|
||||
{
|
||||
if (!root) return;
|
||||
RemoveNode(root->kid);
|
||||
RemoveNode(root->sib);
|
||||
delete root;
|
||||
}
|
||||
|
||||
//
|
||||
// Recurse through tree and call callback on each node
|
||||
//
|
||||
hsBool hsStringTable::IterateRecur(Node* root, hsStringTableCallback* callback)
|
||||
{
|
||||
if (!root)
|
||||
return true;
|
||||
if (root->data)
|
||||
{
|
||||
if (!callback(root))
|
||||
return false;
|
||||
}
|
||||
if (root->kid)
|
||||
{
|
||||
if (!IterateRecur(root->kid,callback))
|
||||
return false;
|
||||
}
|
||||
if (root->sib)
|
||||
{
|
||||
if (!IterateRecur(root->sib,callback))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*==LICENSE==*
|
||||
|
||||
CyanWorlds.com Engine - MMOG client, server and tools
|
||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
or by snail mail at:
|
||||
Cyan Worlds, Inc.
|
||||
14617 N Newport Hwy
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#include "hsStringTable.h"
|
||||
#include <stdlib.h>
|
||||
#if HS_BUILD_FOR_PS2 || __MWERKS__ || HS_BUILD_FOR_UNIX
|
||||
#include <ctype.h>
|
||||
#endif
|
||||
//
|
||||
// hsStringTable
|
||||
//
|
||||
|
||||
hsStringTable::Node::Node(char c) : sib(0), kid(0), chr(c), data(0) {};
|
||||
hsStringTable::Node::~Node() { };
|
||||
void* hsStringTable::Node::GetData() { return data; }
|
||||
void hsStringTable::Node::SetData(void* v) { data = v; }
|
||||
|
||||
hsStringTable::~hsStringTable()
|
||||
{
|
||||
RemoveNode(root.kid);
|
||||
}
|
||||
|
||||
void hsStringTable::Reset()
|
||||
{
|
||||
RemoveNode(root.kid);
|
||||
root.kid = nil;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Find a the Node associated with a given string
|
||||
//
|
||||
hsStringTable::Node* hsStringTable::Find(const char* str)
|
||||
{
|
||||
return (str && *str) ? FindRecur(root.kid, str) : nil;
|
||||
}
|
||||
|
||||
//
|
||||
// Find the unique node matching the given prefix. Returns the node
|
||||
// at the first point where a unique path can not be determined
|
||||
// char* str is filled out with the matching path
|
||||
//
|
||||
hsStringTable::Node* hsStringTable::FindPartial(char* str, Int32 len) const
|
||||
{
|
||||
return (str && *str) ? FindPartialRecur(root.kid, str, len) : nil;
|
||||
}
|
||||
|
||||
//
|
||||
// Find and Add if needs a node for str and register it with data
|
||||
//
|
||||
void hsStringTable::Register(const char* str, void* data)
|
||||
{
|
||||
Node* node = FindRecur(root.kid, str, true);
|
||||
if (!node)
|
||||
{
|
||||
node = AddRecur(&root, str);
|
||||
}
|
||||
node->SetData(data);
|
||||
}
|
||||
|
||||
//
|
||||
// Iterate through the tree and call the callback function on each child node
|
||||
// of the fromNode (or the root if fromNode is nil)
|
||||
//
|
||||
hsBool hsStringTable::Iterate(hsStringTableCallback* callback, Node* fromNode)
|
||||
{
|
||||
if (!fromNode)
|
||||
fromNode = &root;
|
||||
return IterateRecur(fromNode->kid,callback);
|
||||
}
|
||||
|
||||
//
|
||||
// Recursively find node, create if needed?
|
||||
//
|
||||
hsStringTable::Node* hsStringTable::FindRecur(Node* root, const char* str, hsBool createIfNeeded)
|
||||
{
|
||||
if (!root || !str) return nil;
|
||||
if (tolower(root->chr)==tolower(*str))
|
||||
{
|
||||
if (*(str+1))
|
||||
{
|
||||
Node* node = FindRecur(root->kid, str+1, createIfNeeded);
|
||||
if (!node && createIfNeeded) node = AddRecur(root, str+1);
|
||||
return node;
|
||||
}
|
||||
else
|
||||
{
|
||||
return root;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return FindRecur(root->sib,str,createIfNeeded);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Recursively find the unique partial match
|
||||
//
|
||||
hsStringTable::Node* hsStringTable::FindPartialRecur(Node* root, char* str, Int32 len) const
|
||||
{
|
||||
if (!root || !str)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (tolower(root->chr)==tolower(*str))
|
||||
{
|
||||
if (len)
|
||||
{
|
||||
*str = root->chr;
|
||||
}
|
||||
|
||||
if (*(str+1))
|
||||
{
|
||||
Node* node = FindPartialRecur(root->kid,str+1,len-1);
|
||||
//if (!node) node = AddRecur(root,str+1);
|
||||
return node;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FindLeafRecur(root, str, len);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return FindPartialRecur(root->sib, str, len);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Follow the current node as far as possible towards a unique leaf
|
||||
//
|
||||
hsStringTable::Node* hsStringTable::FindLeafRecur(Node* root, char* str, Int32 len) const
|
||||
{
|
||||
if (root->data || !root->kid || root->kid->sib)
|
||||
{
|
||||
if (len)
|
||||
{
|
||||
*(str+1) = 0;
|
||||
}
|
||||
return root;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (len)
|
||||
{
|
||||
*(str+1) = len>1 ? root->kid->chr : 0;
|
||||
}
|
||||
return FindLeafRecur(root->kid,str+1,len-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Add a string to the tree
|
||||
//
|
||||
hsStringTable::Node* hsStringTable::AddRecur(Node* root, const char* str)
|
||||
{
|
||||
Node* node = TRACKED_NEW Node(*str);
|
||||
node->sib = root->kid;
|
||||
root->kid = node;
|
||||
if (*(str+1)) return AddRecur(node,str+1);
|
||||
else return node;
|
||||
}
|
||||
|
||||
//
|
||||
// Remove a node recursive from the tree
|
||||
//
|
||||
void hsStringTable::RemoveNode(Node* root)
|
||||
{
|
||||
if (!root) return;
|
||||
RemoveNode(root->kid);
|
||||
RemoveNode(root->sib);
|
||||
delete root;
|
||||
}
|
||||
|
||||
//
|
||||
// Recurse through tree and call callback on each node
|
||||
//
|
||||
hsBool hsStringTable::IterateRecur(Node* root, hsStringTableCallback* callback)
|
||||
{
|
||||
if (!root)
|
||||
return true;
|
||||
if (root->data)
|
||||
{
|
||||
if (!callback(root))
|
||||
return false;
|
||||
}
|
||||
if (root->kid)
|
||||
{
|
||||
if (!IterateRecur(root->kid,callback))
|
||||
return false;
|
||||
}
|
||||
if (root->sib)
|
||||
{
|
||||
if (!IterateRecur(root->sib,callback))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1,71 +1,71 @@
|
||||
/*==LICENSE==*
|
||||
|
||||
CyanWorlds.com Engine - MMOG client, server and tools
|
||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
or by snail mail at:
|
||||
Cyan Worlds, Inc.
|
||||
14617 N Newport Hwy
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#ifndef HS_STRING_TABLE_H
|
||||
#define HS_STRING_TABLE_H
|
||||
|
||||
#include "HeadSpin.h"
|
||||
|
||||
class hsStringTable
|
||||
{
|
||||
public:
|
||||
class Node {
|
||||
protected:
|
||||
Node(char c=0);
|
||||
~Node();
|
||||
public:
|
||||
void* GetData();
|
||||
void SetData(void* v);
|
||||
friend class hsStringTable;
|
||||
private:
|
||||
Node* sib;
|
||||
Node* kid;
|
||||
char chr;
|
||||
void* data;
|
||||
};
|
||||
|
||||
hsStringTable() {}
|
||||
~hsStringTable();
|
||||
void Reset();
|
||||
Node* Find(const char* str);
|
||||
Node* FindPartial(char* str, Int32 len=0) const;
|
||||
void Register(const char* str, void* data);
|
||||
|
||||
typedef hsBool (hsStringTableCallback)(Node*);
|
||||
hsBool Iterate(hsStringTableCallback* callback, Node* fromNode=nil);
|
||||
private:
|
||||
Node* FindRecur(Node* root, const char* str, hsBool createIfNeeded=false);
|
||||
Node* FindPartialRecur(Node* root, char* str, Int32 len) const;
|
||||
Node* AddRecur(Node* root, const char* str);
|
||||
Node* FindLeafRecur(Node* root, char* str, Int32 len) const;
|
||||
void RemoveNode(Node* root);
|
||||
hsBool IterateRecur(Node* root, hsStringTableCallback* callback);
|
||||
|
||||
Node root;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
/*==LICENSE==*
|
||||
|
||||
CyanWorlds.com Engine - MMOG client, server and tools
|
||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
or by snail mail at:
|
||||
Cyan Worlds, Inc.
|
||||
14617 N Newport Hwy
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#ifndef HS_STRING_TABLE_H
|
||||
#define HS_STRING_TABLE_H
|
||||
|
||||
#include "HeadSpin.h"
|
||||
|
||||
class hsStringTable
|
||||
{
|
||||
public:
|
||||
class Node {
|
||||
protected:
|
||||
Node(char c=0);
|
||||
~Node();
|
||||
public:
|
||||
void* GetData();
|
||||
void SetData(void* v);
|
||||
friend class hsStringTable;
|
||||
private:
|
||||
Node* sib;
|
||||
Node* kid;
|
||||
char chr;
|
||||
void* data;
|
||||
};
|
||||
|
||||
hsStringTable() {}
|
||||
~hsStringTable();
|
||||
void Reset();
|
||||
Node* Find(const char* str);
|
||||
Node* FindPartial(char* str, Int32 len=0) const;
|
||||
void Register(const char* str, void* data);
|
||||
|
||||
typedef hsBool (hsStringTableCallback)(Node*);
|
||||
hsBool Iterate(hsStringTableCallback* callback, Node* fromNode=nil);
|
||||
private:
|
||||
Node* FindRecur(Node* root, const char* str, hsBool createIfNeeded=false);
|
||||
Node* FindPartialRecur(Node* root, char* str, Int32 len) const;
|
||||
Node* AddRecur(Node* root, const char* str);
|
||||
Node* FindLeafRecur(Node* root, char* str, Int32 len) const;
|
||||
void RemoveNode(Node* root);
|
||||
hsBool IterateRecur(Node* root, hsStringTableCallback* callback);
|
||||
|
||||
Node root;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,481 +1,481 @@
|
||||
/*==LICENSE==*
|
||||
|
||||
CyanWorlds.com Engine - MMOG client, server and tools
|
||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
or by snail mail at:
|
||||
Cyan Worlds, Inc.
|
||||
14617 N Newport Hwy
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#ifndef plConfigInfo_h_inc
|
||||
#define plConfigInfo_h_inc
|
||||
|
||||
#include "plKeysAndValues.h"
|
||||
#include "hsStlUtils.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
typedef std::vector<std::string> plStringList;
|
||||
typedef std::vector<std::wstring> plWStringList;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class plConfigSource;
|
||||
class plConfigInfo
|
||||
{
|
||||
public:
|
||||
typedef plKeysAndValues::Keys
|
||||
Keys;
|
||||
typedef plKeysAndValues::Values
|
||||
Values;
|
||||
typedef std::map<xtl::istring, plKeysAndValues>
|
||||
Sections;
|
||||
|
||||
static const std::string& GlobalSection();
|
||||
|
||||
private:
|
||||
mutable Sections fSections;
|
||||
|
||||
public:
|
||||
plConfigInfo();
|
||||
plConfigInfo(const plConfigInfo & src);
|
||||
virtual ~plConfigInfo() {}
|
||||
plConfigInfo & operator =(const plConfigInfo & src);
|
||||
|
||||
// REMOVE
|
||||
// remove all sections
|
||||
void Clear();
|
||||
// remove section
|
||||
void RemoveSection(const std::string & section);
|
||||
// remove key from section
|
||||
void RemoveKey(const std::string & section, const std::string & key);
|
||||
// QUERY
|
||||
// does this section exist?
|
||||
bool HasSection(const std::string & section) const;
|
||||
// does the given section contain this key?
|
||||
bool HasKey(const std::string & section, const std::string & key);
|
||||
// does any section contain this key?
|
||||
bool HasKeyAny(const std::string & key);
|
||||
// does any of the given sections contain this key?
|
||||
bool HasKeyIn(const std::string & key, const char * section1, ... /*, nil*/);
|
||||
bool HasKeyIn(const std::string & key, const std::vector<std::string> & sections );
|
||||
// does key in section have this value?
|
||||
bool KeyHasValue(const std::string & section, const std::string & key, const std::string & value);
|
||||
bool KeyHasValue(const std::string & section, const std::string & key, int value);
|
||||
bool KeyHasValue(const std::string & section, const std::string & key, double value);
|
||||
// ADD
|
||||
// add key=value to the section
|
||||
bool AddValue(const std::string & section, const std::string & key, const std::string & value, KAddValueMode mode=kAlwaysAdd);
|
||||
bool AddValue(const std::string & section, const std::string & key, int value, KAddValueMode mode=kAlwaysAdd);
|
||||
bool AddValue(const std::string & section, const std::string & key, double value, KAddValueMode mode=kAlwaysAdd);
|
||||
bool AddValues(const std::string & section, const std::string & key, const std::vector<std::string> & values, KAddValueMode mode=kAlwaysAdd);
|
||||
// GET
|
||||
plKeysAndValues GetSection(const std::string & section, bool & found);
|
||||
std::vector<std::string> GetSectionNames();
|
||||
// get value for key from given section
|
||||
std::string GetValue(const std::string & section, const std::string & key, const std::string & defval="", bool * outFound=nil) const;
|
||||
int GetValue(const std::string & section, const std::string & key, int defval, bool * outFound=nil) const;
|
||||
double GetValue(const std::string & section, const std::string & key, double defval, bool * outFound=nil) const;
|
||||
std::vector<std::string> GetAllValues(const std::string & section, const std::string & key) const;
|
||||
// get value for key from any section
|
||||
std::string GetValueAny(const std::string & key, const std::string & defval="", bool * outFound=nil) const;
|
||||
int GetValueAny(const std::string & key, int defval, bool * outFound=nil) const;
|
||||
double GetValueAny(const std::string & key, double defval, bool * outFound=nil) const;
|
||||
std::vector<std::string> GetAllValuesAny(const std::string & key) const;
|
||||
// get value for key from one of the given sections
|
||||
std::string GetValueIn(const std::string & key, const std::string & defval, bool * outFound, const char * section1, ... /*, nil*/) const;
|
||||
std::string GetValueIn(const std::string & key, const std::string & defval, bool * outFound, const std::vector<std::string> & sections ) const;
|
||||
int GetValueIn(const std::string & key, int defval, bool * outFound, const char * section1, ... /*, nil*/) const;
|
||||
int GetValueIn(const std::string & key, int defval, bool * outFound, const std::vector<std::string> & sections ) const;
|
||||
double GetValueIn(const std::string & key, double defval, bool * outFound, const char * section1, ... /*, nil*/) const;
|
||||
double GetValueIn(const std::string & key, double defval, bool * outFound, const std::vector<std::string> & sections ) const;
|
||||
std::vector<std::string> GetAllValuesIn(const std::string & key, const char * section1, ... /*, nil*/);
|
||||
// ITERATORS
|
||||
bool GetSectionIterators(Sections::const_iterator & iter, Sections::const_iterator & end) const;
|
||||
bool GetKeyIterators(const xtl::istring & section, Keys::const_iterator & iter, Keys::const_iterator & end) const;
|
||||
bool GetValueIterators(const xtl::istring & section, const xtl::istring & key, Values::const_iterator & iter, Values::const_iterator & end) const;
|
||||
// CONFIG SOURCE
|
||||
virtual bool ReadFrom(plConfigSource * src, KAddValueMode mode=kAlwaysAdd);
|
||||
virtual bool WriteTo(plConfigSource * src);
|
||||
};
|
||||
|
||||
class plConfigInfoLogging
|
||||
{
|
||||
private:
|
||||
plConfigInfo fConfigInfo;
|
||||
|
||||
plConfigInfo fLog;
|
||||
public:
|
||||
plConfigInfoLogging();
|
||||
~plConfigInfoLogging();
|
||||
|
||||
plConfigInfo* GetConfigInfo() { return &fConfigInfo; }
|
||||
plConfigInfo* GetConfigInfoLog() { return &fLog; }
|
||||
|
||||
bool GetValue(std::string& retval, const std::string & section, const std::string & key, const std::string & desc, const std::string& defval = "");
|
||||
bool GetValue(int& retval, const std::string & section, const std::string & key, const std::string & desc, int defval);
|
||||
bool GetValue(bool& retval, const std::string & section, const std::string & key, const std::string & desc, bool defval);
|
||||
bool GetValue(float& retval, const std::string & section, const std::string & key, const std::string & desc, float defval);
|
||||
bool GetValue(double& retval, const std::string & section, const std::string & key, const std::string & desc, double defval);
|
||||
bool GetAllValues(std::vector<std::string>& values, const std::string & section, const std::string & key, const std::string & desc);
|
||||
|
||||
#if USE_MULT_SECTIONS
|
||||
// get value for key from any section
|
||||
bool GetValueAny(std::string& retval, const std::string & key, const std::string & desc, const std::string & defval);
|
||||
bool GetValueAny(int &retval, const std::string & key, const std::string & desc, int defval);
|
||||
bool GetValueAny(bool& retval, const std::string & key, const std::string & desc, bool defval);
|
||||
bool GetValueAny(float& retval, const std::string & key, const std::string & desc, float defval);
|
||||
bool GetValueAny(double& retval, const std::string & key, const std::string & desc, double defval);
|
||||
bool GetAllValuesAny(std::vector<std::string>& values, const std::string & key, const std::string & desc);
|
||||
|
||||
// get value for key from one of the given sections
|
||||
bool GetValueIn(std::string& retval, const std::string & key, const std::string & desc, const std::string & defval, const char * section1, ... /*, nil*/);
|
||||
bool GetValueIn(std::string& retval, const std::string & key, const std::string & desc, const std::string & defval, std::vector<std::string> & sections );
|
||||
bool GetValueIn(int& retval, const std::string & key, const std::string & desc, int defval, const char * section1, ... /*, nil*/);
|
||||
bool GetValueIn(int& retval, const std::string & key, const std::string & desc, int defval, std::vector<std::string> & sections );
|
||||
bool GetValueIn(bool& retval, const std::string & key, const std::string & desc, bool defval, const char * section1, ... /*, nil*/);
|
||||
bool GetValueIn(bool& retval, const std::string & key, const std::string & desc, bool defval, std::vector<std::string> & sections );
|
||||
bool GetValueIn(float& retval, const std::string & key, const std::string & desc, double defval, const char * section1, ... /*, nil*/);
|
||||
bool GetValueIn(float& retval, const std::string & key, const std::string & desc, double defval, std::vector<std::string> & sections );
|
||||
bool GetValueIn(double& retval, const std::string & key, const std::string & desc, double defval, const char * section1, ... /*, nil*/);
|
||||
bool GetValueIn(double& retval, const std::string & key, const std::string & desc, double defval, std::vector<std::string> & sections );
|
||||
#endif
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class plConfigSource
|
||||
{
|
||||
protected:
|
||||
std::string fCurrSection; // used in parsing
|
||||
std::string fEffectiveSection; // used in parsing
|
||||
KAddValueMode fAddMode; // used in parsing
|
||||
plConfigInfo * fConfigInfo;
|
||||
|
||||
void SplitAt(std::string & key, std::string & value, char splitter, std::string & in);
|
||||
virtual bool ReadString(const std::string & in);
|
||||
virtual bool ReadPair(std::string & key, std::string & value);
|
||||
virtual bool ReadList(char ** list);
|
||||
virtual bool ReadSubSource( const char * name ) { return true; }
|
||||
|
||||
protected:
|
||||
virtual bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd);
|
||||
virtual bool WriteOutOf(plConfigInfo & configInfo);
|
||||
|
||||
public:
|
||||
plConfigSource() {}
|
||||
virtual ~plConfigSource() {}
|
||||
|
||||
friend class plConfigInfo;
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class plCmdLineConfigSource : public plConfigSource
|
||||
{
|
||||
int fArgc;
|
||||
char ** fArgv;
|
||||
std::string fMySection;
|
||||
protected:
|
||||
bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd);
|
||||
public:
|
||||
plCmdLineConfigSource(int argc, char ** argv, const char * mySection="CmdLine");
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class plEnvConfigSource : public plConfigSource
|
||||
{
|
||||
char ** fEnvp;
|
||||
std::string fMySection;
|
||||
protected:
|
||||
bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd);
|
||||
public:
|
||||
plEnvConfigSource(char ** envp, const char * mySection="Environment");
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class plIniConfigSource : public plConfigSource
|
||||
{
|
||||
protected:
|
||||
std::string fFileName;
|
||||
bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd);
|
||||
bool WriteOutOf(plConfigInfo & configInfo);
|
||||
public:
|
||||
plIniConfigSource(const char * iniFileName);
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// just like above, but works with hsStream-derived classes
|
||||
|
||||
class hsStream;
|
||||
class plIniStreamConfigSource : public plConfigSource
|
||||
{
|
||||
protected:
|
||||
hsStream * fStream;
|
||||
bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd);
|
||||
bool WriteOutOf(plConfigInfo & configInfo);
|
||||
public:
|
||||
plIniStreamConfigSource(hsStream * stream);
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
// an ini file reader/writer that ignores section headers and puts all
|
||||
// data in an unnamed section, or more accurately, in a section named "".
|
||||
class plIniNoSectionsConfigSource : public plConfigSource
|
||||
{
|
||||
std::string fFileName;
|
||||
protected:
|
||||
bool ReadString(const std::string & in);
|
||||
bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd);
|
||||
bool WriteOutOf(plConfigInfo & configInfo);
|
||||
public:
|
||||
plIniNoSectionsConfigSource(const char * iniFileName);
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
// an ini file reader that only reads specified sections
|
||||
class plIniSectionConfigSource : public plIniConfigSource
|
||||
{
|
||||
typedef std::vector<xtl::istring>
|
||||
Sections;
|
||||
protected:
|
||||
Sections fSections;
|
||||
bool ReadPair(std::string & key, std::string & value);
|
||||
bool ReadSubSource( const char * name );
|
||||
public:
|
||||
plIniSectionConfigSource(const char * iniFileName, std::vector<std::string> & sections);
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
// TODO: This would be a cool thing. not needed right now though.
|
||||
class plDatabaseConfigSource : public plConfigSource
|
||||
{
|
||||
protected:
|
||||
bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd);
|
||||
bool WriteOutOf(plConfigInfo & configInfo);
|
||||
public:
|
||||
plDatabaseConfigSource(const char * connectString);
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class plDebugConfigSource : public plConfigSource
|
||||
{
|
||||
protected:
|
||||
std::string fFileName;
|
||||
bool WriteOutOf(plConfigInfo & configInfo);
|
||||
public:
|
||||
plDebugConfigSource(){}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class plWWWAuthenticateConfigSource : public plConfigSource
|
||||
{
|
||||
const std::string& fAuth;
|
||||
protected:
|
||||
bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd);
|
||||
public:
|
||||
plWWWAuthenticateConfigSource(const std::string& auth);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
// NOTE: plClass _must_ appear first in a multiple-inheritance list.
|
||||
class plClass
|
||||
{
|
||||
public:
|
||||
virtual void Unused(){}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef bool (plClass::*TEvaluate)();
|
||||
typedef bool (plClass::*TEvaluateConst)() const;
|
||||
struct plEvaluate
|
||||
{
|
||||
plClass * fTarget;
|
||||
bool (plClass::*fEvaluate)();
|
||||
bool (plClass::*fEvaluateConst)() const;
|
||||
plEvaluate( plClass * target=nil, TEvaluate evaluate=nil )
|
||||
: fTarget(target)
|
||||
, fEvaluate(evaluate)
|
||||
, fEvaluateConst(nil)
|
||||
{}
|
||||
plEvaluate( plClass * target, TEvaluateConst evaluate )
|
||||
: fTarget(target)
|
||||
, fEvaluateConst(evaluate)
|
||||
, fEvaluate(nil)
|
||||
{}
|
||||
bool operator()()
|
||||
{
|
||||
if (fEvaluate)
|
||||
return (fTarget)?(fTarget->*fEvaluate)():true;
|
||||
else
|
||||
if (fEvaluateConst)
|
||||
return (fTarget)?(fTarget->*fEvaluateConst)():true;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef std::string (plClass::*TModify)(const std::string & value);
|
||||
|
||||
struct plModify
|
||||
{
|
||||
plClass * fTarget;
|
||||
std::string (plClass::*fModify)(const std::string & value);
|
||||
plModify( plClass * target=nil, TModify modify=nil )
|
||||
: fTarget(target)
|
||||
, fModify(modify)
|
||||
{}
|
||||
std::string operator()(const std::string & value) { return (fTarget)?(fTarget->*fModify)(value):value;}
|
||||
std::string operator()(const std::string & value) const { return (fTarget)?(fTarget->*fModify)(value):value;}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
class plConfigValueBase
|
||||
{
|
||||
public:
|
||||
std::string fConfigName;
|
||||
std::string fConfigGroup;
|
||||
plEvaluate fReadEvaluate; // returns true if we want to read this value from options
|
||||
plEvaluate fWriteEvaluate; // returns true if we want to write this value to options
|
||||
plModify fReadModify; // may modify the value being read from options
|
||||
plModify fWriteModify; // may modify the value being written to options
|
||||
plModify fGetModify; // may modify the value when being assigned
|
||||
plModify fSetModify; // may modify the value when being accessed
|
||||
plConfigValueBase( const char * configName="", const char * configGroup="" )
|
||||
: fConfigName(configName)
|
||||
, fConfigGroup(configGroup)
|
||||
{}
|
||||
void SetConfigName(const char * name) { fConfigName=(name)?name:"";}
|
||||
std::string GetConfigName() const { return fConfigName;}
|
||||
void SetConfigGroup(const char * group) { fConfigGroup=group;}
|
||||
std::string GetConfigGroup() const { return fConfigGroup;}
|
||||
bool HasConfigName() { return fConfigName.length()>0;}
|
||||
bool HasConfigGroup() { return fConfigGroup.length()>0;}
|
||||
virtual void ConfigRead(plConfigInfo * opts);
|
||||
virtual void ConfigWrite(plConfigInfo * opts);
|
||||
void SetValue(const char * value);
|
||||
std::string GetValue() const;
|
||||
virtual void ISetValue(const char * value) = 0;
|
||||
virtual std::string IGetValue() const = 0;
|
||||
|
||||
void SetReadEvaluate(plClass * targetObj, TEvaluate evalFunc);
|
||||
void SetWriteEvaluate(plClass * targetObj, TEvaluate evalFunc);
|
||||
void SetWriteEvaluate(plClass * targetObj, TEvaluateConst evalFunc);
|
||||
void SetReadModify(plClass * targetObj, TModify modifyFunc);
|
||||
void SetWriteModify(plClass * targetObj, TModify modifyFunc);
|
||||
void SetGetModify(plClass * targetObj, TModify modifyFunc);
|
||||
void SetSetModify(plClass * targetObj, TModify modifyFunc);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
class plConfigValue : public plConfigValueBase
|
||||
{
|
||||
public:
|
||||
plConfigValue( const char * configName="", const char * configGroup="" )
|
||||
: plConfigValueBase(configName, configGroup)
|
||||
{}
|
||||
std::string fConfigValue;
|
||||
void ISetValue(const char * value) { fConfigValue=value;}
|
||||
std::string IGetValue() const { return fConfigValue;}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
class plConfigAggregateValue : public plConfigValueBase
|
||||
{
|
||||
public:
|
||||
std::vector<plConfigValueBase*> fItems;
|
||||
plConfigAggregateValue(
|
||||
const char * name=nil,
|
||||
// A vararg here would not work because of a
|
||||
// multiple inheritance issue. Classes that are
|
||||
// plConfigValueBase are likely to be derived from
|
||||
// plClass also. Since plClass must be first in
|
||||
// the inheritance list, the vararg would not
|
||||
// point to the plConfigValueBase vtable that we
|
||||
// need to access.
|
||||
plConfigValueBase * item1=nil,
|
||||
plConfigValueBase * item2=nil,
|
||||
plConfigValueBase * item3=nil,
|
||||
plConfigValueBase * item4=nil,
|
||||
plConfigValueBase * item5=nil,
|
||||
plConfigValueBase * item6=nil,
|
||||
plConfigValueBase * item7=nil);
|
||||
void ISetValue(const char * value);
|
||||
std::string IGetValue() const;
|
||||
void AddItem(plConfigValueBase * item);
|
||||
void AddItems(
|
||||
plConfigValueBase * item1=nil,
|
||||
plConfigValueBase * item2=nil,
|
||||
plConfigValueBase * item3=nil,
|
||||
plConfigValueBase * item4=nil,
|
||||
plConfigValueBase * item5=nil,
|
||||
plConfigValueBase * item6=nil,
|
||||
plConfigValueBase * item7=nil);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
class plConfigValueProxy : public plConfigValueBase
|
||||
{
|
||||
plConfigValueBase * fConfigurable;
|
||||
public:
|
||||
plConfigValueProxy(plConfigValueBase * item=nil)
|
||||
: fConfigurable(item)
|
||||
{}
|
||||
void Set(plConfigValueBase * item) { fConfigurable=item;}
|
||||
void ISetValue(const char * value) { fConfigurable->ISetValue(value);}
|
||||
std::string IGetValue() const { return fConfigurable->IGetValue();}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
class plConfigGroup
|
||||
{
|
||||
public:
|
||||
plConfigInfo fOpts;
|
||||
std::string fGroupName;
|
||||
std::vector<plConfigValueBase*> fItems;
|
||||
plConfigGroup(const char * groupName="");
|
||||
bool Read(plConfigSource * src);
|
||||
bool Write(plConfigSource * src);
|
||||
void AddItem(plConfigValueBase * item, const char * name=nil);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // plConfigInfo_h_inc
|
||||
/*==LICENSE==*
|
||||
|
||||
CyanWorlds.com Engine - MMOG client, server and tools
|
||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
or by snail mail at:
|
||||
Cyan Worlds, Inc.
|
||||
14617 N Newport Hwy
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#ifndef plConfigInfo_h_inc
|
||||
#define plConfigInfo_h_inc
|
||||
|
||||
#include "plKeysAndValues.h"
|
||||
#include "hsStlUtils.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
typedef std::vector<std::string> plStringList;
|
||||
typedef std::vector<std::wstring> plWStringList;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class plConfigSource;
|
||||
class plConfigInfo
|
||||
{
|
||||
public:
|
||||
typedef plKeysAndValues::Keys
|
||||
Keys;
|
||||
typedef plKeysAndValues::Values
|
||||
Values;
|
||||
typedef std::map<xtl::istring, plKeysAndValues>
|
||||
Sections;
|
||||
|
||||
static const std::string& GlobalSection();
|
||||
|
||||
private:
|
||||
mutable Sections fSections;
|
||||
|
||||
public:
|
||||
plConfigInfo();
|
||||
plConfigInfo(const plConfigInfo & src);
|
||||
virtual ~plConfigInfo() {}
|
||||
plConfigInfo & operator =(const plConfigInfo & src);
|
||||
|
||||
// REMOVE
|
||||
// remove all sections
|
||||
void Clear();
|
||||
// remove section
|
||||
void RemoveSection(const std::string & section);
|
||||
// remove key from section
|
||||
void RemoveKey(const std::string & section, const std::string & key);
|
||||
// QUERY
|
||||
// does this section exist?
|
||||
bool HasSection(const std::string & section) const;
|
||||
// does the given section contain this key?
|
||||
bool HasKey(const std::string & section, const std::string & key);
|
||||
// does any section contain this key?
|
||||
bool HasKeyAny(const std::string & key);
|
||||
// does any of the given sections contain this key?
|
||||
bool HasKeyIn(const std::string & key, const char * section1, ... /*, nil*/);
|
||||
bool HasKeyIn(const std::string & key, const std::vector<std::string> & sections );
|
||||
// does key in section have this value?
|
||||
bool KeyHasValue(const std::string & section, const std::string & key, const std::string & value);
|
||||
bool KeyHasValue(const std::string & section, const std::string & key, int value);
|
||||
bool KeyHasValue(const std::string & section, const std::string & key, double value);
|
||||
// ADD
|
||||
// add key=value to the section
|
||||
bool AddValue(const std::string & section, const std::string & key, const std::string & value, KAddValueMode mode=kAlwaysAdd);
|
||||
bool AddValue(const std::string & section, const std::string & key, int value, KAddValueMode mode=kAlwaysAdd);
|
||||
bool AddValue(const std::string & section, const std::string & key, double value, KAddValueMode mode=kAlwaysAdd);
|
||||
bool AddValues(const std::string & section, const std::string & key, const std::vector<std::string> & values, KAddValueMode mode=kAlwaysAdd);
|
||||
// GET
|
||||
plKeysAndValues GetSection(const std::string & section, bool & found);
|
||||
std::vector<std::string> GetSectionNames();
|
||||
// get value for key from given section
|
||||
std::string GetValue(const std::string & section, const std::string & key, const std::string & defval="", bool * outFound=nil) const;
|
||||
int GetValue(const std::string & section, const std::string & key, int defval, bool * outFound=nil) const;
|
||||
double GetValue(const std::string & section, const std::string & key, double defval, bool * outFound=nil) const;
|
||||
std::vector<std::string> GetAllValues(const std::string & section, const std::string & key) const;
|
||||
// get value for key from any section
|
||||
std::string GetValueAny(const std::string & key, const std::string & defval="", bool * outFound=nil) const;
|
||||
int GetValueAny(const std::string & key, int defval, bool * outFound=nil) const;
|
||||
double GetValueAny(const std::string & key, double defval, bool * outFound=nil) const;
|
||||
std::vector<std::string> GetAllValuesAny(const std::string & key) const;
|
||||
// get value for key from one of the given sections
|
||||
std::string GetValueIn(const std::string & key, const std::string & defval, bool * outFound, const char * section1, ... /*, nil*/) const;
|
||||
std::string GetValueIn(const std::string & key, const std::string & defval, bool * outFound, const std::vector<std::string> & sections ) const;
|
||||
int GetValueIn(const std::string & key, int defval, bool * outFound, const char * section1, ... /*, nil*/) const;
|
||||
int GetValueIn(const std::string & key, int defval, bool * outFound, const std::vector<std::string> & sections ) const;
|
||||
double GetValueIn(const std::string & key, double defval, bool * outFound, const char * section1, ... /*, nil*/) const;
|
||||
double GetValueIn(const std::string & key, double defval, bool * outFound, const std::vector<std::string> & sections ) const;
|
||||
std::vector<std::string> GetAllValuesIn(const std::string & key, const char * section1, ... /*, nil*/);
|
||||
// ITERATORS
|
||||
bool GetSectionIterators(Sections::const_iterator & iter, Sections::const_iterator & end) const;
|
||||
bool GetKeyIterators(const xtl::istring & section, Keys::const_iterator & iter, Keys::const_iterator & end) const;
|
||||
bool GetValueIterators(const xtl::istring & section, const xtl::istring & key, Values::const_iterator & iter, Values::const_iterator & end) const;
|
||||
// CONFIG SOURCE
|
||||
virtual bool ReadFrom(plConfigSource * src, KAddValueMode mode=kAlwaysAdd);
|
||||
virtual bool WriteTo(plConfigSource * src);
|
||||
};
|
||||
|
||||
class plConfigInfoLogging
|
||||
{
|
||||
private:
|
||||
plConfigInfo fConfigInfo;
|
||||
|
||||
plConfigInfo fLog;
|
||||
public:
|
||||
plConfigInfoLogging();
|
||||
~plConfigInfoLogging();
|
||||
|
||||
plConfigInfo* GetConfigInfo() { return &fConfigInfo; }
|
||||
plConfigInfo* GetConfigInfoLog() { return &fLog; }
|
||||
|
||||
bool GetValue(std::string& retval, const std::string & section, const std::string & key, const std::string & desc, const std::string& defval = "");
|
||||
bool GetValue(int& retval, const std::string & section, const std::string & key, const std::string & desc, int defval);
|
||||
bool GetValue(bool& retval, const std::string & section, const std::string & key, const std::string & desc, bool defval);
|
||||
bool GetValue(float& retval, const std::string & section, const std::string & key, const std::string & desc, float defval);
|
||||
bool GetValue(double& retval, const std::string & section, const std::string & key, const std::string & desc, double defval);
|
||||
bool GetAllValues(std::vector<std::string>& values, const std::string & section, const std::string & key, const std::string & desc);
|
||||
|
||||
#if USE_MULT_SECTIONS
|
||||
// get value for key from any section
|
||||
bool GetValueAny(std::string& retval, const std::string & key, const std::string & desc, const std::string & defval);
|
||||
bool GetValueAny(int &retval, const std::string & key, const std::string & desc, int defval);
|
||||
bool GetValueAny(bool& retval, const std::string & key, const std::string & desc, bool defval);
|
||||
bool GetValueAny(float& retval, const std::string & key, const std::string & desc, float defval);
|
||||
bool GetValueAny(double& retval, const std::string & key, const std::string & desc, double defval);
|
||||
bool GetAllValuesAny(std::vector<std::string>& values, const std::string & key, const std::string & desc);
|
||||
|
||||
// get value for key from one of the given sections
|
||||
bool GetValueIn(std::string& retval, const std::string & key, const std::string & desc, const std::string & defval, const char * section1, ... /*, nil*/);
|
||||
bool GetValueIn(std::string& retval, const std::string & key, const std::string & desc, const std::string & defval, std::vector<std::string> & sections );
|
||||
bool GetValueIn(int& retval, const std::string & key, const std::string & desc, int defval, const char * section1, ... /*, nil*/);
|
||||
bool GetValueIn(int& retval, const std::string & key, const std::string & desc, int defval, std::vector<std::string> & sections );
|
||||
bool GetValueIn(bool& retval, const std::string & key, const std::string & desc, bool defval, const char * section1, ... /*, nil*/);
|
||||
bool GetValueIn(bool& retval, const std::string & key, const std::string & desc, bool defval, std::vector<std::string> & sections );
|
||||
bool GetValueIn(float& retval, const std::string & key, const std::string & desc, double defval, const char * section1, ... /*, nil*/);
|
||||
bool GetValueIn(float& retval, const std::string & key, const std::string & desc, double defval, std::vector<std::string> & sections );
|
||||
bool GetValueIn(double& retval, const std::string & key, const std::string & desc, double defval, const char * section1, ... /*, nil*/);
|
||||
bool GetValueIn(double& retval, const std::string & key, const std::string & desc, double defval, std::vector<std::string> & sections );
|
||||
#endif
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class plConfigSource
|
||||
{
|
||||
protected:
|
||||
std::string fCurrSection; // used in parsing
|
||||
std::string fEffectiveSection; // used in parsing
|
||||
KAddValueMode fAddMode; // used in parsing
|
||||
plConfigInfo * fConfigInfo;
|
||||
|
||||
void SplitAt(std::string & key, std::string & value, char splitter, std::string & in);
|
||||
virtual bool ReadString(const std::string & in);
|
||||
virtual bool ReadPair(std::string & key, std::string & value);
|
||||
virtual bool ReadList(char ** list);
|
||||
virtual bool ReadSubSource( const char * name ) { return true; }
|
||||
|
||||
protected:
|
||||
virtual bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd);
|
||||
virtual bool WriteOutOf(plConfigInfo & configInfo);
|
||||
|
||||
public:
|
||||
plConfigSource() {}
|
||||
virtual ~plConfigSource() {}
|
||||
|
||||
friend class plConfigInfo;
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class plCmdLineConfigSource : public plConfigSource
|
||||
{
|
||||
int fArgc;
|
||||
char ** fArgv;
|
||||
std::string fMySection;
|
||||
protected:
|
||||
bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd);
|
||||
public:
|
||||
plCmdLineConfigSource(int argc, char ** argv, const char * mySection="CmdLine");
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class plEnvConfigSource : public plConfigSource
|
||||
{
|
||||
char ** fEnvp;
|
||||
std::string fMySection;
|
||||
protected:
|
||||
bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd);
|
||||
public:
|
||||
plEnvConfigSource(char ** envp, const char * mySection="Environment");
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class plIniConfigSource : public plConfigSource
|
||||
{
|
||||
protected:
|
||||
std::string fFileName;
|
||||
bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd);
|
||||
bool WriteOutOf(plConfigInfo & configInfo);
|
||||
public:
|
||||
plIniConfigSource(const char * iniFileName);
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// just like above, but works with hsStream-derived classes
|
||||
|
||||
class hsStream;
|
||||
class plIniStreamConfigSource : public plConfigSource
|
||||
{
|
||||
protected:
|
||||
hsStream * fStream;
|
||||
bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd);
|
||||
bool WriteOutOf(plConfigInfo & configInfo);
|
||||
public:
|
||||
plIniStreamConfigSource(hsStream * stream);
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
// an ini file reader/writer that ignores section headers and puts all
|
||||
// data in an unnamed section, or more accurately, in a section named "".
|
||||
class plIniNoSectionsConfigSource : public plConfigSource
|
||||
{
|
||||
std::string fFileName;
|
||||
protected:
|
||||
bool ReadString(const std::string & in);
|
||||
bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd);
|
||||
bool WriteOutOf(plConfigInfo & configInfo);
|
||||
public:
|
||||
plIniNoSectionsConfigSource(const char * iniFileName);
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
// an ini file reader that only reads specified sections
|
||||
class plIniSectionConfigSource : public plIniConfigSource
|
||||
{
|
||||
typedef std::vector<xtl::istring>
|
||||
Sections;
|
||||
protected:
|
||||
Sections fSections;
|
||||
bool ReadPair(std::string & key, std::string & value);
|
||||
bool ReadSubSource( const char * name );
|
||||
public:
|
||||
plIniSectionConfigSource(const char * iniFileName, std::vector<std::string> & sections);
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
// TODO: This would be a cool thing. not needed right now though.
|
||||
class plDatabaseConfigSource : public plConfigSource
|
||||
{
|
||||
protected:
|
||||
bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd);
|
||||
bool WriteOutOf(plConfigInfo & configInfo);
|
||||
public:
|
||||
plDatabaseConfigSource(const char * connectString);
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class plDebugConfigSource : public plConfigSource
|
||||
{
|
||||
protected:
|
||||
std::string fFileName;
|
||||
bool WriteOutOf(plConfigInfo & configInfo);
|
||||
public:
|
||||
plDebugConfigSource(){}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
class plWWWAuthenticateConfigSource : public plConfigSource
|
||||
{
|
||||
const std::string& fAuth;
|
||||
protected:
|
||||
bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd);
|
||||
public:
|
||||
plWWWAuthenticateConfigSource(const std::string& auth);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
// NOTE: plClass _must_ appear first in a multiple-inheritance list.
|
||||
class plClass
|
||||
{
|
||||
public:
|
||||
virtual void Unused(){}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef bool (plClass::*TEvaluate)();
|
||||
typedef bool (plClass::*TEvaluateConst)() const;
|
||||
struct plEvaluate
|
||||
{
|
||||
plClass * fTarget;
|
||||
bool (plClass::*fEvaluate)();
|
||||
bool (plClass::*fEvaluateConst)() const;
|
||||
plEvaluate( plClass * target=nil, TEvaluate evaluate=nil )
|
||||
: fTarget(target)
|
||||
, fEvaluate(evaluate)
|
||||
, fEvaluateConst(nil)
|
||||
{}
|
||||
plEvaluate( plClass * target, TEvaluateConst evaluate )
|
||||
: fTarget(target)
|
||||
, fEvaluateConst(evaluate)
|
||||
, fEvaluate(nil)
|
||||
{}
|
||||
bool operator()()
|
||||
{
|
||||
if (fEvaluate)
|
||||
return (fTarget)?(fTarget->*fEvaluate)():true;
|
||||
else
|
||||
if (fEvaluateConst)
|
||||
return (fTarget)?(fTarget->*fEvaluateConst)():true;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef std::string (plClass::*TModify)(const std::string & value);
|
||||
|
||||
struct plModify
|
||||
{
|
||||
plClass * fTarget;
|
||||
std::string (plClass::*fModify)(const std::string & value);
|
||||
plModify( plClass * target=nil, TModify modify=nil )
|
||||
: fTarget(target)
|
||||
, fModify(modify)
|
||||
{}
|
||||
std::string operator()(const std::string & value) { return (fTarget)?(fTarget->*fModify)(value):value;}
|
||||
std::string operator()(const std::string & value) const { return (fTarget)?(fTarget->*fModify)(value):value;}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
class plConfigValueBase
|
||||
{
|
||||
public:
|
||||
std::string fConfigName;
|
||||
std::string fConfigGroup;
|
||||
plEvaluate fReadEvaluate; // returns true if we want to read this value from options
|
||||
plEvaluate fWriteEvaluate; // returns true if we want to write this value to options
|
||||
plModify fReadModify; // may modify the value being read from options
|
||||
plModify fWriteModify; // may modify the value being written to options
|
||||
plModify fGetModify; // may modify the value when being assigned
|
||||
plModify fSetModify; // may modify the value when being accessed
|
||||
plConfigValueBase( const char * configName="", const char * configGroup="" )
|
||||
: fConfigName(configName)
|
||||
, fConfigGroup(configGroup)
|
||||
{}
|
||||
void SetConfigName(const char * name) { fConfigName=(name)?name:"";}
|
||||
std::string GetConfigName() const { return fConfigName;}
|
||||
void SetConfigGroup(const char * group) { fConfigGroup=group;}
|
||||
std::string GetConfigGroup() const { return fConfigGroup;}
|
||||
bool HasConfigName() { return fConfigName.length()>0;}
|
||||
bool HasConfigGroup() { return fConfigGroup.length()>0;}
|
||||
virtual void ConfigRead(plConfigInfo * opts);
|
||||
virtual void ConfigWrite(plConfigInfo * opts);
|
||||
void SetValue(const char * value);
|
||||
std::string GetValue() const;
|
||||
virtual void ISetValue(const char * value) = 0;
|
||||
virtual std::string IGetValue() const = 0;
|
||||
|
||||
void SetReadEvaluate(plClass * targetObj, TEvaluate evalFunc);
|
||||
void SetWriteEvaluate(plClass * targetObj, TEvaluate evalFunc);
|
||||
void SetWriteEvaluate(plClass * targetObj, TEvaluateConst evalFunc);
|
||||
void SetReadModify(plClass * targetObj, TModify modifyFunc);
|
||||
void SetWriteModify(plClass * targetObj, TModify modifyFunc);
|
||||
void SetGetModify(plClass * targetObj, TModify modifyFunc);
|
||||
void SetSetModify(plClass * targetObj, TModify modifyFunc);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
class plConfigValue : public plConfigValueBase
|
||||
{
|
||||
public:
|
||||
plConfigValue( const char * configName="", const char * configGroup="" )
|
||||
: plConfigValueBase(configName, configGroup)
|
||||
{}
|
||||
std::string fConfigValue;
|
||||
void ISetValue(const char * value) { fConfigValue=value;}
|
||||
std::string IGetValue() const { return fConfigValue;}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
class plConfigAggregateValue : public plConfigValueBase
|
||||
{
|
||||
public:
|
||||
std::vector<plConfigValueBase*> fItems;
|
||||
plConfigAggregateValue(
|
||||
const char * name=nil,
|
||||
// A vararg here would not work because of a
|
||||
// multiple inheritance issue. Classes that are
|
||||
// plConfigValueBase are likely to be derived from
|
||||
// plClass also. Since plClass must be first in
|
||||
// the inheritance list, the vararg would not
|
||||
// point to the plConfigValueBase vtable that we
|
||||
// need to access.
|
||||
plConfigValueBase * item1=nil,
|
||||
plConfigValueBase * item2=nil,
|
||||
plConfigValueBase * item3=nil,
|
||||
plConfigValueBase * item4=nil,
|
||||
plConfigValueBase * item5=nil,
|
||||
plConfigValueBase * item6=nil,
|
||||
plConfigValueBase * item7=nil);
|
||||
void ISetValue(const char * value);
|
||||
std::string IGetValue() const;
|
||||
void AddItem(plConfigValueBase * item);
|
||||
void AddItems(
|
||||
plConfigValueBase * item1=nil,
|
||||
plConfigValueBase * item2=nil,
|
||||
plConfigValueBase * item3=nil,
|
||||
plConfigValueBase * item4=nil,
|
||||
plConfigValueBase * item5=nil,
|
||||
plConfigValueBase * item6=nil,
|
||||
plConfigValueBase * item7=nil);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
class plConfigValueProxy : public plConfigValueBase
|
||||
{
|
||||
plConfigValueBase * fConfigurable;
|
||||
public:
|
||||
plConfigValueProxy(plConfigValueBase * item=nil)
|
||||
: fConfigurable(item)
|
||||
{}
|
||||
void Set(plConfigValueBase * item) { fConfigurable=item;}
|
||||
void ISetValue(const char * value) { fConfigurable->ISetValue(value);}
|
||||
std::string IGetValue() const { return fConfigurable->IGetValue();}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
class plConfigGroup
|
||||
{
|
||||
public:
|
||||
plConfigInfo fOpts;
|
||||
std::string fGroupName;
|
||||
std::vector<plConfigValueBase*> fItems;
|
||||
plConfigGroup(const char * groupName="");
|
||||
bool Read(plConfigSource * src);
|
||||
bool Write(plConfigSource * src);
|
||||
void AddItem(plConfigValueBase * item, const char * name=nil);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // plConfigInfo_h_inc
|
||||
|
@ -1,307 +1,307 @@
|
||||
/*==LICENSE==*
|
||||
|
||||
CyanWorlds.com Engine - MMOG client, server and tools
|
||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
or by snail mail at:
|
||||
Cyan Worlds, Inc.
|
||||
14617 N Newport Hwy
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#include "plConfigInfo.h"
|
||||
|
||||
plConfigInfoLogging::plConfigInfoLogging()
|
||||
{
|
||||
}
|
||||
|
||||
plConfigInfoLogging::~plConfigInfoLogging()
|
||||
{
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValue(std::string& retval, const std::string & section, const std::string & key, const std::string & desc, const std::string& defval)
|
||||
{
|
||||
std::string descwdef;
|
||||
xtl::format(descwdef,"%s # %s",defval.c_str(),desc.c_str());
|
||||
fLog.AddValue(section,key,descwdef,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValue(section,key,defval,&found);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValue(int& retval, const std::string & section, const std::string & key, const std::string & desc, int defval)
|
||||
{
|
||||
std::string descwdef;
|
||||
xtl::format(descwdef,"%d # %s",defval,desc.c_str());
|
||||
fLog.AddValue(section,key,descwdef,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValue(section,key,defval,&found);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValue(bool& retval, const std::string & section, const std::string & key, const std::string & desc, bool defval)
|
||||
{
|
||||
std::string descwdef;
|
||||
xtl::format(descwdef,"%d # %s",defval,desc.c_str());
|
||||
fLog.AddValue(section,key,descwdef,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
retval = ( fConfigInfo.GetValue(section,key,(int)defval,&found)!=0 );
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValue(float& retval, const std::string & section, const std::string & key, const std::string & desc, float defval)
|
||||
{
|
||||
std::string descwdef;
|
||||
xtl::format(descwdef,"%f # %s",defval,desc.c_str());
|
||||
fLog.AddValue(section,key,descwdef,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
double retvald = fConfigInfo.GetValue(section,key,defval,&found);
|
||||
retval = (float)retvald;
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValue(double& retval, const std::string & section, const std::string & key, const std::string & desc, double defval)
|
||||
{
|
||||
std::string descwdef;
|
||||
xtl::format(descwdef,"%f # %s",defval,desc.c_str());
|
||||
fLog.AddValue(section,key,descwdef,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValue(section,key,defval,&found);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetAllValues(std::vector<std::string>& values, const std::string & section, const std::string & key, const std::string & desc)
|
||||
{
|
||||
std::string descwdef;
|
||||
xtl::format(descwdef,"%s # %s","\"Multiple Entries\"",desc.c_str());
|
||||
fLog.AddValue(section,key,descwdef,kReplaceIfExists);
|
||||
|
||||
values = fConfigInfo.GetAllValues(section,key);
|
||||
return values.size() != 0;
|
||||
}
|
||||
|
||||
#if USE_MULT_SECTIONS
|
||||
|
||||
bool plConfigInfoLogging::GetValueAny(std::string& retval, const std::string & key, const std::string & desc, const std::string & defval)
|
||||
{
|
||||
fLog.AddValue("ANY SECTION",key,desc,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValueAny(key,defval,&found);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueAny(int &retval, const std::string & key, const std::string & desc, int defval)
|
||||
{
|
||||
fLog.AddValue("ANY SECTION",key,desc,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValueAny(key,defval,&found);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueAny(bool &retval, const std::string & key, const std::string & desc, bool defval)
|
||||
{
|
||||
fLog.AddValue("ANY SECTION",key,desc,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
retval = ( fConfigInfo.GetValueAny(key,(int)defval,&found)!=0 );
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueAny(float& retval, const std::string & key, const std::string & desc, float defval)
|
||||
{
|
||||
fLog.AddValue("ANY SECTION",key,desc,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValueAny(key,defval,&found);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueAny(double& retval, const std::string & key, const std::string & desc, double defval)
|
||||
{
|
||||
fLog.AddValue("ANY SECTION",key,desc,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValueAny(key,defval,&found);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetAllValuesAny(std::vector<std::string>& values, const std::string & key, const std::string & desc)
|
||||
{
|
||||
fLog.AddValue("ANY SECTION",key,desc,kReplaceIfExists);
|
||||
|
||||
values = fConfigInfo.GetAllValuesAny(key);
|
||||
return values.size() != 0;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(std::string& retval, const std::string & key, const std::string & desc, const std::string & defval, const char * section1, ... /*, nil*/)
|
||||
{
|
||||
const char * section = section1;
|
||||
va_list va;
|
||||
va_start(va,section1);
|
||||
std::vector<std::string> sections;
|
||||
while (section)
|
||||
{
|
||||
sections.push_back( section );
|
||||
section = va_arg(va,const char *);
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
return GetValueIn(retval,key,desc,defval,sections);
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(std::string& retval, const std::string & key, const std::string & desc, const std::string & defval, std::vector<std::string> & sections )
|
||||
{
|
||||
std::vector<std::string>::iterator si = sections.begin();
|
||||
while (si != sections.end())
|
||||
{
|
||||
fLog.AddValue(*si,key,desc,kReplaceIfExists);
|
||||
si++;
|
||||
}
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValueIn(key,defval,&found,sections);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(int& retval, const std::string & key, const std::string & desc, int defval, const char * section1, ... /*, nil*/)
|
||||
{
|
||||
const char * section = section1;
|
||||
va_list va;
|
||||
va_start(va,section1);
|
||||
std::vector<std::string> sections;
|
||||
while (section)
|
||||
{
|
||||
sections.push_back( section );
|
||||
section = va_arg(va,const char *);
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
return GetValueIn(retval,key,desc,defval,sections);
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(int& retval, const std::string & key, const std::string & desc, int defval, std::vector<std::string> & sections )
|
||||
{
|
||||
std::vector<std::string>::iterator si = sections.begin();
|
||||
while (si != sections.end())
|
||||
{
|
||||
fLog.AddValue(*si,key,desc,kReplaceIfExists);
|
||||
si++;
|
||||
}
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValueIn(key,defval,&found,sections);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(bool& retval, const std::string & key, const std::string & desc, bool defval, const char * section1, ... /*, nil*/)
|
||||
{
|
||||
const char * section = section1;
|
||||
va_list va;
|
||||
va_start(va,section1);
|
||||
std::vector<std::string> sections;
|
||||
while (section)
|
||||
{
|
||||
sections.push_back( section );
|
||||
section = va_arg(va,const char *);
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
return GetValueIn(retval,key,desc,defval,sections);
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(bool& retval, const std::string & key, const std::string & desc, bool defval, std::vector<std::string> & sections )
|
||||
{
|
||||
std::vector<std::string>::iterator si = sections.begin();
|
||||
while (si != sections.end())
|
||||
{
|
||||
fLog.AddValue(*si,key,desc,kReplaceIfExists);
|
||||
si++;
|
||||
}
|
||||
|
||||
bool found;
|
||||
retval = ( fConfigInfo.GetValueIn(key,(int)defval,&found,sections)!=0 );
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(float& retval, const std::string & key, const std::string & desc, double defval, const char * section1, ... /*, nil*/)
|
||||
{
|
||||
const char * section = section1;
|
||||
va_list va;
|
||||
va_start(va,section1);
|
||||
std::vector<std::string> sections;
|
||||
while (section)
|
||||
{
|
||||
sections.push_back( section );
|
||||
section = va_arg(va,const char *);
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
return GetValueIn(retval,key,desc,defval,sections);
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(float& retval, const std::string & key, const std::string & desc, double defval, std::vector<std::string> & sections )
|
||||
{
|
||||
std::vector<std::string>::iterator si = sections.begin();
|
||||
while (si != sections.end())
|
||||
{
|
||||
fLog.AddValue(*si,key,desc,kReplaceIfExists);
|
||||
si++;
|
||||
}
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValueIn(key,defval,&found,sections);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(double& retval, const std::string & key, const std::string & desc, double defval, const char * section1, ... /*, nil*/)
|
||||
{
|
||||
const char * section = section1;
|
||||
va_list va;
|
||||
va_start(va,section1);
|
||||
std::vector<std::string> sections;
|
||||
while (section)
|
||||
{
|
||||
sections.push_back( section );
|
||||
section = va_arg(va,const char *);
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
return GetValueIn(retval,key,desc,defval,sections);
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(double& retval, const std::string & key, const std::string & desc, double defval, std::vector<std::string> & sections )
|
||||
{
|
||||
std::vector<std::string>::iterator si = sections.begin();
|
||||
while (si != sections.end())
|
||||
{
|
||||
fLog.AddValue(*si,key,desc,kReplaceIfExists);
|
||||
si++;
|
||||
}
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValueIn(key,defval,&found,sections);
|
||||
return found;
|
||||
}
|
||||
|
||||
/*==LICENSE==*
|
||||
|
||||
CyanWorlds.com Engine - MMOG client, server and tools
|
||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
or by snail mail at:
|
||||
Cyan Worlds, Inc.
|
||||
14617 N Newport Hwy
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#include "plConfigInfo.h"
|
||||
|
||||
plConfigInfoLogging::plConfigInfoLogging()
|
||||
{
|
||||
}
|
||||
|
||||
plConfigInfoLogging::~plConfigInfoLogging()
|
||||
{
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValue(std::string& retval, const std::string & section, const std::string & key, const std::string & desc, const std::string& defval)
|
||||
{
|
||||
std::string descwdef;
|
||||
xtl::format(descwdef,"%s # %s",defval.c_str(),desc.c_str());
|
||||
fLog.AddValue(section,key,descwdef,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValue(section,key,defval,&found);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValue(int& retval, const std::string & section, const std::string & key, const std::string & desc, int defval)
|
||||
{
|
||||
std::string descwdef;
|
||||
xtl::format(descwdef,"%d # %s",defval,desc.c_str());
|
||||
fLog.AddValue(section,key,descwdef,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValue(section,key,defval,&found);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValue(bool& retval, const std::string & section, const std::string & key, const std::string & desc, bool defval)
|
||||
{
|
||||
std::string descwdef;
|
||||
xtl::format(descwdef,"%d # %s",defval,desc.c_str());
|
||||
fLog.AddValue(section,key,descwdef,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
retval = ( fConfigInfo.GetValue(section,key,(int)defval,&found)!=0 );
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValue(float& retval, const std::string & section, const std::string & key, const std::string & desc, float defval)
|
||||
{
|
||||
std::string descwdef;
|
||||
xtl::format(descwdef,"%f # %s",defval,desc.c_str());
|
||||
fLog.AddValue(section,key,descwdef,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
double retvald = fConfigInfo.GetValue(section,key,defval,&found);
|
||||
retval = (float)retvald;
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValue(double& retval, const std::string & section, const std::string & key, const std::string & desc, double defval)
|
||||
{
|
||||
std::string descwdef;
|
||||
xtl::format(descwdef,"%f # %s",defval,desc.c_str());
|
||||
fLog.AddValue(section,key,descwdef,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValue(section,key,defval,&found);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetAllValues(std::vector<std::string>& values, const std::string & section, const std::string & key, const std::string & desc)
|
||||
{
|
||||
std::string descwdef;
|
||||
xtl::format(descwdef,"%s # %s","\"Multiple Entries\"",desc.c_str());
|
||||
fLog.AddValue(section,key,descwdef,kReplaceIfExists);
|
||||
|
||||
values = fConfigInfo.GetAllValues(section,key);
|
||||
return values.size() != 0;
|
||||
}
|
||||
|
||||
#if USE_MULT_SECTIONS
|
||||
|
||||
bool plConfigInfoLogging::GetValueAny(std::string& retval, const std::string & key, const std::string & desc, const std::string & defval)
|
||||
{
|
||||
fLog.AddValue("ANY SECTION",key,desc,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValueAny(key,defval,&found);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueAny(int &retval, const std::string & key, const std::string & desc, int defval)
|
||||
{
|
||||
fLog.AddValue("ANY SECTION",key,desc,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValueAny(key,defval,&found);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueAny(bool &retval, const std::string & key, const std::string & desc, bool defval)
|
||||
{
|
||||
fLog.AddValue("ANY SECTION",key,desc,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
retval = ( fConfigInfo.GetValueAny(key,(int)defval,&found)!=0 );
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueAny(float& retval, const std::string & key, const std::string & desc, float defval)
|
||||
{
|
||||
fLog.AddValue("ANY SECTION",key,desc,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValueAny(key,defval,&found);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueAny(double& retval, const std::string & key, const std::string & desc, double defval)
|
||||
{
|
||||
fLog.AddValue("ANY SECTION",key,desc,kReplaceIfExists);
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValueAny(key,defval,&found);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetAllValuesAny(std::vector<std::string>& values, const std::string & key, const std::string & desc)
|
||||
{
|
||||
fLog.AddValue("ANY SECTION",key,desc,kReplaceIfExists);
|
||||
|
||||
values = fConfigInfo.GetAllValuesAny(key);
|
||||
return values.size() != 0;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(std::string& retval, const std::string & key, const std::string & desc, const std::string & defval, const char * section1, ... /*, nil*/)
|
||||
{
|
||||
const char * section = section1;
|
||||
va_list va;
|
||||
va_start(va,section1);
|
||||
std::vector<std::string> sections;
|
||||
while (section)
|
||||
{
|
||||
sections.push_back( section );
|
||||
section = va_arg(va,const char *);
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
return GetValueIn(retval,key,desc,defval,sections);
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(std::string& retval, const std::string & key, const std::string & desc, const std::string & defval, std::vector<std::string> & sections )
|
||||
{
|
||||
std::vector<std::string>::iterator si = sections.begin();
|
||||
while (si != sections.end())
|
||||
{
|
||||
fLog.AddValue(*si,key,desc,kReplaceIfExists);
|
||||
si++;
|
||||
}
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValueIn(key,defval,&found,sections);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(int& retval, const std::string & key, const std::string & desc, int defval, const char * section1, ... /*, nil*/)
|
||||
{
|
||||
const char * section = section1;
|
||||
va_list va;
|
||||
va_start(va,section1);
|
||||
std::vector<std::string> sections;
|
||||
while (section)
|
||||
{
|
||||
sections.push_back( section );
|
||||
section = va_arg(va,const char *);
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
return GetValueIn(retval,key,desc,defval,sections);
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(int& retval, const std::string & key, const std::string & desc, int defval, std::vector<std::string> & sections )
|
||||
{
|
||||
std::vector<std::string>::iterator si = sections.begin();
|
||||
while (si != sections.end())
|
||||
{
|
||||
fLog.AddValue(*si,key,desc,kReplaceIfExists);
|
||||
si++;
|
||||
}
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValueIn(key,defval,&found,sections);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(bool& retval, const std::string & key, const std::string & desc, bool defval, const char * section1, ... /*, nil*/)
|
||||
{
|
||||
const char * section = section1;
|
||||
va_list va;
|
||||
va_start(va,section1);
|
||||
std::vector<std::string> sections;
|
||||
while (section)
|
||||
{
|
||||
sections.push_back( section );
|
||||
section = va_arg(va,const char *);
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
return GetValueIn(retval,key,desc,defval,sections);
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(bool& retval, const std::string & key, const std::string & desc, bool defval, std::vector<std::string> & sections )
|
||||
{
|
||||
std::vector<std::string>::iterator si = sections.begin();
|
||||
while (si != sections.end())
|
||||
{
|
||||
fLog.AddValue(*si,key,desc,kReplaceIfExists);
|
||||
si++;
|
||||
}
|
||||
|
||||
bool found;
|
||||
retval = ( fConfigInfo.GetValueIn(key,(int)defval,&found,sections)!=0 );
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(float& retval, const std::string & key, const std::string & desc, double defval, const char * section1, ... /*, nil*/)
|
||||
{
|
||||
const char * section = section1;
|
||||
va_list va;
|
||||
va_start(va,section1);
|
||||
std::vector<std::string> sections;
|
||||
while (section)
|
||||
{
|
||||
sections.push_back( section );
|
||||
section = va_arg(va,const char *);
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
return GetValueIn(retval,key,desc,defval,sections);
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(float& retval, const std::string & key, const std::string & desc, double defval, std::vector<std::string> & sections )
|
||||
{
|
||||
std::vector<std::string>::iterator si = sections.begin();
|
||||
while (si != sections.end())
|
||||
{
|
||||
fLog.AddValue(*si,key,desc,kReplaceIfExists);
|
||||
si++;
|
||||
}
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValueIn(key,defval,&found,sections);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(double& retval, const std::string & key, const std::string & desc, double defval, const char * section1, ... /*, nil*/)
|
||||
{
|
||||
const char * section = section1;
|
||||
va_list va;
|
||||
va_start(va,section1);
|
||||
std::vector<std::string> sections;
|
||||
while (section)
|
||||
{
|
||||
sections.push_back( section );
|
||||
section = va_arg(va,const char *);
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
return GetValueIn(retval,key,desc,defval,sections);
|
||||
}
|
||||
|
||||
bool plConfigInfoLogging::GetValueIn(double& retval, const std::string & key, const std::string & desc, double defval, std::vector<std::string> & sections )
|
||||
{
|
||||
std::vector<std::string>::iterator si = sections.begin();
|
||||
while (si != sections.end())
|
||||
{
|
||||
fLog.AddValue(*si,key,desc,kReplaceIfExists);
|
||||
si++;
|
||||
}
|
||||
|
||||
bool found;
|
||||
retval = fConfigInfo.GetValueIn(key,defval,&found,sections);
|
||||
return found;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,63 +1,63 @@
|
||||
/*==LICENSE==*
|
||||
|
||||
CyanWorlds.com Engine - MMOG client, server and tools
|
||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
or by snail mail at:
|
||||
Cyan Worlds, Inc.
|
||||
14617 N Newport Hwy
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#ifndef plContainer_h_inc
|
||||
#define plContainer_h_inc
|
||||
|
||||
#include "hsTypes.h"
|
||||
#include "hsStlUtils.h"
|
||||
|
||||
template < class T >
|
||||
class plDataContainerT
|
||||
{
|
||||
typedef std::map<UInt32,T*> Items;
|
||||
Items fItems;
|
||||
UInt32 fNextKey;
|
||||
public:
|
||||
plDataContainerT()
|
||||
: fNextKey( 1 )
|
||||
{}
|
||||
UInt32 Add( T* data )
|
||||
{
|
||||
UInt32 key = fNextKey;
|
||||
fItems[ key ] = data;
|
||||
fNextKey++;
|
||||
return key;
|
||||
}
|
||||
bool Get( UInt32 key, T*& outItem, bool remove=true )
|
||||
{
|
||||
outItem = nil;
|
||||
Items::iterator ii = fItems.find( key );
|
||||
if ( ii==fItems.end() )
|
||||
return false;
|
||||
outItem = ii->second;
|
||||
if ( remove )
|
||||
fItems.erase( ii );
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // plContainer_h_inc
|
||||
/*==LICENSE==*
|
||||
|
||||
CyanWorlds.com Engine - MMOG client, server and tools
|
||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
or by snail mail at:
|
||||
Cyan Worlds, Inc.
|
||||
14617 N Newport Hwy
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#ifndef plContainer_h_inc
|
||||
#define plContainer_h_inc
|
||||
|
||||
#include "hsTypes.h"
|
||||
#include "hsStlUtils.h"
|
||||
|
||||
template < class T >
|
||||
class plDataContainerT
|
||||
{
|
||||
typedef std::map<UInt32,T*> Items;
|
||||
Items fItems;
|
||||
UInt32 fNextKey;
|
||||
public:
|
||||
plDataContainerT()
|
||||
: fNextKey( 1 )
|
||||
{}
|
||||
UInt32 Add( T* data )
|
||||
{
|
||||
UInt32 key = fNextKey;
|
||||
fItems[ key ] = data;
|
||||
fNextKey++;
|
||||
return key;
|
||||
}
|
||||
bool Get( UInt32 key, T*& outItem, bool remove=true )
|
||||
{
|
||||
outItem = nil;
|
||||
Items::iterator ii = fItems.find( key );
|
||||
if ( ii==fItems.end() )
|
||||
return false;
|
||||
outItem = ii->second;
|
||||
if ( remove )
|
||||
fItems.erase( ii );
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // plContainer_h_inc
|
||||
|
@ -1,263 +1,263 @@
|
||||
/*==LICENSE==*
|
||||
|
||||
CyanWorlds.com Engine - MMOG client, server and tools
|
||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
or by snail mail at:
|
||||
Cyan Worlds, Inc.
|
||||
14617 N Newport Hwy
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#include "plKeysAndValues.h"
|
||||
#include "hsStream.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
plKeysAndValues::plKeysAndValues()
|
||||
{
|
||||
}
|
||||
|
||||
plKeysAndValues::plKeysAndValues(const plKeysAndValues & src)
|
||||
: fKeys(src.fKeys)
|
||||
{
|
||||
}
|
||||
|
||||
plKeysAndValues & plKeysAndValues::operator =(const plKeysAndValues & src)
|
||||
{
|
||||
fKeys = src.fKeys;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void plKeysAndValues::Clear()
|
||||
{
|
||||
fKeys.clear();
|
||||
}
|
||||
|
||||
void plKeysAndValues::RemoveKey(const std::string & key)
|
||||
{
|
||||
fKeys.erase(key.c_str());
|
||||
}
|
||||
|
||||
bool plKeysAndValues::HasKey(const std::string & key) const
|
||||
{
|
||||
return (fKeys.find(key.c_str()) != fKeys.end());
|
||||
}
|
||||
|
||||
bool plKeysAndValues::KeyHasValue(const std::string & key, const std::string & value)
|
||||
{
|
||||
Keys::const_iterator ki = fKeys.find(key.c_str());
|
||||
if (ki==fKeys.end())
|
||||
return false;
|
||||
return std::find(ki->second.begin(),ki->second.end(), value.c_str()) != ki->second.end();
|
||||
}
|
||||
|
||||
bool plKeysAndValues::KeyHasValue(const std::string & key, int value)
|
||||
{
|
||||
char buf[20];
|
||||
sprintf(buf, "%d", value);
|
||||
std::string v(buf);
|
||||
return KeyHasValue(key, v);
|
||||
}
|
||||
|
||||
bool plKeysAndValues::KeyHasValue(const std::string & key, double value)
|
||||
{
|
||||
char buf[30];
|
||||
sprintf(buf, "%f", value);
|
||||
std::string v(buf);
|
||||
return KeyHasValue(key, v);
|
||||
}
|
||||
|
||||
bool plKeysAndValues::AddValue(const std::string & key, const std::string & value, KAddValueMode mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case kFailIfExists:
|
||||
if (HasKey(key))
|
||||
return false;
|
||||
break;
|
||||
case kReplaceIfExists:
|
||||
if (HasKey(key))
|
||||
RemoveKey(key);
|
||||
break;
|
||||
}
|
||||
fKeys[key.c_str()].push_front(value.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool plKeysAndValues::AddValue(const std::string & key, int value, KAddValueMode mode)
|
||||
{
|
||||
char buf[20];
|
||||
sprintf(buf, "%d", value);
|
||||
std::string v(buf);
|
||||
return AddValue(key,v,mode);
|
||||
}
|
||||
|
||||
bool plKeysAndValues::AddValue(const std::string & key, double value, KAddValueMode mode)
|
||||
{
|
||||
char buf[30];
|
||||
sprintf(buf, "%f", value);
|
||||
std::string v(buf);
|
||||
return AddValue(key,v,mode);
|
||||
}
|
||||
|
||||
bool plKeysAndValues::AddValues(const std::string & key, const std::vector<std::string> & values, KAddValueMode mode)
|
||||
{
|
||||
for (int i=0; i<values.size(); i++)
|
||||
AddValue(key,values[i],mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool plKeysAndValues::SetValue(const std::string & key, const std::string & value)
|
||||
{
|
||||
fKeys[key.c_str()].clear();
|
||||
return AddValue(key,value);
|
||||
}
|
||||
|
||||
bool plKeysAndValues::SetValue(const std::string & key, int value)
|
||||
{
|
||||
char buf[20];
|
||||
sprintf(buf, "%d", value);
|
||||
std::string v(buf);
|
||||
return SetValue(key, v);
|
||||
}
|
||||
|
||||
bool plKeysAndValues::SetValue(const std::string & key, double value)
|
||||
{
|
||||
char buf[30];
|
||||
sprintf(buf, "%f", value);
|
||||
std::string v(buf);
|
||||
return SetValue(key, v);
|
||||
}
|
||||
|
||||
std::string plKeysAndValues::GetValue(const std::string & key, const std::string & defval, bool * outFound) const
|
||||
{
|
||||
Keys::const_iterator ki = fKeys.find(key.c_str());
|
||||
if (outFound)
|
||||
*outFound = (ki!=fKeys.end());
|
||||
if(ki != fKeys.end())
|
||||
return ki->second.front().c_str();
|
||||
// fKeys[key.c_str()].push_front(defval.c_str());
|
||||
return defval;
|
||||
}
|
||||
|
||||
UInt32 plKeysAndValues::GetValue(const std::string & key, UInt32 defval, bool * outFound) const
|
||||
{
|
||||
char buf[20];
|
||||
sprintf(buf, "%ul", defval);
|
||||
std::string v(buf);
|
||||
return strtoul(GetValue(key,v,outFound).c_str(), nil, 0);
|
||||
}
|
||||
|
||||
int plKeysAndValues::GetValue(const std::string & key, int defval, bool * outFound) const
|
||||
{
|
||||
char buf[20];
|
||||
sprintf(buf, "%d", defval);
|
||||
std::string v(buf);
|
||||
return atol(GetValue(key,v,outFound).c_str());
|
||||
}
|
||||
|
||||
double plKeysAndValues::GetValue(const std::string & key, double defval, bool * outFound) const
|
||||
{
|
||||
char buf[30];
|
||||
sprintf(buf, "%f", defval);
|
||||
std::string v(buf);
|
||||
return atof(GetValue(key,v,outFound).c_str());
|
||||
}
|
||||
|
||||
std::vector<std::string> plKeysAndValues::GetAllValues(const std::string & key)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
xtl::istring xkey = key.c_str();
|
||||
if (HasKey(key))
|
||||
for (Values::const_iterator vi=fKeys[xkey].begin(); vi!=fKeys[xkey].end(); ++vi)
|
||||
result.push_back(vi->c_str());
|
||||
return result;
|
||||
}
|
||||
|
||||
bool plKeysAndValues::GetKeyIterators(Keys::const_iterator & iter, Keys::const_iterator & end) const
|
||||
{
|
||||
iter = fKeys.begin();
|
||||
end = fKeys.end();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool plKeysAndValues::GetValueIterators(const xtl::istring & key, Values::const_iterator & iter, Values::const_iterator & end) const
|
||||
{
|
||||
Keys::const_iterator ki = fKeys.find(key);
|
||||
if(ki != fKeys.end())
|
||||
{
|
||||
iter = ki->second.begin();
|
||||
end = ki->second.end();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void plKeysAndValues::Read(hsStream * s)
|
||||
{
|
||||
UInt16 nkeys;
|
||||
s->ReadSwap(&nkeys);
|
||||
for (int ki=0; ki<nkeys; ki++)
|
||||
{
|
||||
UInt16 strlen;
|
||||
s->ReadSwap(&strlen);
|
||||
std::string key;
|
||||
key.assign(strlen+1,'\0');
|
||||
s->Read(strlen,(void*)key.data());
|
||||
key.resize(strlen);
|
||||
UInt16 nvalues;
|
||||
s->ReadSwap(&nvalues);
|
||||
for (int vi=0; vi<nvalues; vi++)
|
||||
{
|
||||
s->ReadSwap(&strlen);
|
||||
std::string value;
|
||||
value.assign(strlen+1,'\0');
|
||||
s->Read(strlen,(void*)value.data());
|
||||
value.resize(strlen);
|
||||
// for now, only single value for key on stream is allowed.
|
||||
SetValue(key,value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void plKeysAndValues::Write(hsStream * s)
|
||||
{
|
||||
// write nkeys
|
||||
s->WriteSwap((UInt16)fKeys.size());
|
||||
// iterate through keys
|
||||
Keys::const_iterator ki,ke;
|
||||
GetKeyIterators(ki,ke);
|
||||
for (ki;ki!=ke;++ki)
|
||||
{
|
||||
// write key string
|
||||
s->WriteSwap((UInt16)ki->first.size());
|
||||
s->Write(ki->first.size(),ki->first.c_str());
|
||||
// write nvalues for this key
|
||||
s->WriteSwap((UInt16)ki->second.size());
|
||||
// iterate through values for this key
|
||||
Values::const_iterator vi,ve;
|
||||
GetValueIterators(ki->first,vi,ve);
|
||||
for (vi;vi!=ve;++vi)
|
||||
{
|
||||
// write value string
|
||||
s->WriteSwap((UInt16)vi->size());
|
||||
s->Write(vi->size(),vi->c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
/*==LICENSE==*
|
||||
|
||||
CyanWorlds.com Engine - MMOG client, server and tools
|
||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
or by snail mail at:
|
||||
Cyan Worlds, Inc.
|
||||
14617 N Newport Hwy
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#include "plKeysAndValues.h"
|
||||
#include "hsStream.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
plKeysAndValues::plKeysAndValues()
|
||||
{
|
||||
}
|
||||
|
||||
plKeysAndValues::plKeysAndValues(const plKeysAndValues & src)
|
||||
: fKeys(src.fKeys)
|
||||
{
|
||||
}
|
||||
|
||||
plKeysAndValues & plKeysAndValues::operator =(const plKeysAndValues & src)
|
||||
{
|
||||
fKeys = src.fKeys;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void plKeysAndValues::Clear()
|
||||
{
|
||||
fKeys.clear();
|
||||
}
|
||||
|
||||
void plKeysAndValues::RemoveKey(const std::string & key)
|
||||
{
|
||||
fKeys.erase(key.c_str());
|
||||
}
|
||||
|
||||
bool plKeysAndValues::HasKey(const std::string & key) const
|
||||
{
|
||||
return (fKeys.find(key.c_str()) != fKeys.end());
|
||||
}
|
||||
|
||||
bool plKeysAndValues::KeyHasValue(const std::string & key, const std::string & value)
|
||||
{
|
||||
Keys::const_iterator ki = fKeys.find(key.c_str());
|
||||
if (ki==fKeys.end())
|
||||
return false;
|
||||
return std::find(ki->second.begin(),ki->second.end(), value.c_str()) != ki->second.end();
|
||||
}
|
||||
|
||||
bool plKeysAndValues::KeyHasValue(const std::string & key, int value)
|
||||
{
|
||||
char buf[20];
|
||||
sprintf(buf, "%d", value);
|
||||
std::string v(buf);
|
||||
return KeyHasValue(key, v);
|
||||
}
|
||||
|
||||
bool plKeysAndValues::KeyHasValue(const std::string & key, double value)
|
||||
{
|
||||
char buf[30];
|
||||
sprintf(buf, "%f", value);
|
||||
std::string v(buf);
|
||||
return KeyHasValue(key, v);
|
||||
}
|
||||
|
||||
bool plKeysAndValues::AddValue(const std::string & key, const std::string & value, KAddValueMode mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case kFailIfExists:
|
||||
if (HasKey(key))
|
||||
return false;
|
||||
break;
|
||||
case kReplaceIfExists:
|
||||
if (HasKey(key))
|
||||
RemoveKey(key);
|
||||
break;
|
||||
}
|
||||
fKeys[key.c_str()].push_front(value.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool plKeysAndValues::AddValue(const std::string & key, int value, KAddValueMode mode)
|
||||
{
|
||||
char buf[20];
|
||||
sprintf(buf, "%d", value);
|
||||
std::string v(buf);
|
||||
return AddValue(key,v,mode);
|
||||
}
|
||||
|
||||
bool plKeysAndValues::AddValue(const std::string & key, double value, KAddValueMode mode)
|
||||
{
|
||||
char buf[30];
|
||||
sprintf(buf, "%f", value);
|
||||
std::string v(buf);
|
||||
return AddValue(key,v,mode);
|
||||
}
|
||||
|
||||
bool plKeysAndValues::AddValues(const std::string & key, const std::vector<std::string> & values, KAddValueMode mode)
|
||||
{
|
||||
for (int i=0; i<values.size(); i++)
|
||||
AddValue(key,values[i],mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool plKeysAndValues::SetValue(const std::string & key, const std::string & value)
|
||||
{
|
||||
fKeys[key.c_str()].clear();
|
||||
return AddValue(key,value);
|
||||
}
|
||||
|
||||
bool plKeysAndValues::SetValue(const std::string & key, int value)
|
||||
{
|
||||
char buf[20];
|
||||
sprintf(buf, "%d", value);
|
||||
std::string v(buf);
|
||||
return SetValue(key, v);
|
||||
}
|
||||
|
||||
bool plKeysAndValues::SetValue(const std::string & key, double value)
|
||||
{
|
||||
char buf[30];
|
||||
sprintf(buf, "%f", value);
|
||||
std::string v(buf);
|
||||
return SetValue(key, v);
|
||||
}
|
||||
|
||||
std::string plKeysAndValues::GetValue(const std::string & key, const std::string & defval, bool * outFound) const
|
||||
{
|
||||
Keys::const_iterator ki = fKeys.find(key.c_str());
|
||||
if (outFound)
|
||||
*outFound = (ki!=fKeys.end());
|
||||
if(ki != fKeys.end())
|
||||
return ki->second.front().c_str();
|
||||
// fKeys[key.c_str()].push_front(defval.c_str());
|
||||
return defval;
|
||||
}
|
||||
|
||||
UInt32 plKeysAndValues::GetValue(const std::string & key, UInt32 defval, bool * outFound) const
|
||||
{
|
||||
char buf[20];
|
||||
sprintf(buf, "%ul", defval);
|
||||
std::string v(buf);
|
||||
return strtoul(GetValue(key,v,outFound).c_str(), nil, 0);
|
||||
}
|
||||
|
||||
int plKeysAndValues::GetValue(const std::string & key, int defval, bool * outFound) const
|
||||
{
|
||||
char buf[20];
|
||||
sprintf(buf, "%d", defval);
|
||||
std::string v(buf);
|
||||
return atol(GetValue(key,v,outFound).c_str());
|
||||
}
|
||||
|
||||
double plKeysAndValues::GetValue(const std::string & key, double defval, bool * outFound) const
|
||||
{
|
||||
char buf[30];
|
||||
sprintf(buf, "%f", defval);
|
||||
std::string v(buf);
|
||||
return atof(GetValue(key,v,outFound).c_str());
|
||||
}
|
||||
|
||||
std::vector<std::string> plKeysAndValues::GetAllValues(const std::string & key)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
xtl::istring xkey = key.c_str();
|
||||
if (HasKey(key))
|
||||
for (Values::const_iterator vi=fKeys[xkey].begin(); vi!=fKeys[xkey].end(); ++vi)
|
||||
result.push_back(vi->c_str());
|
||||
return result;
|
||||
}
|
||||
|
||||
bool plKeysAndValues::GetKeyIterators(Keys::const_iterator & iter, Keys::const_iterator & end) const
|
||||
{
|
||||
iter = fKeys.begin();
|
||||
end = fKeys.end();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool plKeysAndValues::GetValueIterators(const xtl::istring & key, Values::const_iterator & iter, Values::const_iterator & end) const
|
||||
{
|
||||
Keys::const_iterator ki = fKeys.find(key);
|
||||
if(ki != fKeys.end())
|
||||
{
|
||||
iter = ki->second.begin();
|
||||
end = ki->second.end();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void plKeysAndValues::Read(hsStream * s)
|
||||
{
|
||||
UInt16 nkeys;
|
||||
s->ReadSwap(&nkeys);
|
||||
for (int ki=0; ki<nkeys; ki++)
|
||||
{
|
||||
UInt16 strlen;
|
||||
s->ReadSwap(&strlen);
|
||||
std::string key;
|
||||
key.assign(strlen+1,'\0');
|
||||
s->Read(strlen,(void*)key.data());
|
||||
key.resize(strlen);
|
||||
UInt16 nvalues;
|
||||
s->ReadSwap(&nvalues);
|
||||
for (int vi=0; vi<nvalues; vi++)
|
||||
{
|
||||
s->ReadSwap(&strlen);
|
||||
std::string value;
|
||||
value.assign(strlen+1,'\0');
|
||||
s->Read(strlen,(void*)value.data());
|
||||
value.resize(strlen);
|
||||
// for now, only single value for key on stream is allowed.
|
||||
SetValue(key,value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void plKeysAndValues::Write(hsStream * s)
|
||||
{
|
||||
// write nkeys
|
||||
s->WriteSwap((UInt16)fKeys.size());
|
||||
// iterate through keys
|
||||
Keys::const_iterator ki,ke;
|
||||
GetKeyIterators(ki,ke);
|
||||
for (ki;ki!=ke;++ki)
|
||||
{
|
||||
// write key string
|
||||
s->WriteSwap((UInt16)ki->first.size());
|
||||
s->Write(ki->first.size(),ki->first.c_str());
|
||||
// write nvalues for this key
|
||||
s->WriteSwap((UInt16)ki->second.size());
|
||||
// iterate through values for this key
|
||||
Values::const_iterator vi,ve;
|
||||
GetValueIterators(ki->first,vi,ve);
|
||||
for (vi;vi!=ve;++vi)
|
||||
{
|
||||
// write value string
|
||||
s->WriteSwap((UInt16)vi->size());
|
||||
s->Write(vi->size(),vi->c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,103 +1,103 @@
|
||||
/*==LICENSE==*
|
||||
|
||||
CyanWorlds.com Engine - MMOG client, server and tools
|
||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
or by snail mail at:
|
||||
Cyan Worlds, Inc.
|
||||
14617 N Newport Hwy
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#ifndef plKeysAndValues_h_inc
|
||||
#define plKeysAndValues_h_inc
|
||||
|
||||
#include "hsConfig.h"
|
||||
#include "hsUtils.h"
|
||||
#include "hsStlUtils.h"
|
||||
#include "hsStream.h"
|
||||
|
||||
#pragma warning(disable:4284)
|
||||
|
||||
enum KAddValueMode
|
||||
{
|
||||
kAlwaysAdd, // Add another value if key already exists
|
||||
kReplaceIfExists, // Replace any existing key with new value.
|
||||
kFailIfExists, // Do not add if key already exists.
|
||||
};
|
||||
|
||||
|
||||
// class plKeysAndValues
|
||||
// A multimap class. Stores multiple values per key.
|
||||
class plKeysAndValues : public hsStreamable
|
||||
{
|
||||
public:
|
||||
typedef std::list<xtl::istring>
|
||||
Values;
|
||||
typedef std::map<xtl::istring, Values>
|
||||
Keys;
|
||||
|
||||
private:
|
||||
mutable Keys fKeys;
|
||||
|
||||
public:
|
||||
// ctor
|
||||
plKeysAndValues();
|
||||
plKeysAndValues(const plKeysAndValues & src);
|
||||
virtual ~plKeysAndValues(){}
|
||||
// assign
|
||||
plKeysAndValues & operator =(const plKeysAndValues & src);
|
||||
// clear
|
||||
void Clear();
|
||||
void RemoveKey(const std::string & key);
|
||||
// query
|
||||
bool HasKey(const std::string & key) const;
|
||||
bool KeyHasValue(const std::string & key, const std::string & value);
|
||||
bool KeyHasValue(const std::string & key, int value);
|
||||
bool KeyHasValue(const std::string & key, double value);
|
||||
// add
|
||||
bool AddValue(const std::string & key, const std::string & value, KAddValueMode mode=kAlwaysAdd);
|
||||
bool AddValue(const std::string & key, int value, KAddValueMode mode=kAlwaysAdd);
|
||||
bool AddValue(const std::string & key, double value, KAddValueMode mode=kAlwaysAdd);
|
||||
bool AddValues(const std::string & key, const std::vector<std::string> & values, KAddValueMode mode=kAlwaysAdd);
|
||||
// set (clear and add)
|
||||
bool SetValue(const std::string & key, const std::string & value);
|
||||
bool SetValue(const std::string & key, int value);
|
||||
bool SetValue(const std::string & key, double value);
|
||||
// get single value
|
||||
std::string GetValue(const std::string & key, const std::string & defval="", bool * outFound=nil) const;
|
||||
UInt32 GetValue(const std::string & key, UInt32 defval, bool * outFound=nil) const;
|
||||
int GetValue(const std::string & key, int defval, bool * outFound=nil) const;
|
||||
double GetValue(const std::string & key, double defval, bool * outFound=nil) const;
|
||||
std::vector<std::string> GetAllValues(const std::string & key);
|
||||
// key iterator
|
||||
bool GetKeyIterators(Keys::const_iterator & iter, Keys::const_iterator & end) const;
|
||||
// value iterator (use for getting all values for key)
|
||||
bool GetValueIterators(const xtl::istring & key, Values::const_iterator & iter, Values::const_iterator & end) const;
|
||||
// streamable
|
||||
void Read(hsStream * s);
|
||||
void Write(hsStream * s);
|
||||
// TODO:
|
||||
UInt32 GetStreamSize() { return 0;}
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#endif // plKeysAndValues_h_inc
|
||||
/*==LICENSE==*
|
||||
|
||||
CyanWorlds.com Engine - MMOG client, server and tools
|
||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
or by snail mail at:
|
||||
Cyan Worlds, Inc.
|
||||
14617 N Newport Hwy
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#ifndef plKeysAndValues_h_inc
|
||||
#define plKeysAndValues_h_inc
|
||||
|
||||
#include "hsConfig.h"
|
||||
#include "hsUtils.h"
|
||||
#include "hsStlUtils.h"
|
||||
#include "hsStream.h"
|
||||
|
||||
#pragma warning(disable:4284)
|
||||
|
||||
enum KAddValueMode
|
||||
{
|
||||
kAlwaysAdd, // Add another value if key already exists
|
||||
kReplaceIfExists, // Replace any existing key with new value.
|
||||
kFailIfExists, // Do not add if key already exists.
|
||||
};
|
||||
|
||||
|
||||
// class plKeysAndValues
|
||||
// A multimap class. Stores multiple values per key.
|
||||
class plKeysAndValues : public hsStreamable
|
||||
{
|
||||
public:
|
||||
typedef std::list<xtl::istring>
|
||||
Values;
|
||||
typedef std::map<xtl::istring, Values>
|
||||
Keys;
|
||||
|
||||
private:
|
||||
mutable Keys fKeys;
|
||||
|
||||
public:
|
||||
// ctor
|
||||
plKeysAndValues();
|
||||
plKeysAndValues(const plKeysAndValues & src);
|
||||
virtual ~plKeysAndValues(){}
|
||||
// assign
|
||||
plKeysAndValues & operator =(const plKeysAndValues & src);
|
||||
// clear
|
||||
void Clear();
|
||||
void RemoveKey(const std::string & key);
|
||||
// query
|
||||
bool HasKey(const std::string & key) const;
|
||||
bool KeyHasValue(const std::string & key, const std::string & value);
|
||||
bool KeyHasValue(const std::string & key, int value);
|
||||
bool KeyHasValue(const std::string & key, double value);
|
||||
// add
|
||||
bool AddValue(const std::string & key, const std::string & value, KAddValueMode mode=kAlwaysAdd);
|
||||
bool AddValue(const std::string & key, int value, KAddValueMode mode=kAlwaysAdd);
|
||||
bool AddValue(const std::string & key, double value, KAddValueMode mode=kAlwaysAdd);
|
||||
bool AddValues(const std::string & key, const std::vector<std::string> & values, KAddValueMode mode=kAlwaysAdd);
|
||||
// set (clear and add)
|
||||
bool SetValue(const std::string & key, const std::string & value);
|
||||
bool SetValue(const std::string & key, int value);
|
||||
bool SetValue(const std::string & key, double value);
|
||||
// get single value
|
||||
std::string GetValue(const std::string & key, const std::string & defval="", bool * outFound=nil) const;
|
||||
UInt32 GetValue(const std::string & key, UInt32 defval, bool * outFound=nil) const;
|
||||
int GetValue(const std::string & key, int defval, bool * outFound=nil) const;
|
||||
double GetValue(const std::string & key, double defval, bool * outFound=nil) const;
|
||||
std::vector<std::string> GetAllValues(const std::string & key);
|
||||
// key iterator
|
||||
bool GetKeyIterators(Keys::const_iterator & iter, Keys::const_iterator & end) const;
|
||||
// value iterator (use for getting all values for key)
|
||||
bool GetValueIterators(const xtl::istring & key, Values::const_iterator & iter, Values::const_iterator & end) const;
|
||||
// streamable
|
||||
void Read(hsStream * s);
|
||||
void Write(hsStream * s);
|
||||
// TODO:
|
||||
UInt32 GetStreamSize() { return 0;}
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#endif // plKeysAndValues_h_inc
|
||||
|
Reference in New Issue
Block a user