/usr/include/polybori/diagram/CApplyNodeFacade.h is in libbrial-dev 0.8.5-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | // -*- c++ -*-
//*****************************************************************************
/** @file CApplyNodeFacade.h
*
* @author Alexander Dreyer
* @date 2007-07-16
*
* This files defines a facade as a C++ interface for applying
* C-style functions to C-style pointers, wher represent decision diagrams.
*
* @par Copyright:
* (c) 2007-2010 by The PolyBoRi Team
*
**/
//*****************************************************************************
#ifndef polybori_diagram_CApplyNodeFacade_h
#define polybori_diagram_CApplyNodeFacade_h
// include basic definitions
#include <polybori/pbori_defs.h>
#include <stdexcept>
BEGIN_NAMESPACE_PBORI
/** @class CApplyNodeFacade
* @brief This template class defines a facade as a C++ interface for applying
* C-style functions to C-style structs, which represent decision diagrams.
* It is used to wrapp functions calls to raw pointers of the nodes and the
* context to an C++-style object.
*
* @attention We assume that the @c DiagramType owns member functions @c ring(), @c
* getNode() and @c getManager().
*
* @note This template class is a facade and hence it is intented for
* internal use only, e.g. as a base class for BooleSet.
**/
template <class DiagramType, class NodePtr>
class CApplyNodeFacade {
/// Name type of *this
typedef CApplyNodeFacade self;
public:
/// @name Template arguments
//@{
typedef DiagramType diagram_type;
typedef NodePtr node_ptr;
//@}
/// @name Logical operations
//@{
/// Equality
bool operator==(const diagram_type& rhs) const {
return rhs.getNode() == *this;
}
/// Nonequality
bool operator!=(const diagram_type& rhs) const { return !(*this == rhs); }
//@}
protected:
/// Test, whether both operands
void checkSameManager(const diagram_type& other) const {
if PBORI_UNLIKELY(my().getManager() != other.getManager()) {
throw std::runtime_error("Operands come from different manager.");
}
}
/// @name Apply C-style procedures to nodes
//@{
/// Unary function
template <class MgrType>
diagram_type apply(node_ptr (*func)(MgrType, node_ptr)) const {
return diagram(func(get<MgrType>(), *this));
}
/// Binary function (two diagrams)
template <class MgrType>
diagram_type apply(node_ptr (*func)(MgrType, node_ptr, node_ptr),
const diagram_type& rhs) const {
checkSameManager(rhs);
return diagram(func(get<MgrType>(), *this, rhs));
}
/// Ternary function (three diagrams)
template <class MgrType>
diagram_type apply(node_ptr (*func)(MgrType, node_ptr, node_ptr, node_ptr),
const diagram_type& first, const diagram_type& second) const {
checkSameManager(first);
checkSameManager(second);
return diagram(func(get<MgrType>(), *this, first, second));
}
/// Binary functions with non-diagram right-hand side
template <class MgrType, class Type>
diagram_type apply(node_ptr(*func)(MgrType, node_ptr, Type), Type value) const {
return diagram(func(get<MgrType>(), *this, value));
}
/// Unary functions with non-diagram result value
template <class MgrType, class ResultType>
ResultType apply(ResultType(*func)(MgrType, node_ptr)) const {
return func(get<MgrType>(), *this);
}
// @}
/// Get diagram of the same context
diagram_type diagram(node_ptr node) const {
return diagram_type(my().ring(), node);
}
private:
/// Accessing the actual type, for which this facade is inteded to be used for
const diagram_type& my() const {
return static_cast<const diagram_type&>(*this);
}
/// Accessing raw manager
template<class MgrType>
MgrType get() const { return my().getManager(); }
/// This (and only this) class may automatically convert *this to raw pointer
operator node_ptr() const { return my().getNode(); }
};
END_NAMESPACE_PBORI
#endif
|