record.h
Go to the documentation of this file.
/********************* */
#include "cvc4_public.h"
#ifndef __CVC4__RECORD_H
#define __CVC4__RECORD_H
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include "util/hash.h"
namespace CVC4 {
class CVC4_PUBLIC Record;
// operators for record select and update
class CVC4_PUBLIC RecordSelect {
std::string d_field;
public:
RecordSelect(const std::string& field) throw() : d_field(field) { }
std::string getField() const throw() { return d_field; }
bool operator==(const RecordSelect& t) const throw() { return d_field == t.d_field; }
bool operator!=(const RecordSelect& t) const throw() { return d_field != t.d_field; }
};/* class RecordSelect */
class CVC4_PUBLIC RecordUpdate {
std::string d_field;
public:
RecordUpdate(const std::string& field) throw() : d_field(field) { }
std::string getField() const throw() { return d_field; }
bool operator==(const RecordUpdate& t) const throw() { return d_field == t.d_field; }
bool operator!=(const RecordUpdate& t) const throw() { return d_field != t.d_field; }
};/* class RecordUpdate */
struct CVC4_PUBLIC RecordSelectHashFunction {
inline size_t operator()(const RecordSelect& t) const {
return StringHashFunction()(t.getField());
}
};/* struct RecordSelectHashFunction */
struct CVC4_PUBLIC RecordUpdateHashFunction {
inline size_t operator()(const RecordUpdate& t) const {
return StringHashFunction()(t.getField());
}
};/* struct RecordUpdateHashFunction */
std::ostream& operator<<(std::ostream& out, const RecordSelect& t) CVC4_PUBLIC;
std::ostream& operator<<(std::ostream& out, const RecordUpdate& t) CVC4_PUBLIC;
inline std::ostream& operator<<(std::ostream& out, const RecordSelect& t) {
return out << "[" << t.getField() << "]";
}
inline std::ostream& operator<<(std::ostream& out, const RecordUpdate& t) {
return out << "[" << t.getField() << "]";
}
}/* CVC4 namespace */
#include "expr/expr.h"
#include "expr/type.h"
namespace CVC4 {
// now an actual record definition
class CVC4_PUBLIC Record {
std::vector< std::pair<std::string, Type> > d_fields;
public:
typedef std::vector< std::pair<std::string, Type> >::const_iterator const_iterator;
typedef const_iterator iterator;
Record(const std::vector< std::pair<std::string, Type> >& fields) :
d_fields(fields) {
}
const_iterator find(std::string name) const {
const_iterator i;
for(i = begin(); i != end(); ++i) {
if((*i).first == name) {
break;
}
}
return i;
}
size_t getIndex(std::string name) const {
const_iterator i = find(name);
CheckArgument(i != end(), name, "requested field `%s' does not exist in record", name.c_str());
return i - begin();
}
size_t getNumFields() const {
return d_fields.size();
}
const_iterator begin() const {
return d_fields.begin();
}
const_iterator end() const {
return d_fields.end();
}
std::pair<std::string, Type> operator[](size_t index) const {
CheckArgument(index < d_fields.size(), index, "index out of bounds for record type");
return d_fields[index];
}
bool operator==(const Record& r) const {
return d_fields == r.d_fields;
}
bool operator!=(const Record& r) const {
return !(*this == r);
}
};/* class Record */
struct CVC4_PUBLIC RecordHashFunction {
inline size_t operator()(const Record& r) const {
size_t n = 0;
for(Record::iterator i = r.begin(); i != r.end(); ++i) {
n = (n << 3) ^ TypeHashFunction()((*i).second);
}
return n;
}
};/* struct RecordHashFunction */
std::ostream& operator<<(std::ostream& os, const Record& r) CVC4_PUBLIC;
}/* CVC4 namespace */
#endif /* __CVC4__RECORD_H */
CVC4::RecordSelect
Definition record.h:34
CVC4::RecordSelect::operator==
bool operator==(const RecordSelect &t) const
Definition record.h:39
CVC4::RecordSelect::operator!=
bool operator!=(const RecordSelect &t) const
Definition record.h:40
CVC4::RecordSelect::getField
std::string getField() const
Definition record.h:38
CVC4::RecordSelect::RecordSelect
RecordSelect(const std::string &field)
Definition record.h:37
CVC4::RecordUpdate
Definition record.h:43
CVC4::RecordUpdate::RecordUpdate
RecordUpdate(const std::string &field)
Definition record.h:46
CVC4::RecordUpdate::getField
std::string getField() const
Definition record.h:47
CVC4::RecordUpdate::operator!=
bool operator!=(const RecordUpdate &t) const
Definition record.h:49
CVC4::RecordUpdate::operator==
bool operator==(const RecordUpdate &t) const
Definition record.h:48
CVC4::Record
Definition record.h:84
CVC4::Record::getNumFields
size_t getNumFields() const
Definition record.h:112
CVC4::Record::operator==
bool operator==(const Record &r) const
Definition record.h:129
CVC4::Record::find
const_iterator find(std::string name) const
Definition record.h:96
CVC4::Record::iterator
const_iterator iterator
Definition record.h:90
CVC4::Record::const_iterator
std::vector< std::pair< std::string, Type > >::const_iterator const_iterator
Definition record.h:89
CVC4::Record::operator!=
bool operator!=(const Record &r) const
Definition record.h:133
CVC4::Record::getIndex
size_t getIndex(std::string name) const
Definition record.h:106
CVC4::Record::Record
Record(const std::vector< std::pair< std::string, Type > > &fields)
Definition record.h:92
CVC4::Record::operator[]
std::pair< std::string, Type > operator[](size_t index) const
Definition record.h:124
CVC4::Record::begin
const_iterator begin() const
Definition record.h:116
CVC4::Record::end
const_iterator end() const
Definition record.h:120
cvc4_public.h
Macros that should be defined everywhere during the building of the libraries and driver binary,...
CVC4_PUBLIC
#define CVC4_PUBLIC
Definition cvc4_public.h:30
expr.h
hash.h
[[ Add one-line brief description here ]]
CVC4
Definition expr.h:106
CVC4::operator<<
std::ostream & operator<<(std::ostream &out, const TypeCheckingException &e)
CVC4::CheckArgument
void CheckArgument(bool cond, const T &arg, const char *fmt,...)
Definition exception.h:140
CVC4::RecordHashFunction
Definition record.h:139
CVC4::RecordHashFunction::operator()
size_t operator()(const Record &r) const
Definition record.h:140
CVC4::RecordSelectHashFunction
Definition record.h:52
CVC4::RecordSelectHashFunction::operator()
size_t operator()(const RecordSelect &t) const
Definition record.h:53
CVC4::RecordUpdateHashFunction
Definition record.h:58
CVC4::RecordUpdateHashFunction::operator()
size_t operator()(const RecordUpdate &t) const
Definition record.h:59
CVC4::StringHashFunction
Definition hash.h:49
CVC4::TypeHashFunction
Hash function for Types.
Definition type.h:69
type.h
Interface for expression types.