X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=laserbrain_demo;a=blobdiff_plain;f=src%2Fdatamap.cc;h=e466082ec0949500bbe5b47c1b8732cf21be396a;hp=ee7de5121a5bbcc0afd9e9f61890f6b6e743b8da;hb=b30241a8a51be904b22459a1d0cc3322e0a505d9;hpb=21f74bf587d9b7a76bc1ee83db02cb8c243dc567 diff --git a/src/datamap.cc b/src/datamap.cc index ee7de51..e466082 100644 --- a/src/datamap.cc +++ b/src/datamap.cc @@ -1,10 +1,6 @@ #include #include #include -#include -#include -#include -//#include #include "datamap.h" #ifdef WIN32 @@ -15,23 +11,18 @@ static char *clean_line(char *s); -//static std::vector> dmap; -static std::vector> dmap; -static std::map cache; -static std::string root; - -void datamap_reset() +void DataMap::clear() { dmap.clear(); cache.clear(); } -void datamap_set_path(const char *path) +void DataMap::set_path(const char *path) { root = std::string(path); } -bool datamap_load_map(const char *fname) +bool DataMap::load_map(const char *fname) { std::string path = root.empty() ? fname : root + std::string("/") + fname; fname = path.c_str(); @@ -49,7 +40,7 @@ bool datamap_load_map(const char *fname) return false; } - datamap_reset(); + clear(); char *line; int nline = 0; @@ -83,22 +74,20 @@ bool datamap_load_map(const char *fname) err: fprintf(stderr, "error while parsing %s, invalid line %d: %s\n", fname, nline, line); - datamap_reset(); + clear(); fclose(fp); return false; } -void datamap_map(const char *re, const char *path) +void DataMap::map(const char *match, const char *path) { - //std::pair mapping; - //mapping.first = std::regex(re); std::pair mapping; - mapping.first = std::string(re); + mapping.first = std::string(match); mapping.second = std::string(path); dmap.push_back(std::move(mapping)); } -int datamap_lookup(const char *in, char *buf, int bsz) +int DataMap::lookup(const char *in, char *buf, int bsz) const { std::string res; @@ -135,9 +124,9 @@ int datamap_lookup(const char *in, char *buf, int bsz) return res.length() + 1; } -int datamap_path_size(const char *in) +int DataMap::path_size(const char *in) const { - return datamap_lookup(in, 0, 0); + return lookup(in, 0, 0); } static char *clean_line(char *s)