[ObjectHandler-cvs] ObjectHandler/oh/Conversions coerce.hpp, NONE, 1.1
Brought to you by:
ericehlers,
nando
From: Eric E. <eri...@us...> - 2006-11-19 13:08:35
|
Update of /cvsroot/objecthandler/ObjectHandler/oh/Conversions In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv29592/oh/Conversions Added Files: coerce.hpp Log Message: support for coercion --- NEW FILE: coerce.hpp --- /* Copyright (C) 2006 Eric Ehlers This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ QuantLib is free software: you can redistribute it and/or modify it under the terms of the QuantLib license. You should have received a copy of the license along with this program; if not, please email qua...@li... The license is also available online at http://quantlib.org/html/license.html This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */ #ifndef oh_conversions_coerce_hpp #define oh_conversions_coerce_hpp #include <oh/exception.hpp> #include <sstream> namespace ObjHandler { template <class TypeIn, class TypeOut> class Coerce { public: TypeOut operator()(const TypeIn &in) { Conversion *conversion = getConversions(); TypeOut out; while (conversion) { if ((*conversion)(in, out)) return out; conversion++; } std::ostringstream msg; msg << "Unable to coerce value to type " << typeid(TypeOut).name(); throw Exception(msg.str()); } protected: typedef bool (*Conversion)(const TypeIn&, TypeOut&); virtual Conversion *getConversions() = 0; }; } #endif |