79 lines
1.7 KiB
C++
79 lines
1.7 KiB
C++
#include "matador/object/object.hpp"
|
|
|
|
namespace matador::object {
|
|
object::object(std::string name)
|
|
: name_(std::move(name)) {
|
|
int i = 9;
|
|
}
|
|
|
|
const attribute& object::create_attribute(std::string name, const std::shared_ptr<object>& obj) {
|
|
attribute attr{std::move(name)};
|
|
attr.owner_ = obj;
|
|
return obj->attributes_.emplace_back(std::move(attr));
|
|
}
|
|
|
|
attribute* object::primary_key_attribute() const {
|
|
return pk_attribute_;
|
|
}
|
|
|
|
const utils::identifier& object::primary_key() const {
|
|
return pk_identifier_;
|
|
}
|
|
|
|
bool object::has_primary_key() const {
|
|
return pk_attribute_ != nullptr;
|
|
}
|
|
|
|
const std::string& object::name() const {
|
|
return name_;
|
|
}
|
|
|
|
void object::update_name(const std::string& name) {
|
|
name_ = name;
|
|
// for (auto& con : constraints_) {
|
|
// if (con.is_primary_key_constraint()) {
|
|
// con.name_ += name;
|
|
// } else if (con.is_foreign_key_constraint()) {
|
|
// con.name_ = "FK_" + name + "_" + con.column_name();
|
|
// }
|
|
// }
|
|
}
|
|
|
|
bool object::has_attributes() const {
|
|
return attributes_.empty();
|
|
}
|
|
|
|
size_t object::attribute_count() const {
|
|
return attributes_.size();
|
|
}
|
|
|
|
const std::list<attribute>& object::attributes() const {
|
|
return attributes_;
|
|
}
|
|
|
|
bool object::has_constraints() const {
|
|
return constraints_.empty();
|
|
}
|
|
|
|
size_t object::constraint_count() const {
|
|
return constraints_.size();
|
|
}
|
|
|
|
const std::list<class restriction>& object::constraints() const {
|
|
return constraints_;
|
|
}
|
|
|
|
std::ostream & operator<<(std::ostream &os, const object &obj) {
|
|
os << "Object " << obj.name_ << "\nAttributes:\n";
|
|
for (const auto &attr : obj.attributes_) {
|
|
os << " " << attr << "\n";
|
|
}
|
|
os << "Constraints:\n";
|
|
for (const auto &con : obj.constraints_) {
|
|
os << " " << con << "\n";
|
|
}
|
|
os << "\n";
|
|
return os;
|
|
}
|
|
}
|