From fc3fe401efc928377fd87f6ff52e24cd52f922be Mon Sep 17 00:00:00 2001 From: randomdan Date: Thu, 4 Apr 2013 23:39:42 +0000 Subject: Move non p2 specific components into a supporting library, build libmisc into this too --- project2/cgi/Jamfile.jam | 1 + project2/common/Jamfile.jam | 5 +--- project2/common/safeMapFind.h | 45 ------------------------------------ project2/common/scopeObject.cpp | 24 ------------------- project2/common/scopeObject.h | 20 ---------------- project2/common/variables/lookup.cpp | 2 +- project2/files/Jamfile.jam | 1 + project2/files/fileStream.cpp | 2 +- project2/files/presenterCache.cpp | 2 +- project2/json/Jamfile.jam | 1 + project2/lib/Jamfile.jam | 15 ++++++++++++ project2/lib/safeMapFind.h | 45 ++++++++++++++++++++++++++++++++++++ project2/lib/scopeObject.cpp | 22 ++++++++++++++++++ project2/lib/scopeObject.h | 20 ++++++++++++++++ project2/processes/Jamfile.jam | 1 + project2/sql/Jamfile.jam | 1 + project2/streams/Jamfile.jam | 1 + project2/streams/viewStream.cpp | 2 +- project2/url/Jamfile.jam | 1 + project2/url/downloadToFile.cpp | 2 +- project2/xml/Jamfile.jam | 1 + 21 files changed, 116 insertions(+), 98 deletions(-) delete mode 100644 project2/common/safeMapFind.h delete mode 100644 project2/common/scopeObject.cpp delete mode 100644 project2/common/scopeObject.h create mode 100644 project2/lib/Jamfile.jam create mode 100644 project2/lib/safeMapFind.h create mode 100644 project2/lib/scopeObject.cpp create mode 100644 project2/lib/scopeObject.h diff --git a/project2/cgi/Jamfile.jam b/project2/cgi/Jamfile.jam index b5725d0..6d9021e 100644 --- a/project2/cgi/Jamfile.jam +++ b/project2/cgi/Jamfile.jam @@ -24,6 +24,7 @@ lib p2cgicommon : cgicc glibmm ../common//p2common + ../lib//p2lib boost_filesystem ../xml//p2xml gcrypt diff --git a/project2/common/Jamfile.jam b/project2/common/Jamfile.jam index 1559f25..bf61902 100644 --- a/project2/common/Jamfile.jam +++ b/project2/common/Jamfile.jam @@ -15,19 +15,16 @@ cpp-pch pch : pch.hpp : lib p2common : pch [ glob-tree *.cpp ] - ../../libmisc/buffer.cpp - ../../libmisc/misc.cpp : - ../../libmisc glibmm dl boost_system boost_filesystem boost_date_time ../uuid//p2uuid + ../lib//p2lib : : . - ../../libmisc boost_system ; diff --git a/project2/common/safeMapFind.h b/project2/common/safeMapFind.h deleted file mode 100644 index a5786bc..0000000 --- a/project2/common/safeMapFind.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef SAFEMAPFIND_H -#define SAFEMAPFIND_H - -template -typename Map::const_iterator -safeMapFind(const Map & map, const typename Map::key_type & key) -{ - typename Map::const_iterator i = map.find(key); - if (i == map.end()) { - throw Ex(key); - } - return i; -} - -template -typename Map::mapped_type -defaultMapFind(const Map & map, const typename Map::key_type & key, const typename Map::mapped_type & def = typename Map::mapped_type()) -{ - typename Map::const_iterator i = map.find(key); - if (i == map.end()) { - return def; - } - return i->second; -} - -template -const typename Map::mapped_type & -safeMapLookup(const Map & map, const typename Map::key_type & key) -{ - typename Map::const_iterator i = map.find(key); - if (i == map.end()) { - throw Ex(key); - } - return i->second; -} - -template -bool -containerContains(const Cont & c, const typename Cont::value_type & v) -{ - return (std::find(c.begin(), c.end(), v) != c.end()); -} - -#endif - diff --git a/project2/common/scopeObject.cpp b/project2/common/scopeObject.cpp deleted file mode 100644 index b51287c..0000000 --- a/project2/common/scopeObject.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "pch.hpp" -#include "scopeObject.h" -#include "logger.h" - -ScopeObject::ScopeObject(const Event & onexitpre, const Event & onsuccess, const Event & onfailure, const Event & onexitpost) : - onExitPre(onexitpre), - onSuccess(onsuccess), - onFailure(onfailure), - onExitPost(onexitpost) -{ -} - -ScopeObject::~ScopeObject() -{ - if (onExitPre) onExitPre(); - if (std::uncaught_exception()) { - if (onFailure) onFailure(); - } - else { - if (onSuccess) onSuccess(); - } - if (onExitPost) onExitPost(); -} - diff --git a/project2/common/scopeObject.h b/project2/common/scopeObject.h deleted file mode 100644 index d019e7d..0000000 --- a/project2/common/scopeObject.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef SCOPE_OBJECT_H -#define SCOPE_OBJECT_H - -#include - -class ScopeObject { - public: - typedef boost::function0 Event; - ScopeObject(const Event &, const Event & = Event(), const Event & = Event(), const Event & = Event()); - ~ScopeObject(); - - private: - const Event onExitPre; - const Event onSuccess; - const Event onFailure; - const Event onExitPost; -}; - -#endif - diff --git a/project2/common/variables/lookup.cpp b/project2/common/variables/lookup.cpp index 41326c2..19884e5 100644 --- a/project2/common/variables/lookup.cpp +++ b/project2/common/variables/lookup.cpp @@ -1,6 +1,6 @@ #include "../pch.hpp" #include "../variables.h" -#include "../safeMapFind.h" +#include #include "../logger.h" #include "../rowProcessor.h" #include "../rowSet.h" diff --git a/project2/files/Jamfile.jam b/project2/files/Jamfile.jam index 3b23db0..66d55f0 100644 --- a/project2/files/Jamfile.jam +++ b/project2/files/Jamfile.jam @@ -21,6 +21,7 @@ lib p2files : boost_iostreams gcrypt ../common//p2common + ../lib//p2lib : : . ; diff --git a/project2/files/fileStream.cpp b/project2/files/fileStream.cpp index d01ce27..99eb302 100644 --- a/project2/files/fileStream.cpp +++ b/project2/files/fileStream.cpp @@ -1,6 +1,6 @@ #include "pch.hpp" #include "logger.h" -#include "scopeObject.h" +#include #include "stream.h" #include "rowProcessor.h" #include "scriptLoader.h" diff --git a/project2/files/presenterCache.cpp b/project2/files/presenterCache.cpp index ee07fd2..439028a 100644 --- a/project2/files/presenterCache.cpp +++ b/project2/files/presenterCache.cpp @@ -1,7 +1,7 @@ #include "../common/presenterCache.h" #include "../common/exceptions.h" #include "../common/options.h" -#include "../common/safeMapFind.h" +#include #include "../common/environment.h" #include #include diff --git a/project2/json/Jamfile.jam b/project2/json/Jamfile.jam index 323e4fe..88bf92e 100644 --- a/project2/json/Jamfile.jam +++ b/project2/json/Jamfile.jam @@ -16,6 +16,7 @@ lib p2json : ../libmisc glibmm ../common//p2common + ../lib//p2lib ../uuid//p2uuid ../url//p2url boost_filesystem diff --git a/project2/lib/Jamfile.jam b/project2/lib/Jamfile.jam new file mode 100644 index 0000000..5825d48 --- /dev/null +++ b/project2/lib/Jamfile.jam @@ -0,0 +1,15 @@ +alias glibmm : : : : + "`pkg-config --cflags glibmm-2.4`" + "`pkg-config --libs glibmm-2.4`" + ; + +lib p2lib : + [ glob-tree *.cpp ] + ../../libmisc/buffer.cpp + ../../libmisc/misc.cpp + : + ../../libmisc + : : + ../../libmisc + . + ; diff --git a/project2/lib/safeMapFind.h b/project2/lib/safeMapFind.h new file mode 100644 index 0000000..a5786bc --- /dev/null +++ b/project2/lib/safeMapFind.h @@ -0,0 +1,45 @@ +#ifndef SAFEMAPFIND_H +#define SAFEMAPFIND_H + +template +typename Map::const_iterator +safeMapFind(const Map & map, const typename Map::key_type & key) +{ + typename Map::const_iterator i = map.find(key); + if (i == map.end()) { + throw Ex(key); + } + return i; +} + +template +typename Map::mapped_type +defaultMapFind(const Map & map, const typename Map::key_type & key, const typename Map::mapped_type & def = typename Map::mapped_type()) +{ + typename Map::const_iterator i = map.find(key); + if (i == map.end()) { + return def; + } + return i->second; +} + +template +const typename Map::mapped_type & +safeMapLookup(const Map & map, const typename Map::key_type & key) +{ + typename Map::const_iterator i = map.find(key); + if (i == map.end()) { + throw Ex(key); + } + return i->second; +} + +template +bool +containerContains(const Cont & c, const typename Cont::value_type & v) +{ + return (std::find(c.begin(), c.end(), v) != c.end()); +} + +#endif + diff --git a/project2/lib/scopeObject.cpp b/project2/lib/scopeObject.cpp new file mode 100644 index 0000000..e2e42da --- /dev/null +++ b/project2/lib/scopeObject.cpp @@ -0,0 +1,22 @@ +#include "scopeObject.h" + +ScopeObject::ScopeObject(const Event & onexitpre, const Event & onsuccess, const Event & onfailure, const Event & onexitpost) : + onExitPre(onexitpre), + onSuccess(onsuccess), + onFailure(onfailure), + onExitPost(onexitpost) +{ +} + +ScopeObject::~ScopeObject() +{ + if (onExitPre) onExitPre(); + if (std::uncaught_exception()) { + if (onFailure) onFailure(); + } + else { + if (onSuccess) onSuccess(); + } + if (onExitPost) onExitPost(); +} + diff --git a/project2/lib/scopeObject.h b/project2/lib/scopeObject.h new file mode 100644 index 0000000..6fc323d --- /dev/null +++ b/project2/lib/scopeObject.h @@ -0,0 +1,20 @@ +#ifndef SCOPE_OBJECT_H +#define SCOPE_OBJECT_H + +#include + +class ScopeObject { + public: + typedef boost::function Event; + ScopeObject(const Event &, const Event & = Event(), const Event & = Event(), const Event & = Event()); + ~ScopeObject(); + + private: + const Event onExitPre; + const Event onSuccess; + const Event onFailure; + const Event onExitPost; +}; + +#endif + diff --git a/project2/processes/Jamfile.jam b/project2/processes/Jamfile.jam index cba36f2..99f6ffd 100644 --- a/project2/processes/Jamfile.jam +++ b/project2/processes/Jamfile.jam @@ -8,5 +8,6 @@ lib p2processes : ../../libmisc glibmm ../common//p2common + ../lib//p2lib ; diff --git a/project2/sql/Jamfile.jam b/project2/sql/Jamfile.jam index f73fd65..dffab25 100644 --- a/project2/sql/Jamfile.jam +++ b/project2/sql/Jamfile.jam @@ -51,6 +51,7 @@ lib p2sql : yes:sql-modMySQL glibmm ../common//p2common + ../lib//p2lib ../../libmisc ; diff --git a/project2/streams/Jamfile.jam b/project2/streams/Jamfile.jam index be72d6e..530fac1 100644 --- a/project2/streams/Jamfile.jam +++ b/project2/streams/Jamfile.jam @@ -9,5 +9,6 @@ lib p2streams : ../../libmisc glibmm ../common//p2common + ../lib//p2lib ; diff --git a/project2/streams/viewStream.cpp b/project2/streams/viewStream.cpp index fb40c0e..28efc17 100644 --- a/project2/streams/viewStream.cpp +++ b/project2/streams/viewStream.cpp @@ -1,6 +1,6 @@ #include "scriptLoader.h" #include "stream.h" -#include "scopeObject.h" +#include #include "ostreamWrapper.h" #include "viewHost.h" #include diff --git a/project2/url/Jamfile.jam b/project2/url/Jamfile.jam index 272749d..b35eb03 100644 --- a/project2/url/Jamfile.jam +++ b/project2/url/Jamfile.jam @@ -9,6 +9,7 @@ lib p2url : ../../libmisc/curlsup.cpp : ../common//p2common + ../lib//p2lib ../../libmisc glibmm curl diff --git a/project2/url/downloadToFile.cpp b/project2/url/downloadToFile.cpp index dcd9710..5546efc 100644 --- a/project2/url/downloadToFile.cpp +++ b/project2/url/downloadToFile.cpp @@ -1,6 +1,6 @@ #include "curlHelper.h" #include "task.h" -#include "scopeObject.h" +#include #include "scriptLoader.h" #include "exceptions.h" #include "../libmisc/curlsup.h" diff --git a/project2/xml/Jamfile.jam b/project2/xml/Jamfile.jam index 2adadaf..8addab8 100644 --- a/project2/xml/Jamfile.jam +++ b/project2/xml/Jamfile.jam @@ -21,6 +21,7 @@ lib p2xml : ../common//p2common ../uuid//p2uuid ../url//p2url + ../lib//p2lib libxslt boost_filesystem boost_date_time -- cgit v1.2.3