summaryrefslogtreecommitdiff
path: root/src/cstore
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2010-08-25 16:41:44 -0700
committerAn-Cheng Huang <ancheng@vyatta.com>2010-08-25 16:41:44 -0700
commit28b30ff302ed535b1e81902f06d24c9e9fe61c19 (patch)
tree80887a7f8fa0c602ccb6c88257dc6b41bf51e2b1 /src/cstore
parent17e3a880453dc220e5a235df1e21dabfa89f1e8e (diff)
downloadvyatta-cfg-28b30ff302ed535b1e81902f06d24c9e9fe61c19.tar.gz
vyatta-cfg-28b30ff302ed535b1e81902f06d24c9e9fe61c19.zip
switch to unordered_map
Diffstat (limited to 'src/cstore')
-rw-r--r--src/cstore/cstore-varref.cpp2
-rw-r--r--src/cstore/cstore.cpp31
-rw-r--r--src/cstore/cstore.hpp32
-rw-r--r--src/cstore/unionfs/cstore-unionfs.cpp19
-rw-r--r--src/cstore/unionfs/cstore-unionfs.hpp4
5 files changed, 49 insertions, 39 deletions
diff --git a/src/cstore/cstore-varref.cpp b/src/cstore/cstore-varref.cpp
index f00ed38..02bdb97 100644
--- a/src/cstore/cstore-varref.cpp
+++ b/src/cstore/cstore-varref.cpp
@@ -225,7 +225,7 @@ bool
Cstore::VarRef::getValue(string& value, vtw_type_e& def_type)
{
vector<string> result;
- map<string, bool> added;
+ Cstore::MapT<string, bool> added;
def_type = ERROR_TYPE;
for (size_t i = 0; i < _paths.size(); i++) {
if (_paths[i].first.size() == 0) {
diff --git a/src/cstore/cstore.cpp b/src/cstore/cstore.cpp
index 2c30207..25eaae7 100644
--- a/src/cstore/cstore.cpp
+++ b/src/cstore/cstore.cpp
@@ -21,7 +21,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-#include <map>
#include <algorithm>
#include <sstream>
@@ -62,10 +61,14 @@ const string Cstore::C_ENV_SHAPI_HELP_STRS = "_cli_shell_api_hstrs";
const string Cstore::C_ENUM_SCRIPT_DIR = "/opt/vyatta/share/enumeration";
const string Cstore::C_LOGFILE_STDOUT = "/tmp/cfg-stdout.log";
+//// sorting
+const unsigned int Cstore::SORT_DEFAULT = 0;
+const unsigned int Cstore::SORT_DEB_VERSION = 0;
+const unsigned int Cstore::SORT_NONE = 1;
////// static
bool Cstore::_init = false;
-map<Cstore::SortAlgT, Cstore::SortFuncT> Cstore::_sort_func_map;
+Cstore::MapT<unsigned int, Cstore::SortFuncT> Cstore::_sort_func_map;
////// constructors/destructors
@@ -121,7 +124,7 @@ Cstore::validateTmplPath(const vector<string>& path_comps, bool validate_vals,
*/
bool
Cstore::getParsedTmpl(const vector<string>& path_comps,
- map<string, string>& tmap, bool allow_val)
+ Cstore::MapT<string, string>& tmap, bool allow_val)
{
vtw_def def;
/* currently this function is used outside actual CLI operations, mainly
@@ -1099,7 +1102,7 @@ Cstore::cfgPathGetDeletedChildNodesDA(const vector<string>& path_comps,
cfgPathGetChildNodesDA(path_comps, acnodes, true, include_deactivated);
vector<string> wcnodes;
cfgPathGetChildNodesDA(path_comps, wcnodes, false, include_deactivated);
- map<string, bool> cmap;
+ MapT<string, bool> cmap;
for (size_t i = 0; i < wcnodes.size(); i++) {
cmap[wcnodes[i]] = true;
}
@@ -1138,7 +1141,7 @@ Cstore::cfgPathGetDeletedValuesDA(const vector<string>& path_comps,
|| !cfgPathGetValuesDA(path_comps, nvals, false, include_deactivated)) {
return;
}
- map<string, bool> dmap;
+ MapT<string, bool> dmap;
for (size_t i = 0; i < nvals.size(); i++) {
dmap[nvals[i]] = true;
}
@@ -1159,11 +1162,11 @@ Cstore::cfgPathGetDeletedValuesDA(const vector<string>& path_comps,
*/
void
Cstore::cfgPathGetChildNodesStatus(const vector<string>& path_comps,
- map<string, string>& cmap,
+ Cstore::MapT<string, string>& cmap,
vector<string>& sorted_keys)
{
// get a union of active and working
- map<string, bool> umap;
+ MapT<string, bool> umap;
vector<string> acnodes;
vector<string> wcnodes;
cfgPathGetChildNodes(path_comps, acnodes, true);
@@ -1177,7 +1180,7 @@ Cstore::cfgPathGetChildNodesStatus(const vector<string>& path_comps,
// get the status of each one
vector<string> ppath = path_comps;
- map<string, bool>::iterator it = umap.begin();
+ MapT<string, bool>::iterator it = umap.begin();
for (; it != umap.end(); ++it) {
string c = (*it).first;
ppath.push_back(c);
@@ -1204,7 +1207,7 @@ Cstore::cfgPathGetChildNodesStatus(const vector<string>& path_comps,
*/
void
Cstore::cfgPathGetChildNodesStatusDA(const vector<string>& path_comps,
- map<string, string>& cmap,
+ Cstore::MapT<string, string>& cmap,
vector<string>& sorted_keys)
{
// process deleted nodes first
@@ -1574,7 +1577,7 @@ Cstore::cfgPathGetEffectiveChildNodes(const vector<string>& path_comps,
}
// get a union of active and working
- map<string, bool> cmap;
+ MapT<string, bool> cmap;
vector<string> acnodes;
vector<string> wcnodes;
cfgPathGetChildNodes(path_comps, acnodes, true);
@@ -1588,7 +1591,7 @@ Cstore::cfgPathGetEffectiveChildNodes(const vector<string>& path_comps,
// get only the effective ones from the union
vector<string> ppath = path_comps;
- map<string, bool>::iterator it = cmap.begin();
+ MapT<string, bool>::iterator it = cmap.begin();
for (; it != cmap.end(); ++it) {
string c = (*it).first;
ppath.push_back(c);
@@ -1660,7 +1663,7 @@ Cstore::cfgPathGetEffectiveValues(const vector<string>& path_comps,
}
// get a union of active and working
- map<string, bool> vmap;
+ MapT<string, bool> vmap;
vector<string> ovals;
vector<string> nvals;
cfgPathGetValues(path_comps, ovals, true);
@@ -1674,7 +1677,7 @@ Cstore::cfgPathGetEffectiveValues(const vector<string>& path_comps,
// get only the effective ones from the union
vector<string> ppath = path_comps;
- map<string, bool>::iterator it = vmap.begin();
+ MapT<string, bool>::iterator it = vmap.begin();
for (; it != vmap.end(); ++it) {
string c = (*it).first;
ppath.push_back(c);
@@ -1907,7 +1910,7 @@ Cstore::sort_func_deb_version(string a, string b)
}
void
-Cstore::sort_nodes(vector<string>& nvec, Cstore::SortAlgT sort_alg)
+Cstore::sort_nodes(vector<string>& nvec, unsigned int sort_alg)
{
if (_sort_func_map.find(sort_alg) == _sort_func_map.end()) {
return;
diff --git a/src/cstore/cstore.hpp b/src/cstore/cstore.hpp
index 8cb3fd1..5da07fd 100644
--- a/src/cstore/cstore.hpp
+++ b/src/cstore/cstore.hpp
@@ -18,7 +18,7 @@
#define _CSTORE_H_
#include <vector>
#include <string>
-#include <map>
+#include <tr1/unordered_map>
#include <cli_cstore.h>
@@ -42,6 +42,10 @@ public:
Cstore(string& env);
virtual ~Cstore() {};
+ // types
+ template<class K, class V>
+ class MapT : public tr1::unordered_map<K, V> {};
+
// constants
static const string C_NODE_STATUS_DELETED;
static const string C_NODE_STATUS_ADDED;
@@ -74,7 +78,7 @@ public:
bool validateTmplPath(const vector<string>& path_comps, bool validate_vals,
vtw_def& def);
bool getParsedTmpl(const vector<string>& path_comps,
- map<string, string>& tmap, bool allow_val = true);
+ MapT<string, string>& tmap, bool allow_val = true);
void tmplGetChildNodes(const vector<string>& path_comps,
vector<string>& cnodes);
@@ -187,12 +191,12 @@ public:
void cfgPathGetDeletedValues(const vector<string>& path_comps,
vector<string>& dvals);
void cfgPathGetChildNodesStatus(const vector<string>& path_comps,
- map<string, string>& cmap) {
+ MapT<string, string>& cmap) {
vector<string> dummy;
cfgPathGetChildNodesStatus(path_comps, cmap, dummy);
};
void cfgPathGetChildNodesStatus(const vector<string>& path_comps,
- map<string, string>& cmap,
+ MapT<string, string>& cmap,
vector<string>& sorted_keys);
/* observers for "effective config". can be used both during a config
@@ -251,12 +255,12 @@ public:
vector<string>& dvals,
bool include_deactivated = true);
void cfgPathGetChildNodesStatusDA(const vector<string>& path_comps,
- map<string, string>& cmap) {
+ MapT<string, string>& cmap) {
vector<string> dummy;
cfgPathGetChildNodesStatusDA(path_comps, cmap, dummy);
};
void cfgPathGetChildNodesStatusDA(const vector<string>& path_comps,
- map<string, string>& cmap,
+ MapT<string, string>& cmap,
vector<string>& sorted_keys);
@@ -363,16 +367,18 @@ private:
////// implemented
// for sorting
- typedef enum {
- SORT_DEFAULT = 0,
- SORT_DEB_VERSION = 0,
- SORT_NONE
- } SortAlgT;
+ /* apparently unordered_map template does not work with "enum" type, so
+ * change this to simply unsigned ints to allow unifying all map types,
+ * i.e., "Cstore::MapT".
+ */
+ static const unsigned int SORT_DEFAULT;
+ static const unsigned int SORT_DEB_VERSION;
+ static const unsigned int SORT_NONE;
typedef bool (*SortFuncT)(std::string, std::string);
- static map<SortAlgT, SortFuncT> _sort_func_map;
+ static MapT<unsigned int, 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);
+ void sort_nodes(vector<string>& nvec, unsigned int sort_alg = SORT_DEFAULT);
// init
static bool _init;
diff --git a/src/cstore/unionfs/cstore-unionfs.cpp b/src/cstore/unionfs/cstore-unionfs.cpp
index 5cfd8ee..849d659 100644
--- a/src/cstore/unionfs/cstore-unionfs.cpp
+++ b/src/cstore/unionfs/cstore-unionfs.cpp
@@ -17,7 +17,6 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
-#include <map>
#include <fstream>
#include <sstream>
@@ -63,8 +62,8 @@ const string UnionfsCstore::C_DEF_NAME = "node.def";
////// static
-static map<char, string> _fs_escape_chars;
-static map<string, char> _fs_unescape_chars;
+static Cstore::MapT<char, string> _fs_escape_chars;
+static Cstore::MapT<string, char> _fs_unescape_chars;
static void
_init_fs_escape_chars()
{
@@ -80,7 +79,7 @@ _init_fs_escape_chars()
static string
_escape_char(char c)
{
- map<char, string>::iterator p = _fs_escape_chars.find(c);
+ Cstore::MapT<char, string>::iterator p = _fs_escape_chars.find(c);
if (p != _fs_escape_chars.end()) {
return _fs_escape_chars[c];
} else {
@@ -88,12 +87,13 @@ _escape_char(char c)
}
}
-static map<string, string> _escape_path_name_cache;
+static Cstore::MapT<string, string> _escape_path_name_cache;
static string
_escape_path_name(const string& path)
{
- map<string, string>::iterator p = _escape_path_name_cache.find(path);
+ Cstore::MapT<string, string>::iterator p
+ = _escape_path_name_cache.find(path);
if (p != _escape_path_name_cache.end()) {
// found escaped string in cache. just return it.
return _escape_path_name_cache[path];
@@ -110,12 +110,13 @@ _escape_path_name(const string& path)
return npath;
}
-static map<string, string> _unescape_path_name_cache;
+static Cstore::MapT<string, string> _unescape_path_name_cache;
static string
_unescape_path_name(const string& path)
{
- map<string, string>::iterator p = _unescape_path_name_cache.find(path);
+ Cstore::MapT<string, string>::iterator p
+ = _unescape_path_name_cache.find(path);
if (p != _unescape_path_name_cache.end()) {
// found unescaped string in cache. just return it.
return _unescape_path_name_cache[path];
@@ -129,7 +130,7 @@ _unescape_path_name(const string& path)
break;
}
string s = path.substr(i, 3);
- map<string, char>::iterator p = _fs_unescape_chars.find(s);
+ Cstore::MapT<string, char>::iterator p = _fs_unescape_chars.find(s);
if (p != _fs_unescape_chars.end()) {
char c = _fs_unescape_chars[s];
if (path.size() == 3 && c == -1) {
diff --git a/src/cstore/unionfs/cstore-unionfs.hpp b/src/cstore/unionfs/cstore-unionfs.hpp
index 90f28c5..3942e01 100644
--- a/src/cstore/unionfs/cstore-unionfs.hpp
+++ b/src/cstore/unionfs/cstore-unionfs.hpp
@@ -83,7 +83,7 @@ private:
// path buffers
b_fs::path mutable_cfg_path; // mutable part of config path
b_fs::path tmpl_path; // whole template path
- map<const void *, pair<b_fs::path, b_fs::path> > saved_paths;
+ Cstore::MapT<const void *, pair<b_fs::path, b_fs::path> > saved_paths;
// saved mutable part of cfg path and whole template path
////// virtual functions defined in base class
@@ -122,7 +122,7 @@ private:
saved_paths[handle] = p;
};
void restore_paths(const void *handle = NULL) {
- map<const void *, pair<b_fs::path, b_fs::path> >::iterator it
+ Cstore::MapT<const void *, pair<b_fs::path, b_fs::path> >::iterator it
= saved_paths.find(handle);
if (it == saved_paths.end()) {
exit_internal("restore_paths: handle not found\n");