summaryrefslogtreecommitdiff
path: root/src/cstore/svector.hpp
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2011-04-06 18:58:22 -0700
committerAn-Cheng Huang <ancheng@vyatta.com>2011-04-06 18:58:22 -0700
commitfcdc4ad086945f8a947c2ede2f87bc8d549bcae0 (patch)
treec5741ab4bfd5b8e3ffd9e0524d241cdcc63f5419 /src/cstore/svector.hpp
parentff6dbf4361fe64ed00478e98f895d3bd15248869 (diff)
downloadvyatta-cfg-fcdc4ad086945f8a947c2ede2f87bc8d549bcae0.tar.gz
vyatta-cfg-fcdc4ad086945f8a947c2ede2f87bc8d549bcae0.zip
minor refactoring
Diffstat (limited to 'src/cstore/svector.hpp')
-rw-r--r--src/cstore/svector.hpp27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/cstore/svector.hpp b/src/cstore/svector.hpp
index fd63297..bc04fdc 100644
--- a/src/cstore/svector.hpp
+++ b/src/cstore/svector.hpp
@@ -21,14 +21,9 @@
#include <string>
#include <tr1/functional>
-namespace cstore {
+#include <cstore/util.hpp>
-template<int v>
-struct Int2Type {
- enum {
- value = v
- };
-};
+namespace cstore {
template<class P>
class svector {
@@ -88,6 +83,9 @@ public:
size_t hash() const {
return std::tr1::_Fnv_hash<sizeof(size_t)>::hash(_data, _len);
};
+ std::string to_string() const {
+ return to_string(Int2Type<RAW_CSTR_DATA>());
+ };
private:
size_t _num_elems;
@@ -117,7 +115,20 @@ private:
};
const char *elem_at(size_t idx, Int2Type<true>) const {
return (idx < _num_elems ? (_elems[idx] + 1) : NULL);
- }
+ };
+ std::string to_string(Int2Type<true>) const {
+ return std::string(_data);
+ };
+ std::string to_string(Int2Type<false>) const {
+ std::string ret;
+ for (size_t i = 0; i < size(); i++) {
+ if (i > 0) {
+ ret += " ";
+ }
+ ret += elem_at(i, Int2Type<RANDOM_ACCESS>());
+ }
+ return ret;
+ };
};
template<class P>