Ejemplo n.º 1
0
 bool Rule::Variant::loadFromStream(istream& stream)
 {
     if (isString() && data.String.value)
     {
         destruct_range(data.String.value, data.String.value + data.String.size + 1);
         allocator<char>::deallocate(data.String.value, data.String.size + 1);
     }
     stream >> type;
     switch (trueType())
     {
     case TFromTo:
         stream >> data.Char.value1 >> data.Char.value2;
         return true;
     case TChar:
         stream >> data.Char.value1;
         return true;
     case TString:
         stream >> data.String.size;
         data.String.value = allocator<char>::allocate(data.String.size + 1);
         if (!stream.readToBuffer(data.String.value, data.String.size)) return false;
         data.String.value[data.String.size] = 0;
         return true;
     default:
         return false;
     }
 }
Ejemplo n.º 2
0
 bool Rule::Variant::loadFromData(const char*& buffer)
 {
     if (isString() && data.String.value)
     {
         destruct_range(data.String.value, data.String.value + data.String.size + 1);
         allocator<char>::deallocate(data.String.value, data.String.size + 1);
     }
     type = *buffer;
     ++buffer;
     switch (trueType())
     {
     case TFromTo:
         data.Char.value1 = *buffer;
         ++buffer;
         data.Char.value2 = *buffer;
         ++buffer;
         return true;
     case TChar:
         data.Char.value1 = *buffer;
         ++buffer;
         return true;
     case TString:
         data.String.size = *reinterpret_cast<const size_t*>(buffer);
         buffer += sizeof(size_t);
         data.String.value = allocator<char>::allocate(data.String.size + 1);
         if (!memcpy(data.String.value, buffer, data.String.size)) return false;
         buffer += data.String.size;
         data.String.value[data.String.size] = 0;
         return true;
     default:
         return false;
     }
 }
Ejemplo n.º 3
0
 Rule::Variant& Rule::Variant::operator=(const Variant& x)
 {
     if (&x != this)
     {
         if (x.isString() && isString())
         {
             destruct_range(data.String.value, data.String.value + data.String.size + 1);
             allocator<char>::deallocate(data.String.value, data.String.size + 1);
         }
         type = x.type;
         switch (trueType())
         {
         case TFromTo:
         case TChar:
             memcpy(&data, &x.data, sizeof(data));
             break;
         case TString:
             data.String.size  = x.data.String.size;
             data.String.value = allocator<char>::allocate(data.String.size + 1);
             strcpy(data.String.value, x.data.String.value);
             data.String.value[data.String.size] = 0;
             break;
         default:
             break;
         }
     }
     return *this;
 }
Ejemplo n.º 4
0
 Rule::Variant::~Variant()
 {
     if (isString() && data.String.value)
     {
         destruct_range(data.String.value, data.String.value + data.String.size + 1);
         allocator<char>::deallocate(data.String.value, data.String.size + 1);
     }
 }
Ejemplo n.º 5
0
	void MaxArray<T,C>::clear() {
		destruct_range(data(), _size);
		_size = 0;
	}
Ejemplo n.º 6
0
	MaxArray<T,C>::~MaxArray() {
		destruct_range(data(), _size);
	}