Fixed bug where mask for casting Flags to Type was to small.

This commit is contained in:
Kruno Tomola Fabro 2016-09-05 15:56:08 +01:00
parent 5d235b51f3
commit 0ca1436703
11 changed files with 67 additions and 21 deletions

View File

@ -281,25 +281,29 @@ private:
} else if (equal_str(type, "double[]")) {
std::unique_ptr<Filler> f(
make_array_filler<TG, double, ArrayDouble>(
*this, property_key<TG>(name, Flags::ArrayDouble), to_double));
*this, property_key<TG>(name, Flags::ArrayDouble),
to_double));
return make_option(std::move(f));
} else if (equal_str(type, "int[]")) {
std::unique_ptr<Filler> f(
make_array_filler<TG, int32_t, ArrayInt32>(
*this, property_key<TG>(name, Flags::ArrayInt32), to_int32));
*this, property_key<TG>(name, Flags::ArrayInt32),
to_int32));
return make_option(std::move(f));
} else if (equal_str(type, "long[]")) {
std::unique_ptr<Filler> f(
make_array_filler<TG, int64_t, ArrayInt64>(
*this, property_key<TG>(name, Flags::ArrayInt64), to_int64));
*this, property_key<TG>(name, Flags::ArrayInt64),
to_int64));
return make_option(std::move(f));
} else if (equal_str(type, "string[]")) {
std::unique_ptr<Filler> f(
make_array_filler<TG, string, ArrayString>(
*this, property_key<TG>(name, Flags::ArrayString), to_string));
make_array_filler<TG, std::string, ArrayString>(
*this, property_key<TG>(name, Flags::ArrayString),
to_string));
return make_option(std::move(f));
} else {

View File

@ -44,6 +44,8 @@ public:
VertexAccessor add_vertex()
{
assert(properties_e.empty());
auto va = db.vertex_insert();
for (auto l : labels) {
@ -67,11 +69,13 @@ public:
if (!to_va.is_present()) {
return make_option(std::string("To field must be seted"));
}
if (!type.is_present()) {
return make_option(std::string("Type field must be seted"));
}
assert(properties_v.empty());
auto ve = db.edge_insert(from_va.get(), to_va.get());
if (type.is_present()) {
ve.edge_type(*type.get());
}
ve.edge_type(*type.get());
for (auto prop : properties_e) {
ve.set(std::move(prop));

View File

@ -34,10 +34,14 @@ public:
EdgePropertyFamily &property_family_find_or_create(const std::string &name);
private:
store_t edges;
// TODO: Because familys wont be removed this could be done with more
// efficent
// data structure.
prop_familys_t prop_familys;
// NOTE: this must be before prop_familys field to be destroyed before them.
// Because there are property_family references in vertices.
store_t edges;
AtomicCounter<uint64_t> counter;
};

View File

@ -56,7 +56,9 @@ public:
return true;
}
operator const Arr &() const { return value(); };
// NOTE: OTHER METHODS WILL AUTOMATICALLY USE THIS IN CERTAIN SITUATIONS TO
// MOVE ARR OUT OF SHARED_PTR WHICH IS BAD
// operator const Arr &() const { return value(); };
private:
std::shared_ptr<Arr> data;

View File

@ -59,13 +59,13 @@ enum class Flags : unsigned
ArrayFloat = (Float << 13) | Array,
ArrayDouble = (Double << 13) | Array,
type_mask = 0xFFF
type_mask = 0xFFFFFF
};
// Mask to turn flags into type. It passes all bits except 0x2 and 0x4 which
// correspond
// to True and False.
const unsigned flags_equal_mask = 0xFF9;
const unsigned flags_equal_mask = 0xFF3FF9;
class Type : public TotalOrdering<Type>
{
@ -75,10 +75,13 @@ public:
Flags o = Flags(value);
assert(o == Flags::Null || o == Flags::Bool || o == Flags::String ||
o == Flags::Int32 || o == Flags::Int64 || o == Flags::Float ||
o == Flags::Double || o == Flags::Array);
o == Flags::Double || o == Flags::ArrayBool ||
o == Flags::ArrayString || o == Flags::ArrayInt32 ||
o == Flags::ArrayInt64 || o == Flags::ArrayFloat ||
o == Flags::ArrayDouble);
}
const std::string to_str()
const std::string to_str() const
{
switch (flags()) {
case Flags::Null:
@ -95,8 +98,19 @@ public:
return "float";
case Flags::Double:
return "double";
case Flags::Array:
return "array";
case Flags::ArrayBool:
return "array_bool";
case Flags::ArrayString:
return "array_string";
case Flags::ArrayInt64:
return "array_int64";
case Flags::ArrayInt32:
return "array_int32";
case Flags::ArrayFloat:
return "array_float";
case Flags::ArrayDouble:
return "array_double";
default:
assert(false);
return "err_unknown_type_" + std::to_string(value);
@ -107,6 +121,11 @@ public:
Type get_type() const { return *this; }
bool is_array() const
{
return (value & underlying_cast(Flags::Array)) != 0;
}
template <class T>
bool is() const
{

View File

@ -93,6 +93,11 @@ public:
const PropertyFamily &get_family() const { return type->family; }
const std::string to_str() const
{
return std::string(family_name());
}
private:
const PropertyType *type;
};

View File

@ -98,6 +98,7 @@ public:
default:
assert(false);
}
assert(key.get_type().flags() == Flags::Int64 || this->int64_v != 0);
}
PropertyHolder(PropertyHolder &&other) : key(other.key)
@ -118,6 +119,7 @@ public:
default:
assert(false);
}
assert(key.get_type().flags() == Flags::Int64 || this->int64_v != 0);
}
~PropertyHolder()
@ -133,6 +135,7 @@ public:
{
this->~PropertyHolder();
new (this) PropertyHolder(other);
assert(key.get_type().flags() == Flags::Int64 || this->int64_v != 0);
return *this;
}
@ -140,6 +143,7 @@ public:
{
this->~PropertyHolder();
new (this) PropertyHolder(std::move(other));
assert(key.get_type().flags() == Flags::Int64 || this->int64_v != 0);
return *this;
}

View File

@ -26,7 +26,9 @@ public:
bool operator==(const std::string &other) const;
operator const std::string &() const;
// NOTE: OTHER METHODS WILL AUTOMATICALLY USE THIS IN CERTAIN SITUATIONS
// TO MOVE STD::STRING OUT OF SHARED_PTR WHICH IS BAD.
// operator const std::string &() const;
private:
std::string data;

View File

@ -36,7 +36,7 @@ public:
void handle(const Bool &b) { buffer << (b ? "true" : "false"); }
void handle(const String &s) { buffer << '"' << s << '"'; }
void handle(const String &s) { buffer << '"' << s.value() << '"'; }
void handle(const Int32 &int32) { buffer << std::to_string(int32.value()); }

View File

@ -39,10 +39,14 @@ public:
prop_familys_t::Accessor property_family_access();
private:
vertices_t vertices;
// TODO: Because families wont be removed this could be done with more
// efficent
// data structure.
prop_familys_t prop_familys;
// NOTE: this must be before prop_familys field to be destroyed before them.
// Because there are property_family references in vertices.
vertices_t vertices;
AtomicCounter<uint64_t> counter;
};

View File

@ -2,8 +2,6 @@
const Type String::type = Type(Flags::String);
String::operator const std::string &() const { return value(); }
bool String::operator==(const String &other) const
{
return value() == other.value();