2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
21 #ifndef __STG_STGLIBS_SRVCONF_RESETABLE_UTILS_H__
22 #define __STG_STGLIBS_SRVCONF_RESETABLE_UTILS_H__
24 #include "stg/resetable.h"
25 #include "stg/common.h"
35 void appendTag(std::ostream & stream, const std::string & name, const T & value)
37 stream << "<" << name << " value=\"" << value << "\"/>";
42 void appendTag(std::ostream & stream, const std::string & name, size_t suffix, const T & value)
44 stream << "<" << name << suffix << " value=\"" << value << "\"/>";
49 void appendTag<uint8_t>(std::ostream & stream, const std::string & name, const uint8_t & value)
51 stream << "<" << name << " value=\"" << static_cast<unsigned>(value) << "\"/>";
56 void appendTag<int8_t>(std::ostream & stream, const std::string & name, const int8_t & value)
58 stream << "<" << name << " value=\"" << static_cast<int>(value) << "\"/>";
63 void appendAttr(std::ostream & stream, const std::string & name, const T & value)
65 stream << " " << name << "=\"" << value << "\"";
70 void appendAttr(std::ostream & stream, const std::string & name, size_t suffix, const T & value)
72 stream << " " << name << suffix << "=\"" << value << "\"";
77 void appendAttr<uint8_t>(std::ostream & stream, const std::string & name, const uint8_t & value)
79 stream << " " << name << "=\"" << static_cast<unsigned>(value) << "\"";
84 void appendAttr<int8_t>(std::ostream & stream, const std::string & name, const int8_t & value)
86 stream << " " << name << "=\"" << static_cast<int>(value) << "\"";
91 void appendResetableTag(std::ostream & stream, const std::string & name, const T & value)
94 appendTag(stream, name, value.const_data());
99 void appendResetableTag(std::ostream & stream, const std::string & name, size_t suffix, const T & value)
102 appendTag(stream, name, suffix, value.const_data());
105 template <typename T>
107 void appendResetableAttr(std::ostream & stream, const std::string & name, const T & value)
110 appendAttr(stream, name, value.const_data());
113 template <typename T>
115 void appendResetableAttr(std::ostream & stream, const std::string & name, size_t suffix, const T & value)
118 appendAttr(stream, name, suffix, value.const_data());
122 RESETABLE<std::string> MaybeEncode(const RESETABLE<std::string> & value)
124 RESETABLE<std::string> res;
126 res = Encode12str(value.data());
131 RESETABLE<std::string> MaybeIconv(const RESETABLE<std::string> & value, const std::string & fromEncoding, const std::string & toEncoding)
133 RESETABLE<std::string> res;
135 res = IconvString(value.data(), fromEncoding, toEncoding);