From 3afeb6df69058c605ad251dfc7ae93d4d0ae6f1d Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Tue, 24 Aug 2010 18:54:06 -0700 Subject: add extensible node sorting mechanism * unify node sorting implementation into the backend library. * allow future implementation of per-node, customized sorting policy. --- src/cstore/cstore.hpp | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'src/cstore/cstore.hpp') 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& path_comps, vector& dvals); void cfgPathGetChildNodesStatus(const vector& path_comps, - map& cmap); + map& cmap) { + vector dummy; + cfgPathGetChildNodesStatus(path_comps, cmap, dummy); + }; + void cfgPathGetChildNodesStatus(const vector& path_comps, + map& cmap, + vector& 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& dvals, bool include_deactivated = true); void cfgPathGetChildNodesStatusDA(const vector& path_comps, - map& cmap); + map& cmap) { + vector dummy; + cfgPathGetChildNodesStatusDA(path_comps, cmap, dummy); + }; + void cfgPathGetChildNodesStatusDA(const vector& path_comps, + map& cmap, + vector& 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 _sort_func_map; + + static bool sort_func_deb_version(string a, string b); + void sort_nodes(vector& 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& path_comps, bool& is_tag); bool append_tmpl_path(const vector& path_comps) { -- cgit v1.2.3