void fromValue(ValuePtr value, int* type, double* scalar, ValueRangePtr** ranges, int* rangeLen, StdStringPtr** strings, int* stringsLen, char** text, int* textLen) { Value_Type t = value->type(); *type = (int) t; if (t == Value_Type_SCALAR) { *scalar = value->mutable_scalar()->value(); } else if (t == Value_Type_RANGES) { *rangeLen = value->mutable_ranges()->range_size(); *ranges = value->mutable_ranges()->mutable_range()->mutable_data(); } else if (t == Value_Type_SET) { *stringsLen = value->set().item_size(); *strings = value->mutable_set()->mutable_item()->mutable_data(); } else if (t == Value_Type_TEXT) { std::string* txt = value->mutable_text()->mutable_value(); *text = (char*) txt->data(); *textLen = txt->size(); } }
AttributePtr toAttribute(char* name, int nameLen, ValuePtr value) { AttributePtr attribute = new Attribute(); attribute->set_name(name, nameLen); attribute->set_type(value->type()); if (value->has_scalar()) *attribute->mutable_scalar() = *value->mutable_scalar(); if (value->has_ranges()) *attribute->mutable_ranges() = *value->mutable_ranges(); if (value->has_set()) *attribute->mutable_set() = *value->mutable_set(); if (value->has_text()) *attribute->mutable_text() = *value->mutable_text(); return attribute; }
void fromAttribute(AttributePtr attribute, char** name, int* nameLen, ValuePtr* vp) { std::string* n = attribute->mutable_name(); *name = (char*) n->data(); *nameLen = n->size(); ValuePtr value = new Value(); value->set_type(attribute->type()); if (attribute->has_scalar()) *value->mutable_scalar() = *attribute->mutable_scalar(); if (attribute->has_ranges()) *value->mutable_ranges() = *attribute->mutable_ranges(); if (attribute->has_set()) *value->mutable_set() = *attribute->mutable_set(); if (attribute->has_text()) *value->mutable_text() = *attribute->mutable_text(); *vp = value; }
ValuePtr toValue(int type, double scalar, ValueRangePtr* ranges, int rangeLen, StdStringPtr* strings, int stringsLen, char* text, int textLen) { ValuePtr value = new Value(); value->set_type((Value_Type) type); if (type == Value_Type_SCALAR) { Value_Scalar s; s.set_value(scalar); *value->mutable_scalar() = s; } else if (type == Value_Type_RANGES) { Value_RangesPtr rs = value->mutable_ranges(); for (int i = 0; i < rangeLen; ++i) *rs->add_range() = *ranges[i]; } else if (type == Value_Type_SET) { Value_SetPtr set = value->mutable_set(); for (int i = 0; i < stringsLen; ++i) set->add_item(*strings[i]); } else if (type == Value_Type_TEXT) { Value_Text t; t.set_value(text, textLen); *value->mutable_text() = t; } return value; }