#ifndef STOPOS_KEY_H #define STOPOS_KEY_H #include #include class stopos_key { protected: std::string value; static const char firstchar = 'a'; static const char lastchar = 'z'; static const unsigned int base = lastchar - firstchar + 1; template void tostring1(std::string &v,const T n) { if (n == 0) return; unsigned int c = n + firstchar - base*(n/base); tostring1(v,n/base); v.push_back(c); } template void tostring(std::string &v,const T n) { if (n == 0) v = firstchar; else tostring1(v,n); } public: stopos_key(); stopos_key(const std::string &s); void increment(void); std::string str(void) const; void impossible(); bool operator==(const stopos_key &k) const; bool operator!=(const stopos_key &k) const; // to assign an unsigned integer value to a key template void set(const T k) { this->value = ""; this->tostring(this->value,k); return; } // to get the unsigned integer value from a key template T get() const { T r = 0; for (unsigned int i=0; ivalue.size(); i++) r = this->base*r + this->value[i]-this->firstchar; return r; } }; #endif