| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "imodule.h" |
| 4 |
#include "xmlutil/Document.h" |
| 5 |
#include "xmlutil/Node.h" |
| 6 |
|
| 7 |
#include <sigc++/slot.h> |
| 8 |
#include <sigc++/signal.h> |
| 9 |
|
| 10 |
/** |
| 11 |
* \addtogroup registry XML Registry |
| 12 |
*/ |
| 13 |
|
| 14 |
// String identifier for the registry module |
| 15 |
const char* const MODULE_XMLREGISTRY("XMLRegistry"); |
| 16 |
|
| 17 |
/** |
| 18 |
* Abstract base class for the registry module. |
| 19 |
* |
| 20 |
* \ingroup registry |
| 21 |
*/ |
| 22 |
class Registry: public RegisterableModule |
| 23 |
{ |
| 24 |
public: |
| 25 |
enum Tree { |
| 26 |
treeStandard, |
| 27 |
treeUser |
| 28 |
}; |
| 29 |
|
| 30 |
/// Set a keyvalue in the registry |
| 31 |
virtual void set(const std::string& key, const std::string& value) = 0; |
| 32 |
|
| 33 |
/// Get a keyvalue from the registry |
| 34 |
virtual std::string get(const std::string& key) = 0; |
| 35 |
|
| 36 |
// Checks whether a key exists in the registry |
| 37 |
virtual bool keyExists(const std::string& key) = 0; |
| 38 |
|
| 39 |
/** |
| 40 |
* Import an XML file into the registry, without a version check. If the |
| 41 |
* file cannot be imported for any reason, a std::runtime_error exception |
| 42 |
* will be thrown. |
| 43 |
* |
| 44 |
* @param importFilePath |
| 45 |
* Full pathname of the file to import. |
| 46 |
* |
| 47 |
* @param parentKey |
| 48 |
* The path to the node within the current registry under which the |
| 49 |
* imported nodes should be added. |
| 50 |
* |
| 51 |
* @param tree: the tree the file should be imported to (e.g. eDefault) |
| 52 |
*/ |
| 53 |
virtual void import(const std::string& importFilePath, const std::string& parentKey, Tree tree) = 0; |
| 54 |
|
| 55 |
// Dumps the whole XML content to std::out for debugging purposes |
| 56 |
virtual void dump() const = 0; |
| 57 |
|
| 58 |
// Exports the data which has been modified during this session |
| 59 |
// to XML files in the user's settings path |
| 60 |
virtual void saveToDisk() = 0; |
| 61 |
|
| 62 |
// Saves the specified node and all its children into the file <filename> |
| 63 |
virtual void exportToFile(const std::string& key, const std::string& filename = "-") = 0; |
| 64 |
|
| 65 |
// Retrieves the nodelist corresponding for the specified XPath (wraps to xml::Document) |
| 66 |
virtual xml::NodeList findXPath(const std::string& path) = 0; |
| 67 |
|
| 68 |
// Creates an empty key |
| 69 |
virtual xml::Node createKey(const std::string& key) = 0; |
| 70 |
|
| 71 |
// Creates a new node named <key> as children of <path> with the name attribute set to <name> |
| 72 |
// The newly created node is returned after creation |
| 73 |
virtual xml::Node createKeyWithName(const std::string& path, |
| 74 |
const std::string& key, |
| 75 |
const std::string& name) = 0; |
| 76 |
|
| 77 |
/** |
| 78 |
* greebo: Sets the named attribute of the given node specified by <path>. |
| 79 |
* |
| 80 |
* @path: The XPath to the node. |
| 81 |
* @attrName: The name of the attribute. |
| 82 |
* @attrValue: The string value of the attribute. |
| 83 |
*/ |
| 84 |
virtual void setAttribute(const std::string& path, |
| 85 |
const std::string& attrName, |
| 86 |
const std::string& attrValue) = 0; |
| 87 |
|
| 88 |
/** |
| 89 |
* greebo: Loads the value of the given attribute at the given path. |
| 90 |
* |
| 91 |
* @path: The XPath to the node. |
| 92 |
* @attrName: The name of the attribute. |
| 93 |
* |
| 94 |
* @returns: the string value of the attribute. |
| 95 |
*/ |
| 96 |
virtual std::string getAttribute(const std::string& path, const std::string& attrName) = 0; |
| 97 |
|
| 98 |
// Deletes an entire subtree from the registry |
| 99 |
virtual void deleteXPath(const std::string& path) = 0; |
| 100 |
|
| 101 |
/// Return a signal which will be emitted when a given key changes |
| 102 |
virtual sigc::signal<void> signalForKey(const std::string& key) const = 0; |
| 103 |
}; |
| 104 |
typedef std::shared_ptr<Registry> RegistryPtr; |
| 105 |
|
| 106 |
// This is the accessor for the registry |
| 107 |
inline Registry& GlobalRegistry() |
| 108 |
{ |
| 109 |
static module::InstanceReference<Registry> _reference(MODULE_XMLREGISTRY); |
| 110 |
return _reference; |
| 111 |
} |