1、定义。
/**
* \brief %Choice for performing commit
*
* Must be refined by inheritance such that the information stored
* inside a choice is sufficient to redo a commit performed by a
* particular brancher.
*
* \ingroup TaskActor
*/
class GECODE_VTABLE_EXPORT Choice : public HeapAllocated {
friend class Space;
private:
unsigned int bid; ///< Identity to match creating brancher
unsigned int alt; ///< Number of alternatives
/// Return id of the creating brancher
unsigned int id(void) const;
protected:
/// Initialize for particular brancher \a b and alternatives \a a
Choice(const Brancher& b, const unsigned int a);
public:
/// Return number of alternatives
unsigned int alternatives(void) const;
/// Destructor
GECODE_KERNEL_EXPORT virtual ~Choice(void);
/// Report size occupied by choice
virtual size_t size(void) const = 0;
/// Archive into \a e
GECODE_KERNEL_EXPORT
virtual void archive(Archive& e) const;
};
2、实现。
/*
* Choices
*
*/
forceinline
Choice::Choice(const Brancher& b, const unsigned int a)
: bid(b.id()), alt(a) {}
forceinline unsigned int
Choice::alternatives(void) const {
return alt;
}
forceinline unsigned int
Choice::id(void) const {
return bid;
}
forceinline
Choice::~Choice(void) {}
时间: 2024-10-21 08:46:30