diff options
| -rw-r--r-- | project2/Jamfile.jam | 13 | ||||
| -rw-r--r-- | project2/streamRows.cpp | 4 | ||||
| -rw-r--r-- | project2/variables-modlookup.cpp | 64 | ||||
| -rw-r--r-- | project2/variables.cpp | 45 | ||||
| -rw-r--r-- | project2/variables.h | 6 | 
5 files changed, 72 insertions, 60 deletions
| diff --git a/project2/Jamfile.jam b/project2/Jamfile.jam index 38c4399..e9013ef 100644 --- a/project2/Jamfile.jam +++ b/project2/Jamfile.jam @@ -85,11 +85,12 @@ lib p2common :  lib p2xml :  	rawView.cpp xmlPresenter.cpp transformHtml.cpp transformText.cpp xmlRows.cpp -	xmlRawRows.cpp xslRows.cpp xslRowsCache.cpp xslPreFetch.cpp xmlCache.cpp +	xmlRawRows.cpp xslRows.cpp xslRowsCache.cpp xslPreFetch.cpp xmlCache.cpp sessionXml.cpp  	:  	<include>../libmisc  	<library>libxmlpp  	<library>p2common +	<library>p2uuid  	<library>p2url  	<library>libxslt  	<library>boost_filesystem @@ -124,15 +125,6 @@ lib p2regex :  	<library>p2common  	; -lib p2xmlSession : -	sessionXml.cpp -	: -	<include>../libmisc -	<library>libxmlpp -	<library>p2uuid -	<library>p2common -	; -  explicit object sql-modODBC ;  obj sql-modODBC :  	sql-modODBC.cpp : @@ -203,7 +195,6 @@ lib p2web :  	<library>p2xml  	: :  	<library>p2parts -	<library>p2xmlSession  	<library>p2uuid  	<library>cgicc  	<library>p2common diff --git a/project2/streamRows.cpp b/project2/streamRows.cpp index 98d7f03..0be76cd 100644 --- a/project2/streamRows.cpp +++ b/project2/streamRows.cpp @@ -80,7 +80,9 @@ StreamRows::ParseState::ParseState(const StreamRows * rows, const RowProcessor *  StreamRows::ParseState::~ParseState()  { -	sr->end(*this); +	if (!std::uncaught_exception()) { +		sr->end(*this); +	}  }  void diff --git a/project2/variables-modlookup.cpp b/project2/variables-modlookup.cpp index 6ba489a..026362c 100644 --- a/project2/variables-modlookup.cpp +++ b/project2/variables-modlookup.cpp @@ -1,4 +1,5 @@  #include "variables.h" +#include "safeMapFind.h"  #include "logger.h"  #include "rowProcessor.h"  #include "rowSet.h" @@ -6,47 +7,6 @@  #include "xmlObjectLoader.h"  #include "xmlStorage.h" -template <class S> -class compi : public boost::static_visitor<bool> { -	public: -		compi(const S & s) : _s(s) { } -		bool operator()(const S & t) const -		{ -			return _s < t; -		} -		template <class T> -		bool operator()(const T &) const -		{ -			// should never be called -			throw std::logic_error("Shouldn't ever be comparing variables of different type"); -		} -	private: -		const S & _s; -}; - -class comp : public boost::static_visitor<bool> { -	public: -		comp(const VariableType & a) : _a(a) { } -		template <class T> -		bool operator()(const T & t) const -		{ -			return boost::apply_visitor(compi<T>(t), _a); -		} -	private: -		const VariableType & _a; -}; - -bool -operator<(const VariableType & a, const VariableType & b) -{ -	if (a.which() < b.which()) { -		return true; -	} -	if (a.which() == b.which()) { -		return boost::apply_visitor(comp(a), b); -	} -	return false; -}  /// Variable implementation that looks up it's value in a map of key(s)/value pairs  class VariableLookup : public VariableImplDyn, public RowProcessor { @@ -54,7 +14,21 @@ class VariableLookup : public VariableImplDyn, public RowProcessor {  		typedef std::vector<VariableType> Key;  		typedef std::map<Key, VariableType> Map;  	public: -		class NotFound { }; +		class NotFound : public std::runtime_error { +			public: +				NotFound(const Key & k) : +					std::runtime_error(mklist(k)) { +				} +				static std::string mklist(const Key & k) { +					std::string l("("); +					for (Key::const_iterator kp = k.begin(); kp != k.end(); kp++) { +						if (kp != k.begin()) l += ", "; +						l += kp->operator const std::string &(); +					} +					l += ")"; +					return l; +				} +		};  		VariableLookup(const xmlpp::Element * e) :  			VariableImplDyn(e),  			RowProcessor(e), @@ -74,11 +48,7 @@ class VariableLookup : public VariableImplDyn, public RowProcessor {  			BOOST_FOREACH(const Parameters::value_type & p, parameters) {  				k.push_back(p.second->value());  			} -			Map::const_iterator i = map.find(k); -			if (i != map.end()) { -				return i->second; -			} -			throw NotFound(); +			return safeMapFind<NotFound>(map, k)->second;  		}  	private:  		void fillCache() const diff --git a/project2/variables.cpp b/project2/variables.cpp index b866165..9108889 100644 --- a/project2/variables.cpp +++ b/project2/variables.cpp @@ -18,6 +18,11 @@ SimpleMessageException(UnknownVariableType);  SimpleMessageException(UnknownVariableSource);  SimpleMessageException(NoVariableDefinition); +bool Null::operator<(const Null &) const +{ +	return false; +} +  enum VT_typeID {  	DefaultType,  	String, @@ -111,6 +116,46 @@ VariableType::operator=(const VariableType & vt)  	_VT::operator=(*((const _VT *)&vt));  } +template <class S> +class compi : public boost::static_visitor<bool> { +	public: +		compi(const S & s) : _s(s) { } +		bool operator()(const S & t) const +		{ +			return _s < t; +		} +		template <class T> +		bool operator()(const T &) const +		{ +			// should never be called +			throw std::logic_error("Shouldn't ever be comparing variables of different type"); +		} +	private: +		const S & _s; +}; +class comp : public boost::static_visitor<bool> { +	public: +		comp(const VariableType & a) : _a(a) { } +		template <class T> +		bool operator()(const T & t) const +		{ +			return boost::apply_visitor(compi<T>(t), _a); +		} +	private: +		const VariableType & _a; +}; +bool +VariableType::operator<(const VariableType & b) const +{ +	if (this->which() < b.which()) { +		return true; +	} +	if (this->which() == b.which()) { +		return boost::apply_visitor(comp(*this), b); +	} +	return false; +} +  /// Variable implementation whose value is a literal value of some known type  class VariableLiteral : public VariableImpl {  	public: diff --git a/project2/variables.h b/project2/variables.h index 4c06f96..54ac52c 100644 --- a/project2/variables.h +++ b/project2/variables.h @@ -13,7 +13,10 @@  #include <boost/variant.hpp>  #include <boost/shared_ptr.hpp> -class Null { }; +class Null { +	public: +		bool operator<(const Null &) const; +};  typedef boost::variant<  	Null,  	// Strings @@ -42,6 +45,7 @@ class VariableType : public _VT {  		VariableType(const VariableType &);  		~VariableType();  		void operator=(const VariableType &); +		bool operator<(const VariableType &) const;  		operator const Glib::ustring &() const;  		operator const std::string &() const; | 
