Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
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;
}