1 #ifndef FAIF_VALUE_HPP_ 2 #define FAIF_VALUE_HPP_ 4 #if defined(_MSC_VER) && (_MSC_VER >= 1400) 6 #pragma warning(disable:4100) 15 #include <boost/bind.hpp> 16 #include <boost/concept_check.hpp> 17 #include <boost/serialization/serialization.hpp> 18 #include <boost/serialization/list.hpp> 19 #include <boost/serialization/nvp.hpp> 21 #include "ExceptionsFaif.hpp" 40 template<
typename Val>
42 : boost::EqualityComparable<Val>, boost::DefaultConstructible<Val>,
43 boost::CopyConstructible<Val>, boost::Assignable<Val> {
45 typedef typename Val::ValueTag ValueTag;
46 typedef typename Val::Value Value;
47 typedef typename Val::DomainType DomainType;
67 BOOST_CONCEPT_ASSERT(( boost::EqualityComparable<Val> ));
68 BOOST_CONCEPT_ASSERT(( boost::DefaultConstructible<Val> ));
69 BOOST_CONCEPT_ASSERT(( boost::CopyConstructible<Val> ));
70 BOOST_CONCEPT_ASSERT(( boost::Assignable<Val> ));
83 ValueNominal(
const Value& val, DomainType* d) : val_(val), domain_(d) {}
99 Value&
get() {
return val_; }
102 const Value&
get()
const {
return val_; }
123 template<
class Archive>
125 ar & boost::serialization::make_nvp(
"ValueVal", val_ );
126 ar & boost::serialization::make_nvp(
"ValueDomain", domain_ );
139 template<
typename Dom>
140 struct DomainConcept : boost::EqualityComparable<Dom>, boost::DefaultConstructible<Dom>,
141 boost::CopyConstructible<Dom>, boost::Assignable<Dom> {
143 typedef typename Dom::ValueTag ValueTag;
144 typedef typename Dom::Value Value;
145 typedef typename Dom::ValueId ValueId;
146 typedef typename Dom::iterator iterator;
147 typedef typename Dom::const_iterator const_iterator;
160 template <
typename Val>
165 typedef typename Val::ValueTag ValueTag;
167 typedef const Val* ValueId;
168 typedef Val* ValueIdSerialize;
169 typedef ValueNominalString* AttrIddSerialize;
171 typedef std::list<Val> Container;
172 typedef typename Container::iterator iterator;
173 typedef typename Container::const_iterator const_iterator;
186 std::string
getId()
const {
return id_; }
195 return &(Value::getUnknown());
199 int getSize()
const {
return static_cast<int>(values_.size()); }
208 iterator
begin() {
return values_.begin(); }
210 iterator
end() {
return values_.end(); }
213 const_iterator
begin()
const {
return values_.begin(); }
215 const_iterator
end()
const {
return values_.end(); }
219 ValueId insert(
const typename Val::Value& value);
222 ValueId find(
const typename Val::Value& value)
const;
225 template<
class Archive>
227 ar & boost::serialization::make_nvp(
"DomainId", id_ );
228 ar & boost::serialization::make_nvp(
"DomainValues", values_ );
238 template <
typename T>
241 for(T* i = begin; i != end; ++i) {
248 template <
typename Value> std::ostream& operator<<(std::ostream& os, const ValueNominal<Value>& a) {
249 if(a.getDomain() == 0L)
252 os << a.getDomain()->
getId() <<
"=" << a.get();
257 template <
typename Value> std::ostream& operator<<(std::ostream& os, const ValueNominal<Value>* a) {
259 return operator<<(os, *a);
266 template <
typename Val>
267 std::ostream& operator<<(std::ostream& os, const DomainEnumerate<Val>& domain) {
268 std::copy(domain.begin(), domain.end(), std::ostream_iterator<Val>(os,
","));
274 template <
typename Val>
275 Val TransformFunction(
const Val& a,
typename Val::DomainType* d) {
276 return Val(a.get(),d);
283 template <
typename Val>
287 std::transform(d.values_.begin(), d.values_.end(), std::back_inserter<Container>(values_),
288 boost::bind(&TransformFunction<Val>, _1,
this) );
292 template <
typename Val>
301 std::transform(d.values_.begin(), d.values_.end(), std::back_inserter<Container>(values_),
302 boost::bind(&TransformFunction<Val>, _1,
this) );
308 template<
typename Val>
309 typename DomainEnumerate<Val>::ValueId
311 Val attr(value,
this);
312 const_iterator found = std::find( values_.begin(), values_.end(), attr );
313 if( found != values_.end() )
316 return getValueId( values_.insert( values_.end(), Val(value,
this) ) );
322 template<
typename Val>
323 typename DomainEnumerate<Val>::ValueId
326 const_iterator found = std::find( values_.begin(), values_.end(), attr );
327 if( found != values_.end() ) {
335 #endif //FAIF_VALUE_HPP_ DomainEnumerate & operator=(const DomainEnumerate &)
assignment (transform the parent pointers)
Definition: Value.hpp:294
bool operator!=(const ValueNominal &v) const
the equality comparison
Definition: Value.hpp:114
~ValueNominal()
d-tor
Definition: Value.hpp:96
ValueNominal & operator=(const ValueNominal &a)
assign operator
Definition: Value.hpp:89
std::string getId() const
accessor
Definition: Value.hpp:186
bool operator!=(const DomainEnumerate &d) const
Definition: Value.hpp:205
iterator begin()
accessor
Definition: Value.hpp:208
bool operator==(const ValueNominal &v) const
the equality comparison
Definition: Value.hpp:111
void serialize(Archive &ar, const unsigned int)
serialization using boost::serialization
Definition: Value.hpp:226
the domain concept
Definition: Value.hpp:140
nominal_tag ValueTag
the attribute trait
Definition: Value.hpp:73
iterator end()
accessor
Definition: Value.hpp:210
ordered attribute trait (equality comparable, less than comparable) , modeled as element in ordered s...
Definition: Value.hpp:29
int getSize() const
accessor
Definition: Value.hpp:199
const DomainType * getDomain() const
accessor - domain
Definition: Value.hpp:108
nominal attribute trait (equality comparable), modeled as element in unordered set ...
Definition: Value.hpp:26
const_iterator end() const
accessor
Definition: Value.hpp:215
forward declaration
Definition: Value.hpp:60
const_iterator begin() const
accessor
Definition: Value.hpp:213
the value concept
Definition: Value.hpp:41
interval attribute trait (equality comparable, less than comparable, distance), integer numbers ...
Definition: Value.hpp:32
static ValueId getValueId(const_iterator it)
return the value id for given value iterator
Definition: Value.hpp:189
bool operator==(const DomainEnumerate &d) const
Definition: Value.hpp:202
nominal attribute trait (equality comparable, less than comparable, distance, continuous), real numbers
Definition: Value.hpp:35
bool isUnknown() const
accessor
Definition: Value.hpp:105
ValueNominal()
c-tor. Create UNKNOWN Value
Definition: Value.hpp:80
ValueId find(const typename Val::Value &value) const
return the first iterator to attribute equal to given
Definition: Value.hpp:324
static ValueNominal & getUnknown()
return the unknown value object
Definition: Value.hpp:117
ValueId insert(const typename Val::Value &value)
search for value equal to given, if found return the value identifier, otherwise insert new into coll...
Definition: Value.hpp:310
ValueNominal(const Value &val, DomainType *d)
c-tor
Definition: Value.hpp:83
static ValueId getUnknownId()
return the value id for unknown value
Definition: Value.hpp:194
nominal attribute template (equality comparable)
Definition: Value.hpp:65
void serialize(Archive &ar, const unsigned int)
serialization using boost::serialization
Definition: Value.hpp:124
ValueNominal(const ValueNominal &a)
c-tor
Definition: Value.hpp:86
the exception thrown when the value for given attribute is not found
Definition: ExceptionsFaif.hpp:32