summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorBrad Kittenbrink <brad@lindenlab.com>2009-06-10 00:00:03 +0000
committerBrad Kittenbrink <brad@lindenlab.com>2009-06-10 00:00:03 +0000
commit050d2db0f805d799c59349253262b648aa8f70b2 (patch)
treedfc8e49391a461ca6c54cedcad0bb1c2b89979f9 /indra
parent820d4a20d1b9c9a3e562b925ba59a6addcffa558 (diff)
Added LLAPRSockStream class and associated LLAPRSockStreambuf class for
DEV-31978 viewer event host socket module. reviewed by palmer+nat+mani.
Diffstat (limited to 'indra')
-rw-r--r--indra/llcommon/CMakeLists.txt3
-rw-r--r--indra/llcommon/stringize.h73
2 files changed, 47 insertions, 29 deletions
diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt
index bbfadbb344..e920475f54 100644
--- a/indra/llcommon/CMakeLists.txt
+++ b/indra/llcommon/CMakeLists.txt
@@ -22,6 +22,7 @@ include_directories(
set(llcommon_SOURCE_FILES
llapp.cpp
llapr.cpp
+ llaprsockstream.cpp
llassettype.cpp
llbase32.cpp
llbase64.cpp
@@ -94,6 +95,7 @@ set(llcommon_HEADER_FILES
llagentconstants.h
llapp.h
llapr.h
+ llaprsockstream.h
llassettype.h
llassoclist.h
llavatarconstants.h
@@ -236,6 +238,7 @@ target_link_libraries(
${BOOST_REGEX_LIBRARY}
)
+ADD_BUILD_TEST(llaprsockstream llcommon)
ADD_BUILD_TEST(lllazy llcommon)
ADD_BUILD_TEST(lleventfilter llcommon)
ADD_BUILD_TEST(lleventcoro llcommon)
diff --git a/indra/llcommon/stringize.h b/indra/llcommon/stringize.h
index 1b2958020f..6399547f5e 100644
--- a/indra/llcommon/stringize.h
+++ b/indra/llcommon/stringize.h
@@ -13,6 +13,7 @@
#define LL_STRINGIZE_H
#include <sstream>
+#include <boost/lambda/lambda.hpp>
/**
* stringize(item) encapsulates an idiom we use constantly, using
@@ -28,6 +29,17 @@ std::string stringize(const T& item)
}
/**
+ * stringize_f(functor)
+ */
+template <typename Functor>
+std::string stringize_f(Functor const & f)
+{
+ std::ostringstream out;
+ f(out);
+ return out.str();
+}
+
+/**
* STRINGIZE(item1 << item2 << item3 ...) effectively expands to the
* following:
* @code
@@ -36,40 +48,43 @@ std::string stringize(const T& item)
* return out.str();
* @endcode
*/
-#define STRINGIZE(EXPRESSION) (static_cast<std::ostringstream&>(Stringize() << EXPRESSION).str())
+#define STRINGIZE(EXPRESSION) (stringize_f(boost::lambda::_1 << EXPRESSION))
+
/**
- * Helper class for STRINGIZE() macro. Ideally the body of
- * STRINGIZE(EXPRESSION) would look something like this:
+ * destringize(str)
+ * defined for symmetry with stringize
+ * *NOTE - this has distinct behavior from boost::lexical_cast<T> regarding
+ * leading/trailing whitespace and handling of bad_lexical_cast exceptions
+ */
+template <typename T>
+T destringize(std::string const & str)
+{
+ T val;
+ std::istringstream in(str);
+ in >> val;
+ return val;
+}
+
+/**
+ * destringize_f(str, functor)
+ */
+template <typename Functor>
+void destringize_f(std::string const & str, Functor const & f)
+{
+ std::istringstream in(str);
+ f(in);
+}
+
+/**
+ * DESTRINGIZE(str, item1 >> item2 >> item3 ...) effectively expands to the
+ * following:
* @code
- * (std::ostringstream() << EXPRESSION).str()
+ * std::istringstream in(str);
+ * in >> item1 >> item2 >> item3 ... ;
* @endcode
- * That doesn't work because each of the relevant operator<<() functions
- * accepts a non-const std::ostream&, to which you can't pass a temp instance
- * of std::ostringstream. Stringize plays the necessary const tricks to make
- * the whole thing work.
*/
-class Stringize
-{
-public:
- /**
- * This is the essence of Stringize. The leftmost << operator (the one
- * coded in the STRINGIZE() macro) engages this operator<<() const method
- * on the temp Stringize instance. Every other << operator (ones embedded
- * in EXPRESSION) simply sees the std::ostream& returned by the first one.
- *
- * Finally, the STRINGIZE() macro downcasts that std::ostream& to
- * std::ostringstream&.
- */
- template <typename T>
- std::ostream& operator<<(const T& item) const
- {
- mOut << item;
- return mOut;
- }
+#define DESTRINGIZE(STR, EXPRESSION) (destringize_f((STR), (boost::lambda::_1 >> EXPRESSION)))
-private:
- mutable std::ostringstream mOut;
-};
#endif /* ! defined(LL_STRINGIZE_H) */