Commit 13c65b49 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

namespace related cleanups


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1408 e5f2f494-b856-4b98-b285-d166d9295462
parent ad2c089b
...@@ -43,7 +43,11 @@ const unsigned char ITEM_LENGTH_16 = 0x10; ...@@ -43,7 +43,11 @@ const unsigned char ITEM_LENGTH_16 = 0x10;
const unsigned char ITEM_LENGTH_8 = 0x20; const unsigned char ITEM_LENGTH_8 = 0x20;
const unsigned char ITEM_LENGTH_MASK = 0x30; const unsigned char ITEM_LENGTH_MASK = 0x30;
static inline void namespace isc {
namespace data {
namespace {
inline void
throwParseError(const std::string& error, const std::string& file, int line = 0, int pos = 0) throwParseError(const std::string& error, const std::string& file, int line = 0, int pos = 0)
{ {
if (line != 0 || pos != 0) { if (line != 0 || pos != 0) {
...@@ -54,6 +58,7 @@ throwParseError(const std::string& error, const std::string& file, int line = 0, ...@@ -54,6 +58,7 @@ throwParseError(const std::string& error, const std::string& file, int line = 0,
throw ParseError(error); throw ParseError(error);
} }
} }
}
std::ostream& operator <<(std::ostream &out, const isc::data::ElementPtr& e) { std::ostream& operator <<(std::ostream &out, const isc::data::ElementPtr& e) {
return out << e->str(); return out << e->str();
...@@ -124,8 +129,8 @@ Element::create(const std::map<std::string, ElementPtr>& m) { ...@@ -124,8 +129,8 @@ Element::create(const std::map<std::string, ElementPtr>& m) {
// //
// helper functions for createFromString factory // helper functions for createFromString factory
// //
namespace {
static bool bool
char_in(const char c, const char *chars) { char_in(const char c, const char *chars) {
for (size_t i = 0; i < strlen(chars); ++i) { for (size_t i = 0; i < strlen(chars); ++i) {
if (chars[i] == c) { if (chars[i] == c) {
...@@ -135,7 +140,7 @@ char_in(const char c, const char *chars) { ...@@ -135,7 +140,7 @@ char_in(const char c, const char *chars) {
return false; return false;
} }
static void void
skip_chars(std::istream &in, const char *chars, int& line, int& pos) { skip_chars(std::istream &in, const char *chars, int& line, int& pos) {
char c = in.peek(); char c = in.peek();
while (char_in(c, chars) && c != EOF) { while (char_in(c, chars) && c != EOF) {
...@@ -155,7 +160,7 @@ skip_chars(std::istream &in, const char *chars, int& line, int& pos) { ...@@ -155,7 +160,7 @@ skip_chars(std::istream &in, const char *chars, int& line, int& pos) {
// unless that character is specified in the optional may_skip // unless that character is specified in the optional may_skip
// //
// the character found is left on the stream // the character found is left on the stream
static void void
skip_to(std::istream &in, const std::string& file, int& line, skip_to(std::istream &in, const std::string& file, int& line,
int& pos, const char* chars, const char* may_skip="") int& pos, const char* chars, const char* may_skip="")
{ {
...@@ -188,7 +193,7 @@ skip_to(std::istream &in, const std::string& file, int& line, ...@@ -188,7 +193,7 @@ skip_to(std::istream &in, const std::string& file, int& line,
throwParseError(std::string("EOF read, one of \"") + chars + "\" expected", file, line, pos); throwParseError(std::string("EOF read, one of \"") + chars + "\" expected", file, line, pos);
} }
static std::string std::string
str_from_stringstream(std::istream &in, const std::string& file, int& line, int& pos) throw (ParseError) str_from_stringstream(std::istream &in, const std::string& file, int& line, int& pos) throw (ParseError)
{ {
char c = 0; char c = 0;
...@@ -213,7 +218,7 @@ str_from_stringstream(std::istream &in, const std::string& file, int& line, int& ...@@ -213,7 +218,7 @@ str_from_stringstream(std::istream &in, const std::string& file, int& line, int&
return ss.str(); return ss.str();
} }
static std::string std::string
word_from_stringstream(std::istream &in, int& line, int& pos) { word_from_stringstream(std::istream &in, int& line, int& pos) {
std::stringstream ss; std::stringstream ss;
while (isalpha(in.peek())) { while (isalpha(in.peek())) {
...@@ -223,7 +228,7 @@ word_from_stringstream(std::istream &in, int& line, int& pos) { ...@@ -223,7 +228,7 @@ word_from_stringstream(std::istream &in, int& line, int& pos) {
return ss.str(); return ss.str();
} }
static inline int inline int
count_chars_i(int i) { count_chars_i(int i) {
int result = 1; int result = 1;
while (i > 10) { while (i > 10) {
...@@ -233,7 +238,7 @@ count_chars_i(int i) { ...@@ -233,7 +238,7 @@ count_chars_i(int i) {
return result; return result;
} }
static inline int inline int
count_chars_d(double d) { count_chars_d(double d) {
int result = 1; int result = 1;
while (d < 1.0) { while (d < 1.0) {
...@@ -243,7 +248,7 @@ count_chars_d(double d) { ...@@ -243,7 +248,7 @@ count_chars_d(double d) {
return result; return result;
} }
static ElementPtr ElementPtr
from_stringstream_int_or_double(std::istream &in, int &line, int &pos) { from_stringstream_int_or_double(std::istream &in, int &line, int &pos) {
int i; int i;
in >> i; in >> i;
...@@ -259,7 +264,7 @@ from_stringstream_int_or_double(std::istream &in, int &line, int &pos) { ...@@ -259,7 +264,7 @@ from_stringstream_int_or_double(std::istream &in, int &line, int &pos) {
} }
} }
static ElementPtr ElementPtr
from_stringstream_bool(std::istream &in, const std::string& file, int& line, int& pos) from_stringstream_bool(std::istream &in, const std::string& file, int& line, int& pos)
{ {
const std::string word = word_from_stringstream(in, line, pos); const std::string word = word_from_stringstream(in, line, pos);
...@@ -274,13 +279,13 @@ from_stringstream_bool(std::istream &in, const std::string& file, int& line, int ...@@ -274,13 +279,13 @@ from_stringstream_bool(std::istream &in, const std::string& file, int& line, int
} }
} }
static ElementPtr ElementPtr
from_stringstream_string(std::istream& in, const std::string& file, int& line, int& pos) from_stringstream_string(std::istream& in, const std::string& file, int& line, int& pos)
{ {
return Element::create(str_from_stringstream(in, file, line, pos)); return Element::create(str_from_stringstream(in, file, line, pos));
} }
static ElementPtr ElementPtr
from_stringstream_list(std::istream &in, const std::string& file, int& line, int& pos) from_stringstream_list(std::istream &in, const std::string& file, int& line, int& pos)
{ {
char c = 0; char c = 0;
...@@ -300,7 +305,7 @@ from_stringstream_list(std::istream &in, const std::string& file, int& line, int ...@@ -300,7 +305,7 @@ from_stringstream_list(std::istream &in, const std::string& file, int& line, int
return Element::create(v); return Element::create(v);
} }
static ElementPtr ElementPtr
from_stringstream_map(std::istream &in, const std::string& file, int& line, int& pos) from_stringstream_map(std::istream &in, const std::string& file, int& line, int& pos)
{ {
char c = 0; char c = 0;
...@@ -329,6 +334,7 @@ from_stringstream_map(std::istream &in, const std::string& file, int& line, int& ...@@ -329,6 +334,7 @@ from_stringstream_map(std::istream &in, const std::string& file, int& line, int&
} }
return Element::create(m); return Element::create(m);
} }
}
ElementPtr ElementPtr
Element::createFromString(std::istream& in) throw(ParseError) { Element::createFromString(std::istream& in) throw(ParseError) {
...@@ -511,10 +517,10 @@ MapElement::find(const std::string& id) { ...@@ -511,10 +517,10 @@ MapElement::find(const std::string& id) {
// //
// Decode from wire format. // Decode from wire format.
// //
namespace {
ElementPtr decode_element(std::stringstream& in, int& in_length); ElementPtr decode_element(std::stringstream& in, int& in_length);
static unsigned char unsigned char
get_byte(std::stringstream& in) { get_byte(std::stringstream& in) {
const int c = in.get(); const int c = in.get();
if (c == EOF) { if (c == EOF) {
...@@ -687,6 +693,7 @@ decode_element(std::stringstream& in, int& in_length) { ...@@ -687,6 +693,7 @@ decode_element(std::stringstream& in, int& in_length) {
return (element); return (element);
} }
}
ElementPtr ElementPtr
Element::fromWire(const std::string& s) { Element::fromWire(const std::string& s) {
...@@ -805,12 +812,14 @@ ListElement::toWire(std::stringstream& ss, const int omit_length) { ...@@ -805,12 +812,14 @@ ListElement::toWire(std::stringstream& ss, const int omit_length) {
} }
} }
namespace {
void void
encode_tag(std::stringstream& ss, const std::string &s) { encode_tag(std::stringstream& ss, const std::string &s) {
const unsigned char val = s.length() & 0x000000ff; const unsigned char val = s.length() & 0x000000ff;
ss << val << s; ss << val << s;
} }
}
void void
MapElement::toWire(std::stringstream& ss, int omit_length) { MapElement::toWire(std::stringstream& ss, int omit_length) {
...@@ -939,12 +948,12 @@ MapElement::equals(ElementPtr other) { ...@@ -939,12 +948,12 @@ MapElement::equals(ElementPtr other) {
} }
bool bool
isc::data::isNull(ElementPtr p) { isNull(ElementPtr p) {
return !p; return !p;
} }
void void
isc::data::removeIdentical(ElementPtr a, const ElementPtr b) { removeIdentical(ElementPtr a, const ElementPtr b) {
if (!b) { if (!b) {
return; return;
} }
...@@ -964,7 +973,7 @@ isc::data::removeIdentical(ElementPtr a, const ElementPtr b) { ...@@ -964,7 +973,7 @@ isc::data::removeIdentical(ElementPtr a, const ElementPtr b) {
} }
void void
isc::data::merge(ElementPtr element, const ElementPtr other) { merge(ElementPtr element, const ElementPtr other) {
if (element->getType() != Element::map || if (element->getType() != Element::map ||
other->getType() != Element::map) { other->getType() != Element::map) {
isc_throw(TypeError, "merge arguments not MapElements"); isc_throw(TypeError, "merge arguments not MapElements");
...@@ -981,3 +990,5 @@ isc::data::merge(ElementPtr element, const ElementPtr other) { ...@@ -981,3 +990,5 @@ isc::data::merge(ElementPtr element, const ElementPtr other) {
} }
} }
}
}
...@@ -492,8 +492,6 @@ void removeIdentical(ElementPtr a, const ElementPtr b); ...@@ -492,8 +492,6 @@ void removeIdentical(ElementPtr a, const ElementPtr b);
/// Raises a TypeError if either ElementPtr is not a MapElement /// Raises a TypeError if either ElementPtr is not a MapElement
void merge(ElementPtr element, const ElementPtr other); void merge(ElementPtr element, const ElementPtr other);
} }
/// ///
/// \brief Insert the Element as a string into stream. /// \brief Insert the Element as a string into stream.
/// ///
...@@ -512,6 +510,7 @@ void merge(ElementPtr element, const ElementPtr other); ...@@ -512,6 +510,7 @@ void merge(ElementPtr element, const ElementPtr other);
std::ostream& operator <<(std::ostream &out, const isc::data::ElementPtr& e); std::ostream& operator <<(std::ostream &out, const isc::data::ElementPtr& e);
bool operator==(const isc::data::ElementPtr a, const isc::data::ElementPtr b); bool operator==(const isc::data::ElementPtr a, const isc::data::ElementPtr b);
} }
#endif // _ISC_DATA_H #endif // _ISC_DATA_H
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment