diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-09-02 00:23:19 +0100 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-09-02 00:54:46 +0100 | 
| commit | 6a8de8cf592878cc6f7d50624d18304967c3138c (patch) | |
| tree | 7b70e9593fb0f91ff0b5a44233fc8074636486bb | |
| parent | Add doxygen documentation and config (diff) | |
| download | libadhocutil-6a8de8cf592878cc6f7d50624d18304967c3138c.tar.bz2 libadhocutil-6a8de8cf592878cc6f7d50624d18304967c3138c.tar.xz libadhocutil-6a8de8cf592878cc6f7d50624d18304967c3138c.zip | |
Move into AdHoc namespacelibadhocutil-0.1
29 files changed, 151 insertions, 25 deletions
| diff --git a/libadhocutil/buffer.cpp b/libadhocutil/buffer.cpp index 2ddca50..c7dda56 100644 --- a/libadhocutil/buffer.cpp +++ b/libadhocutil/buffer.cpp @@ -2,6 +2,8 @@  #include <string.h>  #include <stdio.h> +namespace AdHoc { +  Buffer::FragmentBase::~FragmentBase() = default;  // @@ -317,15 +319,6 @@ Buffer::empty() const  	return content.empty();  } -std::ostream & -std::operator<<(std::ostream & os, const Buffer & b) -{ -	for (const auto & f : b.content) { -		os.write(f->c_str(), f->length()); -	} -	return os; -} -  Buffer &  Buffer::operator+=(const char * str)  { @@ -338,3 +331,14 @@ Buffer::operator+=(const std::string & str)  	return append(str);  } +} + +std::ostream & +std::operator<<(std::ostream & os, const AdHoc::Buffer & b) +{ +	for (const auto & f : b.content) { +		os.write(f->c_str(), f->length()); +	} +	return os; +} + diff --git a/libadhocutil/buffer.h b/libadhocutil/buffer.h index 4a355fa..1d99f22 100644 --- a/libadhocutil/buffer.h +++ b/libadhocutil/buffer.h @@ -9,12 +9,16 @@  #include <boost/shared_ptr.hpp>  #include "visibility.h" -class DLL_PUBLIC Buffer; +namespace AdHoc { +	class DLL_PUBLIC Buffer; +}  namespace std { -	DLL_PUBLIC std::ostream & operator<<(std::ostream &, const Buffer &); +	DLL_PUBLIC std::ostream & operator<<(std::ostream &, const AdHoc::Buffer &);  } +namespace AdHoc { +  /// High-speed text buffer for easy creation of programatically created strings.  class DLL_PUBLIC Buffer : public virtual IntrusivePtrBase {  	public: @@ -158,10 +162,12 @@ class DLL_PUBLIC Buffer : public virtual IntrusivePtrBase {  		mutable Content content;  }; +} +  // libmisc compat macros -#define vstringf(...) Buffer().vappendf(__VA_ARGS__).str() -#define stringf(...) Buffer().appendf(__VA_ARGS__).str() -#define stringbf(...) Buffer().appendbf(__VA_ARGS__).str() +#define vstringf(...) AdHoc::Buffer().vappendf(__VA_ARGS__).str() +#define stringf(...) AdHoc::Buffer().appendf(__VA_ARGS__).str() +#define stringbf(...) AdHoc::Buffer().appendbf(__VA_ARGS__).str()  #endif diff --git a/libadhocutil/cache.h b/libadhocutil/cache.h index f2a4e81..ff899dc 100644 --- a/libadhocutil/cache.h +++ b/libadhocutil/cache.h @@ -10,6 +10,8 @@  #include <boost/thread/shared_mutex.hpp>  #include <boost/variant.hpp> +namespace AdHoc { +  /// @cond  template <typename T, typename K>  class Cacheable { @@ -106,5 +108,7 @@ class Cache {  		mutable Cached cached;  }; +} +  #endif diff --git a/libadhocutil/cache.impl.h b/libadhocutil/cache.impl.h index 7d4119d..7b0340c 100644 --- a/libadhocutil/cache.impl.h +++ b/libadhocutil/cache.impl.h @@ -5,6 +5,8 @@  #include <boost/lambda/lambda.hpp>  #include "lockHelpers.h" +namespace AdHoc { +  /// @cond  template<typename T, typename K>  Cacheable<T, K>::Cacheable(const K & k, time_t vu) : @@ -130,5 +132,7 @@ Cache<T, K>::prune() const  }  /// @endcond +} +  #endif diff --git a/libadhocutil/curlHandle.cpp b/libadhocutil/curlHandle.cpp index 6192c70..b86d8c1 100644 --- a/libadhocutil/curlHandle.cpp +++ b/libadhocutil/curlHandle.cpp @@ -2,6 +2,9 @@  #include <net.h>  #include <boost/numeric/conversion/cast.hpp> +namespace AdHoc { +namespace Net { +  static void cleanup() __attribute__((destructor));  static void cleanup()  { @@ -117,3 +120,6 @@ CurlHandle::checkCurlCode(CURLcode res) const  	}  } +} +} + diff --git a/libadhocutil/curlHandle.h b/libadhocutil/curlHandle.h index de5d812..7bbcfc4 100644 --- a/libadhocutil/curlHandle.h +++ b/libadhocutil/curlHandle.h @@ -5,6 +5,9 @@  #include "intrusivePtrBase.h"  #include "visibility.h" +namespace AdHoc { +namespace Net { +  /// libcurl handle wrapper.  /** Wraps a libcurl CURL * object in a C++ friendly manner. */  class DLL_PUBLIC CurlHandle : public virtual IntrusivePtrBase { @@ -62,5 +65,8 @@ void CurlHandle::setopt(CURLoption opt, const T val)  }  /// @endcond +} +} +  #endif diff --git a/libadhocutil/curlMultiHandle.cpp b/libadhocutil/curlMultiHandle.cpp index 433b78c..9afd9e1 100644 --- a/libadhocutil/curlMultiHandle.cpp +++ b/libadhocutil/curlMultiHandle.cpp @@ -4,6 +4,9 @@  #include "runtimeContext.h"  #include "curlStream.h" +namespace AdHoc { +namespace Net { +  class RunningCurl : public CurlStreamSource {  	public:  		RunningCurl(const std::string & url, const boost::function<void(std::istream &)> & c) : @@ -93,3 +96,6 @@ CurlMultiHandle::performAll()  	}  } +} +} + diff --git a/libadhocutil/curlMultiHandle.h b/libadhocutil/curlMultiHandle.h index 14242c6..6dc79b9 100644 --- a/libadhocutil/curlMultiHandle.h +++ b/libadhocutil/curlMultiHandle.h @@ -8,6 +8,9 @@  #include "visibility.h"  #include "curlHandle.h" +namespace AdHoc { +namespace Net { +  class RunningCurl;  typedef boost::intrusive_ptr<RunningCurl> RunningCurlPtr; @@ -35,5 +38,8 @@ class DLL_PUBLIC CurlMultiHandle : public IntrusivePtrBase {  };  typedef boost::intrusive_ptr<CurlMultiHandle> CurlMultiHandlePtr; +} +} +  #endif diff --git a/libadhocutil/curlStream.cpp b/libadhocutil/curlStream.cpp index 1cc0f4b..9701e54 100644 --- a/libadhocutil/curlStream.cpp +++ b/libadhocutil/curlStream.cpp @@ -1,5 +1,8 @@  #include "curlStream.h" +namespace AdHoc { +namespace Net { +  CurlStreamSource::CurlStreamSource(const std::string & url) :  	CurlHandle(url),  	buflen(0), @@ -51,3 +54,6 @@ CurlStreamSource::recv(void * data, size_t datalen)  	return datalen;  } +} +} + diff --git a/libadhocutil/curlStream.h b/libadhocutil/curlStream.h index 3a131f5..da54f0f 100644 --- a/libadhocutil/curlStream.h +++ b/libadhocutil/curlStream.h @@ -8,8 +8,11 @@  #include "visibility.h"  #include "curlHandle.h" +namespace AdHoc { +namespace Net { +  /// boost::iostreams::source implementation for CURL downloads. -class DLL_PUBLIC CurlStreamSource : public boost::iostreams::source, public CurlHandle, RuntimeContext { +class DLL_PUBLIC CurlStreamSource : public boost::iostreams::source, public CurlHandle, ::AdHoc::System::RuntimeContext {  	public:  		/** Construct a new stream source for the given URL. */  		CurlStreamSource(const std::string & url); @@ -31,5 +34,8 @@ class DLL_PUBLIC CurlStreamSource : public boost::iostreams::source, public Curl  typedef boost::iostreams::stream<boost::reference_wrapper<CurlStreamSource>> CurlStream; +} +} +  #endif diff --git a/libadhocutil/lazyPointer.h b/libadhocutil/lazyPointer.h index 79808b7..9b680c4 100644 --- a/libadhocutil/lazyPointer.h +++ b/libadhocutil/lazyPointer.h @@ -5,6 +5,8 @@  #include <boost/variant.hpp>  #include <boost/intrusive_ptr.hpp> +namespace AdHoc { +  /// Smart pointer that initializes itself only if it has to.  /**   * LazyPointer behaves like a normal smarter for the most part. It's benefit @@ -130,9 +132,11 @@ class LazyPointer {  		mutable Source source;  }; +} +  namespace boost {  	template <typename R, typename T, typename P> -		R * dynamic_pointer_cast(const LazyPointer<T, P> & p) { +		R * dynamic_pointer_cast(const AdHoc::LazyPointer<T, P> & p) {  			return dynamic_cast<R *>(p.get());  		}  } diff --git a/libadhocutil/nvpParse.h b/libadhocutil/nvpParse.h index 354046d..403a6de 100644 --- a/libadhocutil/nvpParse.h +++ b/libadhocutil/nvpParse.h @@ -13,6 +13,8 @@  #endif  #include <visibility.h> +namespace AdHoc { +  /// Name=Value parser.  /**   * Parses an input stream of the format Name=Value;Name2=Value2;... into a predefined object @@ -91,5 +93,7 @@ class NvpParse : public yyFlexLexer {  		const AssignMap values;  }; +} +  #endif diff --git a/libadhocutil/nvpParse.ll b/libadhocutil/nvpParse.ll index 1e6a528..601aa53 100644 --- a/libadhocutil/nvpParse.ll +++ b/libadhocutil/nvpParse.ll @@ -3,7 +3,7 @@  %option noyywrap  %option 8bit  %option stack -%option yyclass="NvpParse" +%option yyclass="AdHoc::NvpParse"  %option prefix="nvpBase"  %{ @@ -51,6 +51,8 @@ semi ";"  %%  #include "safeMapFind.h" +namespace AdHoc { +  NvpParse::ValueNotFound::ValueNotFound(const std::string & vn) :  	std::runtime_error("Value not found: " + vn)  { @@ -83,3 +85,5 @@ NvpParse::parse(std::istream & in, const AssignMap & m)  	p.yylex();  } +} + diff --git a/libadhocutil/processPipes.cpp b/libadhocutil/processPipes.cpp index 55050ae..229c9d2 100644 --- a/libadhocutil/processPipes.cpp +++ b/libadhocutil/processPipes.cpp @@ -5,6 +5,9 @@  #include <sys/resource.h>  #include <stdexcept> +namespace AdHoc { +namespace System { +  ProcessPipes::ProcessPipes(const std::vector<std::string> & args, bool i, bool o, bool e) :  	in(-1),  	out(-1), @@ -136,3 +139,6 @@ ProcessPipes::pid() const  	return child;  } +} +} + diff --git a/libadhocutil/processPipes.h b/libadhocutil/processPipes.h index 42efbe7..195d8e9 100644 --- a/libadhocutil/processPipes.h +++ b/libadhocutil/processPipes.h @@ -5,6 +5,9 @@  #include <string>  #include "visibility.h" +namespace AdHoc { +namespace System { +  /// Spawn a process and attach to its IO handles.  class DLL_PUBLIC ProcessPipes {  	public: @@ -36,5 +39,8 @@ class DLL_PUBLIC ProcessPipes {  		pid_t child;  }; +} +} +  #endif diff --git a/libadhocutil/runtimeContext.cpp b/libadhocutil/runtimeContext.cpp index 4cb5a17..fc09419 100644 --- a/libadhocutil/runtimeContext.cpp +++ b/libadhocutil/runtimeContext.cpp @@ -1,6 +1,9 @@  #include "runtimeContext.h"  #include <stdexcept> +namespace AdHoc { +namespace System { +  RuntimeContext::RuntimeContext(size_t stacksize) :  	completed(false),  	swapped(false) @@ -50,3 +53,6 @@ RuntimeContext::callbackWrapper(RuntimeContext * rc)  	rc->completed = true;  } +} +} + diff --git a/libadhocutil/runtimeContext.h b/libadhocutil/runtimeContext.h index 21c6fe6..8c87263 100644 --- a/libadhocutil/runtimeContext.h +++ b/libadhocutil/runtimeContext.h @@ -5,6 +5,9 @@  #include <ucontext.h>  #include "visibility.h" +namespace AdHoc { +namespace System { +  /// Runtime Context  /**   * Create an alternate stack for processing. @@ -38,5 +41,8 @@ class DLL_PUBLIC RuntimeContext {  		bool swapped;  }; +} +} +  #endif diff --git a/libadhocutil/safeMapFind.h b/libadhocutil/safeMapFind.h index 9b2823a..7c36367 100644 --- a/libadhocutil/safeMapFind.h +++ b/libadhocutil/safeMapFind.h @@ -1,6 +1,10 @@  #ifndef ADHOCUTIL_SAFEMAPFIND_H  #define ADHOCUTIL_SAFEMAPFIND_H +#include <algorithm> + +namespace AdHoc { +  /*   * Find the key and return the iterator to the pair,   * or throw Ex(key) if not found. @@ -56,5 +60,7 @@ containerContains(const Cont & c, const typename Cont::value_type & v)  	return (std::find(c.begin(), c.end(), v) != c.end());  } +} +  #endif diff --git a/libadhocutil/scopeExit.cpp b/libadhocutil/scopeExit.cpp index fa914c5..b9ff8f5 100644 --- a/libadhocutil/scopeExit.cpp +++ b/libadhocutil/scopeExit.cpp @@ -1,5 +1,7 @@  #include "scopeExit.h" +namespace AdHoc { +  ScopeExit::ScopeExit(const Event & onexitpre, const Event & onsuccess, const Event & onfailure, const Event & onexitpost) :  	onExitPre(onexitpre),  	onSuccess(onsuccess), @@ -20,3 +22,5 @@ ScopeExit::~ScopeExit()  	if (onExitPost) onExitPost();  } +} + diff --git a/libadhocutil/scopeExit.h b/libadhocutil/scopeExit.h index dc2a286..a8eb9a2 100644 --- a/libadhocutil/scopeExit.h +++ b/libadhocutil/scopeExit.h @@ -4,6 +4,8 @@  #include <boost/function.hpp>  #include "visibility.h" +namespace AdHoc { +  /// Run code at scope exit.  class DLL_PUBLIC ScopeExit {  	public: @@ -29,5 +31,7 @@ class DLL_PUBLIC ScopeExit {  		const Event onExitPost;  }; +} +  #endif diff --git a/libadhocutil/unittests/testBuffer.cpp b/libadhocutil/unittests/testBuffer.cpp index dce9f66..46a4242 100644 --- a/libadhocutil/unittests/testBuffer.cpp +++ b/libadhocutil/unittests/testBuffer.cpp @@ -3,6 +3,8 @@  #include "buffer.h" +using namespace AdHoc; +  BOOST_AUTO_TEST_CASE ( create )  {  	Buffer empty; diff --git a/libadhocutil/unittests/testCache.cpp b/libadhocutil/unittests/testCache.cpp index da6df69..736cf07 100644 --- a/libadhocutil/unittests/testCache.cpp +++ b/libadhocutil/unittests/testCache.cpp @@ -5,19 +5,23 @@  #include "cache.h"  #include "cache.impl.h" -typedef Cache<int, std::string> TestCache; -template class Cache<int, std::string>; -template class Cacheable<int, std::string>; -template class ObjectCacheable<int, std::string>; -template class CallCacheable<int, std::string>; -  namespace std {  	std::ostream & operator<<(std::ostream & s, const std::nullptr_t &)  	{ -		return s << "(nil)";	 +		return s << "(nil)";  	}  } +namespace AdHoc { +	typedef Cache<int, std::string> TestCache; +	template class Cache<int, std::string>; +	template class Cacheable<int, std::string>; +	template class ObjectCacheable<int, std::string>; +	template class CallCacheable<int, std::string>; +} + +using namespace AdHoc; +  BOOST_AUTO_TEST_CASE( miss )  {  	TestCache tc; diff --git a/libadhocutil/unittests/testContext.cpp b/libadhocutil/unittests/testContext.cpp index de76493..0447beb 100644 --- a/libadhocutil/unittests/testContext.cpp +++ b/libadhocutil/unittests/testContext.cpp @@ -3,6 +3,8 @@  #include "runtimeContext.h" +using namespace AdHoc::System; +  class TestRuntimeContext : public RuntimeContext {  	public:  		void run() diff --git a/libadhocutil/unittests/testCurl.cpp b/libadhocutil/unittests/testCurl.cpp index 5365f58..1a8a595 100644 --- a/libadhocutil/unittests/testCurl.cpp +++ b/libadhocutil/unittests/testCurl.cpp @@ -8,7 +8,11 @@  #include "definedDirs.h"  #include "net.h" -size_t discard(void *, size_t sz, size_t nm, void *) +using namespace AdHoc::Net; + +static +size_t +discard(void *, size_t sz, size_t nm, void *)  {  	return sz * nm;  } diff --git a/libadhocutil/unittests/testLazyPointer.cpp b/libadhocutil/unittests/testLazyPointer.cpp index 6c4ddcd..3b69c80 100644 --- a/libadhocutil/unittests/testLazyPointer.cpp +++ b/libadhocutil/unittests/testLazyPointer.cpp @@ -5,6 +5,8 @@  #include "intrusivePtrBase.h"  #include "lazyPointer.h" +using namespace AdHoc; +  class Test : public IntrusivePtrBase {  	public:  		Test(int v) : diff --git a/libadhocutil/unittests/testMapFinds.cpp b/libadhocutil/unittests/testMapFinds.cpp index c0b7c5e..a787676 100644 --- a/libadhocutil/unittests/testMapFinds.cpp +++ b/libadhocutil/unittests/testMapFinds.cpp @@ -7,6 +7,8 @@  #include <string>  #include <map> +using namespace AdHoc; +  class NotFound : std::runtime_error {  	public:  		NotFound(int key) : diff --git a/libadhocutil/unittests/testNvpParse.cpp b/libadhocutil/unittests/testNvpParse.cpp index dd7432f..db552de 100644 --- a/libadhocutil/unittests/testNvpParse.cpp +++ b/libadhocutil/unittests/testNvpParse.cpp @@ -3,6 +3,8 @@  #include "nvpParse.h" +using namespace AdHoc; +  class TestTarget {  	public:  		std::string a; diff --git a/libadhocutil/unittests/testProcessPipes.cpp b/libadhocutil/unittests/testProcessPipes.cpp index c87e074..ecd596b 100644 --- a/libadhocutil/unittests/testProcessPipes.cpp +++ b/libadhocutil/unittests/testProcessPipes.cpp @@ -5,6 +5,8 @@  #include "definedDirs.h"  #include <sys/wait.h> +using namespace AdHoc::System; +  BOOST_AUTO_TEST_CASE ( readfind )  {  	ProcessPipes pp({"/usr/bin/find", rootDir.string(), "-maxdepth", "1"}, false, true, true); diff --git a/libadhocutil/unittests/testScopeExit.cpp b/libadhocutil/unittests/testScopeExit.cpp index 80574f9..66f4c48 100644 --- a/libadhocutil/unittests/testScopeExit.cpp +++ b/libadhocutil/unittests/testScopeExit.cpp @@ -4,6 +4,8 @@  #include "scopeExit.h"  #include <string> +using namespace AdHoc; +  BOOST_AUTO_TEST_CASE ( cleanexit )  {  	std::string log; | 
