82 lines
1.9 KiB
C++
82 lines
1.9 KiB
C++
#include "matador/object/object.hpp"
|
|
|
|
namespace matador::object {
|
|
object::object(std::string name)
|
|
: name_(std::move(name)) {}
|
|
|
|
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));
|
|
}
|
|
|
|
const attribute* object::primary_key_attribute() const {
|
|
return pk_column_index_ != -1 ? &attributes_.at(pk_column_index_) : nullptr;
|
|
}
|
|
|
|
const utils::identifier& object::primary_key() const {
|
|
return pk_identifier_;
|
|
}
|
|
|
|
bool object::has_primary_key() const {
|
|
return pk_column_index_ != -1;
|
|
}
|
|
|
|
bool object::is_relation_object() const {
|
|
return join_column_index_ != -1 && inverse_join_column_index_ != -1;
|
|
}
|
|
|
|
const attribute * object::join_attribute() const {
|
|
return join_column_index_ != -1 ? &attributes_.at(join_column_index_) : nullptr;
|
|
}
|
|
|
|
const attribute * object::inverse_join_attribute() const {
|
|
return inverse_join_column_index_ != -1 ? &attributes_.at(inverse_join_column_index_) : nullptr;
|
|
}
|
|
|
|
const std::string& object::name() const {
|
|
return name_;
|
|
}
|
|
|
|
void object::update_name(const std::string& name) {
|
|
name_ = name;
|
|
}
|
|
|
|
bool object::has_attributes() const {
|
|
return attributes_.empty();
|
|
}
|
|
|
|
size_t object::attribute_count() const {
|
|
return attributes_.size();
|
|
}
|
|
|
|
const std::vector<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::vector<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;
|
|
}
|
|
}
|