summaryrefslogtreecommitdiff
path: root/src/expr/record.cpp
diff options
context:
space:
mode:
authorTim King <taking@google.com>2015-12-15 14:35:34 -0800
committerTim King <taking@google.com>2015-12-15 15:28:45 -0800
commit3f29ad74a705883181d9c934a0f772d4850b0b0e (patch)
tree8644e56a4d03390d72eac9bbb7ed7a35cc3b221a /src/expr/record.cpp
parentc358ccba3bf54a85ed9503b636c1f0bab381bc05 (diff)
Breaking the include cycle between Record and Expr.
Diffstat (limited to 'src/expr/record.cpp')
-rw-r--r--src/expr/record.cpp92
1 files changed, 91 insertions, 1 deletions
diff --git a/src/expr/record.cpp b/src/expr/record.cpp
index dfcba0d46..2dee03dbf 100644
--- a/src/expr/record.cpp
+++ b/src/expr/record.cpp
@@ -16,12 +16,74 @@
#include "expr/record.h"
+#include "base/cvc4_assert.h"
+#include "base/output.h"
+#include "expr/expr.h"
+#include "expr/type.h"
+
+
namespace CVC4 {
+static Record::FieldVector::const_iterator find(const Record::FieldVector& fields, std::string name){
+ for(Record::FieldVector::const_iterator i = fields.begin(), i_end = fields.end(); i != i_end; ++i){
+ if((*i).first == name) {
+ return i;
+ }
+ }
+ return fields.end();
+}
+
+Record::Record(const FieldVector& fields)
+ : d_fields(new FieldVector(fields))
+{
+ Debug("record") << "making " << this << " " << d_fields << std::endl;
+}
+
+Record::Record(const Record& other)
+ : d_fields(new FieldVector(other.getFields()))
+{
+ Debug("record") << "copy constructor " << this << " " << d_fields << std::endl;
+}
+
+Record::~Record() {
+ Debug("record") << "deleting " << this << " " << d_fields << std::endl;
+ delete d_fields;
+}
+
+Record& Record::operator=(const Record& r) {
+ Debug("record") << "setting " << this << " " << d_fields << std::endl;
+ Record::FieldVector& local = *d_fields;
+ local = r.getFields();
+ return *this;
+}
+
+const Record::FieldVector& Record::getFields() const {
+ return *d_fields;
+}
+
+bool Record::contains(const std::string& name) const {
+ return find(*d_fields, name) != d_fields->end();
+}
+
+
+size_t Record::getIndex(std::string name) const {
+ FieldVector::const_iterator i = find(*d_fields, name);
+ CheckArgument(i != d_fields->end(), name,
+ "requested field `%s' does not exist in record", name.c_str());
+ return i - d_fields->begin();
+}
+
+size_t Record::getNumFields() const {
+ return d_fields->size();
+}
+
+
std::ostream& operator<<(std::ostream& os, const Record& r) {
os << "[# ";
bool first = true;
- for(Record::iterator i = r.begin(); i != r.end(); ++i) {
+ const Record::FieldVector& fields = r.getFields();
+ for(Record::FieldVector::const_iterator i = fields.begin(),
+ i_end = fields.end(); i != i_end; ++i) {
if(!first) {
os << ", ";
}
@@ -33,4 +95,32 @@ std::ostream& operator<<(std::ostream& os, const Record& r) {
return os;
}
+size_t RecordHashFunction::operator()(const Record& r) const {
+ size_t n = 0;
+ const Record::FieldVector& fields = r.getFields();
+ for(Record::FieldVector::const_iterator i = fields.begin(),
+ i_end = fields.end(); i != i_end; ++i) {
+ n = (n << 3) ^ TypeHashFunction()((*i).second);
+ }
+ return n;
+}
+
+std::ostream& operator<<(std::ostream& out, const RecordSelect& t) {
+ return out << "[" << t.getField() << "]";
+}
+
+std::ostream& operator<<(std::ostream& out, const RecordUpdate& t) {
+ return out << "[" << t.getField() << "]";
+}
+
+
+const std::pair<std::string, Type>& Record::operator[](size_t index) const {
+ CheckArgument(index < d_fields->size(), index, "index out of bounds for record type");
+ return (*d_fields)[index];
+}
+
+bool Record::operator==(const Record& r) const {
+ return (*d_fields) == *(r.d_fields);
+}
+
}/* CVC4 namespace */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback