[7] | 1 | |
---|
| 2 | /* |
---|
| 3 | Copyright 2013 Willem Vermin, SURFsara |
---|
| 4 | |
---|
| 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
---|
| 6 | you may not use this file except in compliance with the License. |
---|
| 7 | You may obtain a copy of the License at |
---|
| 8 | |
---|
| 9 | http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 10 | |
---|
| 11 | Unless required by applicable law or agreed to in writing, software |
---|
| 12 | distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 14 | See the License for the specific language governing permissions and |
---|
| 15 | limitations under the License. |
---|
| 16 | */ |
---|
| 17 | #include <string> |
---|
| 18 | #include <vector> |
---|
| 19 | #include "stopos.h" |
---|
| 20 | #include "wutils.h" |
---|
| 21 | #include "stopos_key.h" |
---|
| 22 | |
---|
| 23 | // constructor |
---|
| 24 | stopos_key::stopos_key() |
---|
| 25 | { |
---|
| 26 | this->set(0,""); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | stopos_key::stopos_key(const std::string & s) |
---|
| 30 | { |
---|
| 31 | std::vector <std::string> v; |
---|
| 32 | v = split(v,s,keysep); |
---|
| 33 | this->value = v[0]; |
---|
| 34 | if (v.size()>1) |
---|
| 35 | this->slot = v[1]; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | void stopos_key::impossible() |
---|
| 39 | { |
---|
| 40 | this->value="%%%%"; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | void stopos_key::increment(void) |
---|
| 44 | { // notused |
---|
| 45 | int p = this->value.size(); |
---|
| 46 | while(1) |
---|
| 47 | { |
---|
| 48 | p--; |
---|
| 49 | if (this->value[p] == lastchar) |
---|
| 50 | { |
---|
| 51 | this->value[p] = firstchar; |
---|
| 52 | if (p == 0) |
---|
| 53 | { |
---|
| 54 | this->value = firstchar + this->value; |
---|
| 55 | p = 1; |
---|
| 56 | } |
---|
| 57 | } |
---|
| 58 | else |
---|
| 59 | { |
---|
| 60 | this->value[p] ++; |
---|
| 61 | break; |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | std::string stopos_key::str(void) const |
---|
| 67 | { |
---|
| 68 | if (this->slot == "") |
---|
| 69 | return value; |
---|
| 70 | |
---|
| 71 | return this->value+keysep+this->slot; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | std::string stopos_key::get_key(void) const |
---|
| 75 | { |
---|
| 76 | return this->value; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | std::string stopos_key::get_slot(void) const |
---|
| 80 | { |
---|
| 81 | return this->slot; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | bool stopos_key::operator==(const stopos_key &k) const |
---|
| 85 | { |
---|
| 86 | return k.value == this->value; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | bool stopos_key::operator!=(const stopos_key &k) const |
---|
| 90 | { |
---|
| 91 | return k.value != this->value; |
---|
| 92 | } |
---|
| 93 | |
---|