config nodes: utility code to create a node for a specific file
The factory function is defined in ConfigNode because that is the minimal API that is needed by code creating and using such a node. The actual implementatation is in FileConfigNode.cpp and uses a SafeConfigNode as wrapper to make key/value pairs safe for storing.
This commit is contained in:
parent
b0ff104363
commit
b35c27cc45
|
@ -10,6 +10,8 @@
|
|||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
/**
|
||||
* This class corresponds to the Funambol C++ client
|
||||
* DeviceManagementNode, but offers a slightly different API. See
|
||||
|
@ -20,6 +22,9 @@ class ConfigNode {
|
|||
/** free resources without saving */
|
||||
virtual ~ConfigNode() {}
|
||||
|
||||
/** creates a file-backed config node which accepts arbitrary key/value pairs */
|
||||
static boost::shared_ptr<ConfigNode> createFileNode(const string &filename);
|
||||
|
||||
/** a name for the node that the user can understand */
|
||||
virtual string getName() const = 0;
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*/
|
||||
|
||||
#include "FileConfigNode.h"
|
||||
#include "SafeConfigNode.h"
|
||||
#include "EvolutionSyncClient.h"
|
||||
#include "SyncEvolutionUtil.h"
|
||||
|
||||
|
@ -16,6 +17,22 @@
|
|||
|
||||
/** @TODO: replace stdio.h with streams */
|
||||
|
||||
boost::shared_ptr<ConfigNode> ConfigNode::createFileNode(const string &filename)
|
||||
{
|
||||
string::size_type off = filename.rfind('/');
|
||||
boost::shared_ptr<ConfigNode> filenode;
|
||||
if (off != filename.npos) {
|
||||
filenode.reset(new FileConfigNode(filename.substr(0, off),
|
||||
filename.substr(off + 1),
|
||||
false));
|
||||
} else {
|
||||
filenode.reset(new FileConfigNode(".", filename, false));
|
||||
}
|
||||
boost::shared_ptr<SafeConfigNode> savenode(new SafeConfigNode(filenode));
|
||||
savenode->setMode(false);
|
||||
return savenode;
|
||||
}
|
||||
|
||||
FileConfigNode::FileConfigNode(const string &path, const string &fileName, bool readonly) :
|
||||
m_path(path),
|
||||
m_fileName(fileName),
|
||||
|
|
Loading…
Reference in a new issue