|
| 1 | +/* |
| 2 | + * Copyright 2010-2020 [email protected](http://datasys.cs.iit.edu/index.html) |
| 3 | + * Director: Ioan Raicu([email protected]) |
| 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 | + * This file is part of ZHT library(http://datasys.cs.iit.edu/projects/ZHT/index.html). |
| 18 | + * Tonglin Li([email protected]) with nickname Tony, |
| 19 | + * Xiaobing Zhou([email protected]) with nickname Xiaobingo, |
| 20 | + * Ke Wang([email protected]) with nickname KWang, |
| 21 | + * Dongfang Zhao(dzhao8@@hawk.iit.edu) with nickname DZhao, |
| 22 | + |
| 23 | + * |
| 24 | + * ConfEntry.cpp |
| 25 | + * |
| 26 | + * Created on: Aug 7, 2012 |
| 27 | + * Author: Xiaobingo |
| 28 | + * Contributor: Tony, KWang, DZhao |
| 29 | + */ |
| 30 | + |
| 31 | +#include "ConfEntry.h" |
| 32 | + |
| 33 | +#include "Const-impl.h" |
| 34 | + |
| 35 | +#include <stdio.h> |
| 36 | +#include <string.h> |
| 37 | + |
| 38 | +namespace iit { |
| 39 | +namespace datasys { |
| 40 | +namespace zht { |
| 41 | +namespace dm { |
| 42 | + |
| 43 | +ConfEntry::ConfEntry() { |
| 44 | + |
| 45 | +} |
| 46 | + |
| 47 | +ConfEntry::ConfEntry(const string& sconfigEntry) { |
| 48 | + |
| 49 | + assign(sconfigEntry); |
| 50 | +} |
| 51 | + |
| 52 | +ConfEntry::ConfEntry(const string& name, const string& value) : |
| 53 | + _name(name), _value(value) { |
| 54 | + |
| 55 | +} |
| 56 | + |
| 57 | +ConfEntry::~ConfEntry() { |
| 58 | + |
| 59 | +} |
| 60 | + |
| 61 | +string ConfEntry::name() const { |
| 62 | + |
| 63 | + return _name; |
| 64 | +} |
| 65 | + |
| 66 | +void ConfEntry::name(const string& name) { |
| 67 | + |
| 68 | + _name = name; |
| 69 | +} |
| 70 | + |
| 71 | +string ConfEntry::value() const { |
| 72 | + |
| 73 | + return _value; |
| 74 | +} |
| 75 | + |
| 76 | +void ConfEntry::value(const string& value) { |
| 77 | + |
| 78 | + _value = value; |
| 79 | +} |
| 80 | + |
| 81 | +string ConfEntry::operator()() const { |
| 82 | + |
| 83 | + return toString(); |
| 84 | +} |
| 85 | + |
| 86 | +string ConfEntry::toString() const { |
| 87 | + |
| 88 | + char buf[50]; |
| 89 | + memset(buf, 0, sizeof(buf)); |
| 90 | + int n = sprintf(buf, getFormat().c_str(), _name.c_str(), _value.c_str()); |
| 91 | + |
| 92 | + string result(buf, 0, n); |
| 93 | + |
| 94 | + return result; |
| 95 | +} |
| 96 | + |
| 97 | +ConfEntry& ConfEntry::assign(string sconfigEntry) { |
| 98 | + |
| 99 | + const char* delimiter = ","; |
| 100 | + |
| 101 | + string remains = Const::trim(sconfigEntry); |
| 102 | + |
| 103 | + size_t found = remains.find(delimiter); |
| 104 | + |
| 105 | + if (found != string::npos) { |
| 106 | + |
| 107 | + name(Const::trim(remains.substr(0, int(found)))); |
| 108 | + value(Const::trim(remains.substr(int(found) + 1))); |
| 109 | + } |
| 110 | + |
| 111 | + return *this; |
| 112 | +} |
| 113 | + |
| 114 | +string ConfEntry::getFormat() { |
| 115 | + |
| 116 | + return "%s,%s"; |
| 117 | +} |
| 118 | + |
| 119 | +} /* namespace dm */ |
| 120 | +} /* namespace zht */ |
| 121 | +} /* namespace datasys */ |
| 122 | +} /* namespace iit */ |
0 commit comments