|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r51463 - sandbox/itl/boost/validate/laws
From: afojgo_at_[hidden]
Date: 2009-02-27 04:30:35
Author: jofaber
Date: 2009-02-27 04:30:34 EST (Fri, 27 Feb 2009)
New Revision: 51463
URL: http://svn.boost.org/trac/boost/changeset/51463
Log:
Added law.hpp, law_violations.hpp after moving them to directory laws.
Added:
sandbox/itl/boost/validate/laws/law.hpp (contents, props changed)
sandbox/itl/boost/validate/laws/law_violations.hpp (contents, props changed)
Added: sandbox/itl/boost/validate/laws/law.hpp
==============================================================================
--- (empty file)
+++ sandbox/itl/boost/validate/laws/law.hpp 2009-02-27 04:30:34 EST (Fri, 27 Feb 2009)
@@ -0,0 +1,102 @@
+/*-----------------------------------------------------------------------------+
+A Law Based Test Automaton 'LaBatea'
+Author: Joachim Faulhaber
+Copyright (c) 2007-2009: Joachim Faulhaber
++------------------------------------------------------------------------------+
+ Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file LICENCE.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
++-----------------------------------------------------------------------------*/
+#ifndef __itl_law_hpp_JOFA_070411__
+#define __itl_law_hpp_JOFA_070411__
+
+#include <string>
+#include <set>
+#include <boost/validate/loki_xt/Tuple.h>
+
+namespace boost{namespace itl
+{
+
+ /** abstract template class Law:
+ A Law can hold for a given set of variables.
+ A Law together with the set of input variables is an instance of the law.
+ The evaluation of the law results in a set of output variables.
+ Output variables hold interim and final results of the evaluation of the law.
+ */
+ template
+ <
+ class SubType,
+ typename InputTypes, typename OutputTypes
+ >
+ class Law
+ {
+ public:
+ typedef SubType sub_type;
+ typedef InputTypes input_types;
+ typedef OutputTypes output_types;
+ typedef typename Loki::tuple<InputTypes> input_tuple;
+ typedef typename Loki::tuple<OutputTypes> output_tuple;
+
+ public:
+ bool holds(){ return that()->holds(); }
+ bool debug_holds(){ return that()->debug_holds(); }
+
+ void setInstance(const input_tuple& inVars)
+ { _inputTuple = inVars; }
+
+ void getInstance(input_tuple& inVars, output_tuple& outVars)const
+ { inVars = _inputTuple; outVars = _outputTuple; }
+
+ void getInputInstance(input_tuple& inVars)const
+ { inVars = _inputTuple; }
+
+ void getOutputInstance(output_tuple& outVars)const
+ { outVars = _outputTuple; }
+
+ size_t size()const{ return that()->size(); }
+
+ bool operator == (const Law& rhs)const
+ { return size() == rhs.size(); }
+
+ bool operator < (const Law& rhs)const
+ { return size() < rhs.size(); }
+
+ std::string name()const { return that()->name(); }
+ std::string formula()const { return that()->formula(); }
+ std::string typeString()const { return that()->typeString(); }
+
+ template<unsigned int index>
+ typename Loki::TL::TypeAt<InputTypes, index>::Result
+ setInputValue(const typename Loki::TL::TypeAt<InputTypes, index>::Result& value)
+ { return Loki::tup::refer<index>(_inputTuple)=value; }
+
+ template<unsigned int index>
+ typename Loki::TL::TypeAt<InputTypes, index>::Result getInputValue()const
+ { return Loki::tup::get<index>(_inputTuple); }
+
+ template<unsigned int index>
+ typename Loki::TL::TypeAt<OutputTypes, index>::Result
+ setOutputValue(const typename Loki::TL::TypeAt<OutputTypes, index>::Result& value)
+ { return Loki::tup::refer<index>(_outputTuple)=value; }
+
+ template<unsigned int index>
+ typename Loki::TL::TypeAt<OutputTypes, index>::Result getOutputValue()const
+ { return Loki::tup::get<index>(_outputTuple); }
+
+ protected:
+ sub_type* that() { return static_cast <sub_type*>(this); }
+ const sub_type* that()const { return static_cast<const sub_type*>(this); }
+
+ private:
+ input_tuple _inputTuple;
+ output_tuple _outputTuple;
+ };
+
+
+ enum InputVarIndex { operand_a, operand_b, operand_c, operand_d, operand_e };
+ enum OutputVarIndex { lhs_result, rhs_result };
+
+}} // namespace itl boost
+
+#endif //__itl_law_hpp_JOFA_070411__
+
Added: sandbox/itl/boost/validate/laws/law_violations.hpp
==============================================================================
--- (empty file)
+++ sandbox/itl/boost/validate/laws/law_violations.hpp 2009-02-27 04:30:34 EST (Fri, 27 Feb 2009)
@@ -0,0 +1,176 @@
+/*-----------------------------------------------------------------------------+
+A Law Based Test Automaton 'LaBatea'
+Author: Joachim Faulhaber
+Copyright (c) 2007-2009: Joachim Faulhaber
++------------------------------------------------------------------------------+
+ Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file LICENCE.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
++-----------------------------------------------------------------------------*/
+#ifndef __itl_law_violations_h_JOFA_070411__
+#define __itl_law_violations_h_JOFA_070411__
+
+#include <string>
+#include <boost/itl/set.hpp>
+#include <boost/validate/loki_xt/Tuple.h>
+
+namespace boost{namespace itl
+{
+
+ class LawViolationsI
+ {
+ public:
+ virtual ~LawViolationsI(){}
+
+ virtual size_t size()const=0;
+ virtual size_t getViolationsCount()const=0;
+ virtual LawViolationsI& operator += (const LawViolationsI& rhs)=0;
+
+ virtual const LawViolationsI* getLawViolations()const=0;
+
+ virtual bool operator == (const LawViolationsI& rhs)const=0;
+ virtual bool operator < (const LawViolationsI& rhs)const=0;
+
+ virtual void reportFirst()const=0;
+
+ };
+
+ class PolyLawViolations
+ {
+ public:
+ PolyLawViolations(): p_violations(NULL){}
+ PolyLawViolations(LawViolationsI* vios): p_violations(vios) {}
+ ~PolyLawViolations() {} //JODO delete p_violations; }
+
+ void destroy() { delete p_violations; p_violations = NULL; }
+
+ size_t size()const { return p_violations ? p_violations->size() : 0; }
+ size_t getViolationsCount()const { return p_violations ? p_violations->getViolationsCount() : 0; }
+
+ PolyLawViolations& operator += (const PolyLawViolations& rhs)
+ {
+ if(p_violations == NULL)
+ p_violations = rhs.p_violations;
+ else if(rhs.p_violations != NULL)
+ (*p_violations) += *(rhs.p_violations);
+
+ return *this;
+ }
+
+ bool operator == (const PolyLawViolations& rhs)const
+ {
+ return (p_violations == NULL && rhs.p_violations == NULL)
+ || (
+ ( p_violations != NULL && rhs.p_violations != NULL)
+ &&( p_violations == rhs.p_violations
+ || *p_violations == (*rhs.p_violations))
+ );
+ }
+
+ bool operator < (const PolyLawViolations& rhs)const
+ {
+ return (p_violations != NULL && rhs.p_violations != NULL)
+ && (*p_violations < (*rhs.p_violations));
+ }
+
+ void reportFirst()const
+ {
+ if(p_violations == NULL)
+ std::cout << "Empty law violation." << std::endl;
+ else
+ p_violations->reportFirst();
+ }
+
+ private:
+ LawViolationsI* p_violations;
+ };
+
+
+ /** class LawViolations.
+ LawViolations is a set of instances of a law that are violated sorted by operator <.
+ Operator < will usually be implemented via the size of the laws instance.
+ We are always only interested in small instances of law violations for efficient
+ debugging. */
+ template <class LawT>
+ class LawViolations : public LawViolationsI
+ {
+ public:
+ typedef LawT LawType;
+ typedef typename itl::set<LawType> ViolationSet;
+ typedef typename ViolationSet::size_type size_type;
+
+ typedef typename ViolationSet::iterator iterator;
+ typedef typename ViolationSet::const_iterator const_iterator;
+
+ enum { MaxSize = 20 };
+
+ LawViolations():_maxSize(MaxSize), _violationsCount(0){}
+
+ const LawViolationsI* getLawViolations()const { return this; }
+
+ size_t getViolationsCount()const { return _violationsCount; }
+
+ LawViolationsI& operator += (const LawViolationsI& rhs)
+ {
+ const_FORALL(typename ViolationSet, vio_,
+ dynamic_cast<const LawViolations<LawT>*>(rhs.getLawViolations())->_violations)
+ insert(*vio_);
+
+ return *this;
+ }
+
+ bool operator == (const LawViolationsI& rhs)const
+ {
+ return _violations == dynamic_cast<const LawViolations<LawT>*>(rhs.getLawViolations())->_violations;
+ }
+
+ bool operator < (const LawViolationsI& rhs)const
+ {
+ return _violations < dynamic_cast<const LawViolations<LawT>*>(rhs.getLawViolations())->_violations;
+ }
+
+ void insert(const LawType& lawInstance)
+ {
+ _violations.insert(lawInstance);
+ _violationsCount++;
+ if(0 < _violations.size() && _maxSize < static_cast<int>(_violations.size()))
+ {
+ typename ViolationSet::iterator doomed_ = _violations.end();
+ doomed_--;
+ _violations.erase(doomed_);
+ }
+ }
+
+ iterator begin() { return _violations.begin(); }
+ const_iterator begin()const { return _violations.begin(); }
+ iterator end() { return _violations.end(); }
+ const_iterator end()const { return _violations.begin(); }
+
+ void clear() { _violations.clear(); }
+ bool empty()const { return _violations.empty(); }
+ size_type size()const { return _violations.size(); }
+
+ void reportFirst()const
+ {
+ typename ViolationSet::const_iterator fst = _violations.begin();
+ LawT violation = *(_violations.begin());
+
+ typename LawT::input_tuple inVars;
+ typename LawT::output_tuple outVars;
+ violation.getInstance(inVars, outVars);
+ std::cout << "Violation of: " << violation.typeString() << std::endl;
+ std::cout << inVars.as_string() << std::endl;
+ std::cout << outVars.as_string() << std::endl;
+ }
+
+
+ private:
+ ViolationSet _violations;
+ int _maxSize;
+ size_t _violationsCount;
+ };
+
+}} // namespace itl boost
+
+#endif //__itl_law_violations_h_JOFA_070411__
+
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk