summaryrefslogtreecommitdiff
path: root/src/cstore/cstore.hpp
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2010-08-24 18:54:06 -0700
committerAn-Cheng Huang <ancheng@vyatta.com>2010-08-24 18:54:06 -0700
commit3afeb6df69058c605ad251dfc7ae93d4d0ae6f1d (patch)
treea28c274fc90b445b0564b1a1a2fd4561b6f1d7ac /src/cstore/cstore.hpp
parenta73891ca1724559ce2ad9916124c59eb9c417091 (diff)
downloadvyatta-cfg-3afeb6df69058c605ad251dfc7ae93d4d0ae6f1d.tar.gz
vyatta-cfg-3afeb6df69058c605ad251dfc7ae93d4d0ae6f1d.zip
add extensible node sorting mechanism
* unify node sorting implementation into the backend library. * allow future implementation of per-node, customized sorting policy.
Diffstat (limited to 'src/cstore/cstore.hpp')
-rw-r--r--src/cstore/cstore.hpp41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/cstore/cstore.hpp b/src/cstore/cstore.hpp
index 0c80ffd..8cb3fd1 100644
--- a/src/cstore/cstore.hpp
+++ b/src/cstore/cstore.hpp
@@ -38,7 +38,7 @@ using namespace std;
class Cstore {
public:
- Cstore() {};
+ Cstore() { init(); };
Cstore(string& env);
virtual ~Cstore() {};
@@ -66,6 +66,7 @@ public:
static const size_t MAX_CMD_OUTPUT_SIZE = 4096;
+
////// the public cstore interface
//// functions implemented in this base class
// these operate on template path
@@ -186,7 +187,13 @@ public:
void cfgPathGetDeletedValues(const vector<string>& path_comps,
vector<string>& dvals);
void cfgPathGetChildNodesStatus(const vector<string>& path_comps,
- map<string, string>& cmap);
+ map<string, string>& cmap) {
+ vector<string> dummy;
+ cfgPathGetChildNodesStatus(path_comps, cmap, dummy);
+ };
+ void cfgPathGetChildNodesStatus(const vector<string>& path_comps,
+ map<string, string>& cmap,
+ vector<string>& sorted_keys);
/* observers for "effective config". can be used both during a config
* session and outside a config session. more detailed information
@@ -244,7 +251,13 @@ public:
vector<string>& dvals,
bool include_deactivated = true);
void cfgPathGetChildNodesStatusDA(const vector<string>& path_comps,
- map<string, string>& cmap);
+ map<string, string>& cmap) {
+ vector<string> dummy;
+ cfgPathGetChildNodesStatusDA(path_comps, cmap, dummy);
+ };
+ void cfgPathGetChildNodesStatusDA(const vector<string>& path_comps,
+ map<string, string>& cmap,
+ vector<string>& sorted_keys);
/* these are internal API functions and operate on current cfg and
@@ -349,6 +362,28 @@ private:
virtual string tmpl_path_to_str() = 0;
////// implemented
+ // for sorting
+ typedef enum {
+ SORT_DEFAULT = 0,
+ SORT_DEB_VERSION = 0,
+ SORT_NONE
+ } SortAlgT;
+ typedef bool (*SortFuncT)(std::string, std::string);
+ static map<SortAlgT, SortFuncT> _sort_func_map;
+
+ static bool sort_func_deb_version(string a, string b);
+ void sort_nodes(vector<string>& nvec, SortAlgT sort_alg = SORT_DEFAULT);
+
+ // init
+ static bool _init;
+ static void init() {
+ if (_init) {
+ return;
+ }
+ _init = true;
+ _sort_func_map[SORT_DEB_VERSION] = &sort_func_deb_version;
+ }
+
// begin path modifiers (only these can change path permanently)
bool append_tmpl_path(const vector<string>& path_comps, bool& is_tag);
bool append_tmpl_path(const vector<string>& path_comps) {