summaryrefslogtreecommitdiffstats
path: root/staging_vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2016-11-30 00:30:37 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2016-12-12 02:55:41 +0100
commit848672a85b9a553034e4ff46a52521e3ce681912 (patch)
tree5383b69bff5b732481689f3ec71625a348600431 /staging_vespalib
parent97cff7808649426865e0275f1c24058dbfd65940 (diff)
Do not include the excetions everywhere.
Diffstat (limited to 'staging_vespalib')
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt1
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/jsonexception.cpp18
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/jsonexception.h19
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/jsonstream.cpp3
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/jsonstream.h18
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/jsonwriter.cpp13
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/jsonwriter.h37
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/xmlserializable.cpp6
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/xmlserializable.h21
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/xmlserializable.hpp29
10 files changed, 98 insertions, 67 deletions
diff --git a/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt b/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt
index 8cf7e2239ad..43ef7a416d9 100644
--- a/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt
+++ b/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt
@@ -7,6 +7,7 @@ vespa_add_library(staging_vespalib_vespalib_util OBJECT
crc.cpp
doom.cpp
growablebytebuffer.cpp
+ jsonexception.cpp
jsonstream.cpp
jsonwriter.cpp
librarypool.cpp
diff --git a/staging_vespalib/src/vespa/vespalib/util/jsonexception.cpp b/staging_vespalib/src/vespa/vespalib/util/jsonexception.cpp
new file mode 100644
index 00000000000..d00fc7f3fb1
--- /dev/null
+++ b/staging_vespalib/src/vespa/vespalib/util/jsonexception.cpp
@@ -0,0 +1,18 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "jsonexception.h"
+
+namespace vespalib {
+
+VESPA_IMPLEMENT_EXCEPTION_SPINE(JsonStreamException);
+
+JsonStreamException::JsonStreamException(stringref reason, stringref history,
+ stringref location, int skipStack)
+ : Exception(reason + (history.empty() ? "" : "\nHistory:\n" + history),
+ location, skipStack + 1),
+ _reason(reason)
+{ }
+
+JsonStreamException::~JsonStreamException() { }
+
+}
diff --git a/staging_vespalib/src/vespa/vespalib/util/jsonexception.h b/staging_vespalib/src/vespa/vespalib/util/jsonexception.h
new file mode 100644
index 00000000000..db9873c0bb8
--- /dev/null
+++ b/staging_vespalib/src/vespa/vespalib/util/jsonexception.h
@@ -0,0 +1,19 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#pragma once
+
+#include <vespa/vespalib/util/exception.h>
+
+namespace vespalib {
+
+class JsonStreamException : public Exception {
+ string _reason;
+public:
+ JsonStreamException(stringref reason,
+ stringref history,
+ stringref location, int skipStack = 0);
+ stringref getReason() const { return _reason; }
+ VESPA_DEFINE_EXCEPTION_SPINE(JsonStreamException);
+ ~JsonStreamException();
+};
+
+}
diff --git a/staging_vespalib/src/vespa/vespalib/util/jsonstream.cpp b/staging_vespalib/src/vespa/vespalib/util/jsonstream.cpp
index da8e550a825..b90ce046606 100644
--- a/staging_vespalib/src/vespa/vespalib/util/jsonstream.cpp
+++ b/staging_vespalib/src/vespa/vespalib/util/jsonstream.cpp
@@ -1,12 +1,11 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "jsonstream.h"
+#include "jsonexception.h"
#include <vespa/vespalib/util/exceptions.h>
namespace vespalib {
-VESPA_IMPLEMENT_EXCEPTION_SPINE(JsonStreamException);
-
const char*
JsonStream::getStateName(const State& s) {
switch (s) {
diff --git a/staging_vespalib/src/vespa/vespalib/util/jsonstream.h b/staging_vespalib/src/vespa/vespalib/util/jsonstream.h
index adff9e505b9..c30ec8e08f2 100644
--- a/staging_vespalib/src/vespa/vespalib/util/jsonstream.h
+++ b/staging_vespalib/src/vespa/vespalib/util/jsonstream.h
@@ -8,28 +8,10 @@
* having to resort to template specialization.
*/
-#include <stack>
-#include <vespa/vespalib/util/exception.h>
#include <vespa/vespalib/util/jsonwriter.h>
namespace vespalib {
-class JsonStreamException : public Exception {
- vespalib::string _reason;
-public:
- JsonStreamException(vespalib::stringref reason,
- vespalib::stringref history,
- vespalib::stringref location, int skipStack = 0)
- : Exception(reason + (history.empty() ? "" : "\nHistory:\n" + history),
- location, skipStack + 1),
- _reason(reason)
- {
- }
- stringref getReason() const { return _reason; }
- VESPA_DEFINE_EXCEPTION_SPINE(JsonStreamException);
- virtual ~JsonStreamException() throw () { }
-};
-
// Inherit to refer to types without namespace prefix in header file.
struct JsonStreamTypes {
class Object {};
diff --git a/staging_vespalib/src/vespa/vespalib/util/jsonwriter.cpp b/staging_vespalib/src/vespa/vespalib/util/jsonwriter.cpp
index 48ab6d879d1..8306699516d 100644
--- a/staging_vespalib/src/vespa/vespalib/util/jsonwriter.cpp
+++ b/staging_vespalib/src/vespa/vespalib/util/jsonwriter.cpp
@@ -257,9 +257,9 @@ JSONWriter::appendJSON(const vespalib::stringref & json)
JSONStringer::JSONStringer() :
JSONWriter(),
- _oss()
+ _oss(std::make_unique<asciistream>())
{
- setOutputStream(_oss);
+ setOutputStream(*_oss);
}
JSONStringer &
@@ -267,8 +267,15 @@ JSONStringer::clear()
{
JSONWriter::clear();
// clear the string stream as well
- _oss.clear();
+ _oss->clear();
return *this;
}
+JSONStringer::~JSONStringer() { }
+
+stringref
+JSONStringer::toString() const {
+ return _oss->str();
+}
+
}
diff --git a/staging_vespalib/src/vespa/vespalib/util/jsonwriter.h b/staging_vespalib/src/vespa/vespalib/util/jsonwriter.h
index f63580c45d3..6016ad0a157 100644
--- a/staging_vespalib/src/vespa/vespalib/util/jsonwriter.h
+++ b/staging_vespalib/src/vespa/vespalib/util/jsonwriter.h
@@ -6,6 +6,8 @@
namespace vespalib {
+class asciistream;
+
/**
* If you want a simpler interface to write JSON with, look at the JsonStream
* class in the same directory as this class, this uses this class to make a
@@ -18,11 +20,11 @@ private:
OBJECT,
ARRAY
};
- vespalib::asciistream * _os;
- std::vector<State> _stack;
- bool _comma;
- bool _pretty;
- uint32_t _indent;
+ asciistream * _os;
+ std::vector<State> _stack;
+ bool _comma;
+ bool _pretty;
+ uint32_t _indent;
void push(State next);
void pop(State expected);
@@ -33,41 +35,42 @@ private:
public:
JSONWriter();
- JSONWriter(vespalib::asciistream & output);
+ JSONWriter(asciistream & output);
- JSONWriter & setOutputStream(vespalib::asciistream & output);
+ JSONWriter & setOutputStream(asciistream & output);
JSONWriter & clear();
JSONWriter & beginObject();
JSONWriter & endObject();
JSONWriter & beginArray();
JSONWriter & endArray();
JSONWriter & appendNull();
- JSONWriter & appendKey(const vespalib::stringref & str);
+ JSONWriter & appendKey(const stringref & str);
JSONWriter & appendBool(bool v);
JSONWriter & appendDouble(double v);
JSONWriter & appendFloat(float v);
JSONWriter & appendInt64(int64_t v);
JSONWriter & appendUInt64(uint64_t v);
- JSONWriter & appendString(const vespalib::stringref & str);
- JSONWriter & appendJSON(const vespalib::stringref & json);
+ JSONWriter & appendString(const stringref & str);
+ JSONWriter & appendJSON(const stringref & json);
void setPretty() { _pretty = true; };
};
class JSONStringer : public JSONWriter {
private:
- vespalib::asciistream _oss;
+ std::unique_ptr<asciistream> _oss;
public:
JSONStringer();
+ ~JSONStringer();
JSONStringer & clear();
- vespalib::stringref toString() { return _oss.str(); }
+ stringref toString() const;
};
template<typename T>
struct JSONPrinter
{
- static void printJSON(vespalib::JSONWriter& w, T v) {
+ static void printJSON(JSONWriter& w, T v) {
w.appendInt64(v);
}
};
@@ -75,7 +78,7 @@ struct JSONPrinter
template<>
struct JSONPrinter<uint64_t>
{
- static void printJSON(vespalib::JSONWriter& w, uint64_t v) {
+ static void printJSON(JSONWriter& w, uint64_t v) {
w.appendUInt64(v);
}
};
@@ -83,7 +86,7 @@ struct JSONPrinter<uint64_t>
template<>
struct JSONPrinter<float>
{
- static void printJSON(vespalib::JSONWriter& w, float v) {
+ static void printJSON(JSONWriter& w, float v) {
w.appendDouble(v);
}
};
@@ -91,11 +94,9 @@ struct JSONPrinter<float>
template<>
struct JSONPrinter<double>
{
- static void printJSON(vespalib::JSONWriter& w, double v) {
+ static void printJSON(JSONWriter& w, double v) {
w.appendDouble(v);
}
};
-
}
-
diff --git a/staging_vespalib/src/vespa/vespalib/util/xmlserializable.cpp b/staging_vespalib/src/vespa/vespalib/util/xmlserializable.cpp
index 1020f714b81..58aa6ca0d36 100644
--- a/staging_vespalib/src/vespa/vespalib/util/xmlserializable.cpp
+++ b/staging_vespalib/src/vespa/vespalib/util/xmlserializable.cpp
@@ -1,12 +1,8 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/fastos/fastos.h>
-#include <vespa/vespalib/util/xmlserializable.h>
-
-#include <sstream>
+#include <vespa/vespalib/util/xmlserializable.hpp>
#include <vector>
#include <vespa/vespalib/encoding/base64.h>
-#include <vespa/vespalib/util/exceptions.h>
namespace vespalib {
namespace xml {
diff --git a/staging_vespalib/src/vespa/vespalib/util/xmlserializable.h b/staging_vespalib/src/vespa/vespalib/util/xmlserializable.h
index f79af671b7d..8454ea045ee 100644
--- a/staging_vespalib/src/vespa/vespalib/util/xmlserializable.h
+++ b/staging_vespalib/src/vespa/vespalib/util/xmlserializable.h
@@ -32,10 +32,6 @@
#include <ostream>
#include <list>
#include <memory>
-#include <sstream>
-#include <vespa/vespalib/util/exception.h>
-#include <vespa/vespalib/objects/cloneable.h>
-#include <vespa/vespalib/objects/identifiable.h>
namespace vespalib {
namespace xml {
@@ -101,23 +97,6 @@ public:
const std::string& getValue() const { return _value; }
};
-template<typename T>
-XmlAttribute::XmlAttribute(const std::string& name, const T& value,
- uint32_t flags)
- : _name(name),
- _value(),
- _next()
-{
- std::ostringstream ost;
- if (flags & HEX) ost << std::hex << "0x";
- ost << value;
- _value = ost.str();
- if (!isLegalName(name)) {
- throw vespalib::IllegalArgumentException("Name '" + name + "' contains "
- "illegal XML characters and cannot be used as attribute name");
- }
-}
-
/**
* @class document::XmlContent
diff --git a/staging_vespalib/src/vespa/vespalib/util/xmlserializable.hpp b/staging_vespalib/src/vespa/vespalib/util/xmlserializable.hpp
new file mode 100644
index 00000000000..7fcc964d8f1
--- /dev/null
+++ b/staging_vespalib/src/vespa/vespalib/util/xmlserializable.hpp
@@ -0,0 +1,29 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include "xmlserializable.h"
+#include <sstream>
+#include <vespa/vespalib/util/exceptions.h>
+
+namespace vespalib {
+namespace xml {
+
+template<typename T>
+XmlAttribute::XmlAttribute(const std::string& name, const T& value, uint32_t flags)
+ : _name(name),
+ _value(),
+ _next()
+{
+ std::ostringstream ost;
+ if (flags & HEX) ost << std::hex << "0x";
+ ost << value;
+ _value = ost.str();
+ if (!isLegalName(name)) {
+ throw vespalib::IllegalArgumentException("Name '" + name + "' contains "
+ "illegal XML characters and cannot be used as attribute name");
+ }
+}
+
+}
+}