Example #1
0
const char * GFFField::tostring(char * buffer, int nMax, int nIndex){

	switch (this->Type){

		case 0:sprintf(buffer, "%u", AsByte()); break;
		case 1:sprintf(buffer, "%d", AsChar()); break;
		case 2:sprintf(buffer, "%u", AsWord()); break;
		case 3:sprintf(buffer, "%d", AsShort()); break;
		case 4:sprintf(buffer, "%u", AsDword()); break;
		case 5:sprintf(buffer, "%d", AsInt()); break;
		case 6:sprintf(buffer, "%llu", AsDword64()); break;
		case 7:sprintf(buffer, "%lld", AsInt64()); break;
		case 8:sprintf(buffer, "%f", AsFloat()); break;
		case 9:sprintf(buffer, "%Lf", AsDouble()); break;
		case 10:strncpy(buffer, AsExoString()->str, nMax); break;
		case 11:strncpy(buffer, AsResRef()->str, nMax); break;
		case 12:
			
			if (nIndex >= (int)AsExoLocString()->StringCount)
				buffer[0] = '\0';
			else				
				strncpy(buffer, AsExoLocString()->SubString[nIndex].str, nMax); 
			break;
		case 13:sprintf(buffer, "<binary %u bytes>", AsVoid()->Size); break;
		case 14:sprintf(buffer, "struct ID: %d", AsStruct()->Type ); break;
		case 15:sprintf(buffer, "list %i entries", AsList()->Size); break;
		default:buffer[0] = '\0'; break;
	}

	return buffer;
}
Example #2
0
File: Value.cpp Project: krf/QOds
void
Value::SetDouble(const double d)
{
	DeleteData();
	type_ = ods::Type::Double;
	data_ = new double();
	*AsDouble() = d;
}
Example #3
0
LLBC_Variant &LLBC_Variant::BecomeDouble()
{
    if (!IsDouble())
    {
        *this = AsDouble();
    }

    return *this;
}
Example #4
0
File: Value.cpp Project: krf/QOds
void
Value::DeleteData()
{
	if (!Ok())
		return;
	if (IsDouble() || IsPercentage())
		delete AsDouble();
	else if (IsString())
		delete AsString();
	else if (IsDate())
		delete AsDate();
	else if (IsDuration())
		delete AsDuration();
	data_ = nullptr;
	type_ = ods::Type::NotSet;
}
Example #5
0
File: Value.cpp Project: krf/QOds
QString
Value::toString() const
{
	if (!Ok())
		return "";
	
	if (IsDouble() || IsPercentage())
		return QString::number(*AsDouble());
	if (IsString())
		return *AsString();
	if (IsDate())
		return AsDate()->toString(Qt::ISODate);
	if (IsCurrency())
		mtl_qline("Currency not supported yet");
	if (IsDuration())
		return AsDuration()->ToString();
	
	return "";
}
Example #6
0
File: Value.cpp Project: krf/QOds
void
Value::CopyTo(ods::Value &v)
{
	v.type_set(type_);
	if (NoValue())
		return;
	if (IsDouble())
		v.SetDouble(*AsDouble());
	else if (IsString())
		v.SetString(*AsString());
	else if (IsCurrency())
		v.SetCurrency(*AsCurrency());
	else if (IsPercentage())
		v.SetPercentage(*AsPercentage());
	else if (IsDate())
		v.SetDate(*AsDate());
	else if (IsDuration())
		v.SetDuration(*AsDuration());
	else
		mtl_warn("Not implemented");
}
/*************************************
 * operator ==
 *************************************/
bool SHVDataVariantImpl::operator==(const SHVDataVariant& val) const
{
	if (DataType == val.GetDataType())
	{
		switch (DataType)
		{
		case SHVDataVariant::TypeInt:
			return AsInt() == val.AsInt();
		case SHVDataVariant::TypeInt64:
			return AsInt64() == val.AsInt64();
		case SHVDataVariant::TypeBool:
			return AsBool() == val.AsBool();
		case SHVDataVariant::TypeDouble:
			return AsDouble() == val.AsDouble();
		case SHVDataVariant::TypeString:
			return AsString() == val.AsString();
		case SHVDataVariant::TypeTime:
			return (AsTime() == val.AsTime() ? true : false);
			break;
		}
	}
	return false;
}
Example #8
0
LLBC_Variant::operator double() const
{
    return AsDouble();
}
Example #9
0
float LLBC_Variant::AsFloat() const
{
    return static_cast<float>(AsDouble());
}
Example #10
0
bool ff::Value::Convert(Type type, Value **ppValue) const
{
	assertRetVal(ppValue, false);
	*ppValue = nullptr;

	if (type == GetType())
	{
		*ppValue = GetAddRef(const_cast<Value *>(this));
		return true;
	}

	wchar_t buf[256];

	switch (GetType())
	{
	case Type::Null:
		switch (type)
		{
		case Type::String:
			CreateString(String(L"null"), ppValue);
			break;
		}
		break;

	case Type::Bool:
		switch (type)
		{
		case Type::Double:
			CreateDouble(AsBool() ? 1.0 : 0.0, ppValue);
			break;

		case Type::Float:
			CreateFloat(AsBool() ? 1.0f : 0.0f, ppValue);
			break;

		case Type::Int:
			CreateInt(AsBool() ? 1 : 0, ppValue);
			break;

		case Type::String:
			CreateString(AsBool() ? String(L"true") : String(L"false"), ppValue);
			break;
		}
		break;

	case Type::Double:
		switch (type)
		{
		case Type::Bool:
			CreateBool(AsDouble() != 0, ppValue);
			break;

		case Type::Float:
			CreateFloat((float)AsDouble(), ppValue);
			break;

		case Type::Int:
			CreateInt((int)AsDouble(), ppValue);
			break;

		case Type::String:
			_snwprintf_s(buf, _countof(buf), _TRUNCATE, L"%g", AsDouble());
			CreateString(String(buf), ppValue);
			break;
		}
		break;

	case Type::Float:
		switch (type)
		{
		case Type::Bool:
			CreateBool(AsFloat() != 0, ppValue);
			break;

		case Type::Double:
			CreateDouble((double)AsFloat(), ppValue);
			break;

		case Type::Int:
			CreateInt((int)AsFloat(), ppValue);
			break;

		case Type::String:
			_snwprintf_s(buf, _countof(buf), _TRUNCATE, L"%g", AsFloat());
			CreateString(String(buf), ppValue);
			break;
		}
		break;

	case Type::Int:
		switch (type)
		{
		case Type::Bool:
			CreateBool(AsInt() != 0, ppValue);
			break;

		case Type::Double:
			CreateDouble((double)AsInt(), ppValue);
			break;

		case Type::Float:
			CreateFloat((float)AsInt(), ppValue);
			break;

		case Type::String:
			_snwprintf_s(buf, _countof(buf), _TRUNCATE, L"%d", AsInt());
			CreateString(String(buf), ppValue);
			break;
		}
		break;

	case Type::Point:
		switch (type)
		{
		case Type::String:
			_snwprintf_s(buf, _countof(buf), _TRUNCATE, L"(%d,%d)", AsPoint().x, AsPoint().y);
			CreateString(String(buf), ppValue);
			break;
		}
		break;

	case Type::PointF:
		switch (type)
		{
		case Type::String:
			_snwprintf_s(buf, _countof(buf), _TRUNCATE, L"(%g,%g)", AsPointF().x, AsPointF().y);
			CreateString(String(buf), ppValue);
			break;
		}
		break;

	case Type::Rect:
		switch (type)
		{
		case Type::String:
			_snwprintf_s(buf, _countof(buf), _TRUNCATE, L"(%d,%d,%d,%d)",
				AsRect().left, AsRect().top, AsRect().right, AsRect().bottom);
			CreateString(String(buf), ppValue);
			break;
		}
		break;

	case Type::RectF:
		switch (type)
		{
		case Type::String:
			_snwprintf_s(buf, _countof(buf), _TRUNCATE, L"(%g,%g,%g,%g)",
				AsRectF().left, AsRectF().top, AsRectF().right, AsRectF().bottom);
			CreateString(String(buf), ppValue);
			break;
		}
		break;

	case Type::String:
		switch (type)
		{
		case Type::Bool:
			if (AsString().empty() || AsString() == L"false" || AsString() == L"no" || AsString() == L"0")
			{
				CreateBool(false, ppValue);
			}
			else if (AsString() == L"true" || AsString() == L"yes" || AsString() == L"1")
			{
				CreateBool(true, ppValue);
			}
			break;

		case Type::Double:
			{
				const wchar_t *start = AsString().c_str();
				wchar_t *end = nullptr;
				double val = wcstod(start, &end);

				if (end > start && !*end)
				{
					CreateDouble(val, ppValue);
				}
			} break;

		case Type::Float:
			{
				const wchar_t *start = AsString().c_str();
				wchar_t *end = nullptr;
				double val = wcstod(start, &end);

				if (end > start && !*end)
				{
					CreateFloat((float)val, ppValue);
				}
			} break;

		case Type::Int:
			{
				const wchar_t *start = AsString().c_str();
				wchar_t *end = nullptr;
				long val = wcstol(start, &end, 10);

				if (end > start && !*end)
				{
					CreateInt((int)val, ppValue);
				}
			} break;

		case Type::Guid:
			{
				GUID guid;
				if (StringToGuid(AsString(), guid))
				{
					CreateGuid(guid, ppValue);
				}
			} break;
		}
		break;

	case Type::Object:
		switch (type)
		{
		case Type::Bool:
			CreateBool(AsObject() != nullptr, ppValue);
			break;
		}
		break;

	case Type::Guid:
		switch (type)
		{
		case Type::String:
			CreateString(StringFromGuid(AsGuid()), ppValue);
			break;
		}
		break;

	case Type::Data:
		switch (type)
		{
		case Type::SavedData:
			{
				ff::ComPtr<ff::ISavedData> savedData;
				if (ff::CreateLoadedDataFromMemory(AsData(), false, &savedData))
				{
					CreateSavedData(savedData, ppValue);
				}
			}
			break;
		}
		break;

	case Type::SavedData:
		switch (type)
		{
		case Type::Data:
			{
				ff::ComPtr<ff::ISavedData> savedData;
				if (AsSavedData()->Clone(&savedData))
				{
					ff::ComPtr<ff::IData> data = savedData->Load();
					if (data)
					{
						CreateData(data, ppValue);
					}
				}
			}
			break;
		}
		break;

	case Type::Dict:
		switch (type)
		{
		case Type::Data:
		case Type::SavedData:
		case Type::SavedDict:
			{
				ff::ComPtr<ff::IData> data;
				ff::ComPtr<ff::ISavedData> savedData;

				if (ff::SaveDict(AsDict(), true, false, &data))
				{
					if (type == Type::Data)
					{
						CreateData(data, ppValue);
					}
					else if (ff::CreateLoadedDataFromMemory(data, true, &savedData))
					{
						if (type == Type::SavedData)
						{
							CreateSavedData(savedData, ppValue);
						}
						else
						{
							CreateSavedDict(savedData, ppValue);
						}
					}
				}
			}
			break;
		}
		break;

	case Type::SavedDict:
		switch (type)
		{
		case Type::Data:
			{
				ff::ComPtr<ff::ISavedData> savedData;
				if (AsSavedData()->Clone(&savedData))
				{
					ff::ComPtr<ff::IData> data = savedData->Load();
					if (data)
					{
						CreateData(data, ppValue);
					}
				}
			}
			break;

		case Type::SavedData:
			CreateSavedData(AsSavedData(), ppValue);
			break;

		case Type::Dict:
			{
				ff::ComPtr<ff::ISavedData> savedData;
				if (AsSavedData()->Clone(&savedData))
				{
					ff::ComPtr<ff::IData> data = savedData->Load();
					ff::ComPtr<ff::IDataReader> dataReader;
					Dict dict;

					if (data && ff::CreateDataReader(data, 0, &dataReader) && ff::LoadDict(dataReader, dict))
					{
						CreateDict(std::move(dict), ppValue);
					}
				}
			}
			break;
		}
		break;

	case Type::Resource:
		AsResource()->GetValue()->Convert(type, ppValue);
		break;

	case Type::IntVector:
		switch (type)
		{
		case Type::Point:
			if (AsIntVector().Size() == 2)
			{
				PointInt point(
					AsIntVector().GetAt(0),
					AsIntVector().GetAt(1));
				CreatePoint(point, ppValue);
			}
			break;

		case Type::Rect:
			if (AsIntVector().Size() == 4)
			{
				RectInt rect(
					AsIntVector().GetAt(0),
					AsIntVector().GetAt(1),
					AsIntVector().GetAt(2),
					AsIntVector().GetAt(3));
				CreateRect(rect, ppValue);
			}
			break;
		}
		break;

	case Type::FloatVector:
		switch (type)
		{
		case Type::PointF:
			if (AsFloatVector().Size() == 2)
			{
				PointFloat point(
					AsFloatVector().GetAt(0),
					AsFloatVector().GetAt(1));
				CreatePointF(point, ppValue);
			}
			break;

		case Type::RectF:
			if (AsFloatVector().Size() == 4)
			{
				RectFloat rect(
					AsFloatVector().GetAt(0),
					AsFloatVector().GetAt(1),
					AsFloatVector().GetAt(2),
					AsFloatVector().GetAt(3));
				CreateRectF(rect, ppValue);
			}
			break;
		}
		break;

	case Type::ValueVector:
		switch (type)
		{
		case Type::Point:
			if (AsValueVector().Size() == 2)
			{
				ValuePtr newValues[2];
				const Vector<ValuePtr> &values = AsValueVector();
				if (values[0]->Convert(Type::Int, &newValues[0]) &&
					values[1]->Convert(Type::Int, &newValues[1]))
				{
					CreatePoint(PointInt(newValues[0]->AsInt(), newValues[1]->AsInt()), ppValue);
				}
			}
			break;

		case Type::PointF:
			if (AsValueVector().Size() == 2)
			{
				ValuePtr newValues[2];
				const Vector<ValuePtr> &values = AsValueVector();
				if (values[0]->Convert(Type::Float, &newValues[0]) &&
					values[1]->Convert(Type::Float, &newValues[1]))
				{
					CreatePointF(PointFloat(newValues[0]->AsFloat(), newValues[1]->AsFloat()), ppValue);
				}
			}
			break;

		case Type::Rect:
			if (AsValueVector().Size() == 4)
			{
				ValuePtr newValues[4];
				const Vector<ValuePtr> &values = AsValueVector();
				if (values[0]->Convert(Type::Int, &newValues[0]) &&
					values[1]->Convert(Type::Int, &newValues[1]) &&
					values[2]->Convert(Type::Int, &newValues[2]) &&
					values[3]->Convert(Type::Int, &newValues[3]))
				{
					CreateRect(RectInt(
						newValues[0]->AsInt(),
						newValues[1]->AsInt(),
						newValues[2]->AsInt(),
						newValues[3]->AsInt()), ppValue);
				}
			}
			break;

		case Type::RectF:
			if (AsValueVector().Size() == 4)
			{
				ValuePtr newValues[4];
				const Vector<ValuePtr> &values = AsValueVector();
				if (values[0]->Convert(Type::Float, &newValues[0]) &&
					values[1]->Convert(Type::Float, &newValues[1]) &&
					values[2]->Convert(Type::Float, &newValues[2]) &&
					values[3]->Convert(Type::Float, &newValues[3]))
				{
					CreateRectF(RectFloat(
						newValues[0]->AsFloat(),
						newValues[1]->AsFloat(),
						newValues[2]->AsFloat(),
						newValues[3]->AsFloat()), ppValue);
				}
			}
			break;

		case Type::StringVector:
			{
				bool valid = true;
				Vector<String> newValues;
				const Vector<ValuePtr> &values = AsValueVector();
				for (ValuePtr oldValue : values)
				{
					ValuePtr newValue;
					valid = oldValue->Convert(Type::String, &newValue);
					if (valid)
					{
						newValues.Push(newValue->AsString());
					}
					else
					{
						break;
					}
				}

				if (valid)
				{
					CreateStringVector(std::move(newValues), ppValue);
				}
			}
			break;

		case Type::IntVector:
			{
				bool valid = true;
				Vector<int> newValues;
				const Vector<ValuePtr> &values = AsValueVector();
				for (ValuePtr oldValue : values)
				{
					ValuePtr newValue;
					valid = oldValue->Convert(Type::Int, &newValue);
					if (valid)
					{
						newValues.Push(newValue->AsInt());
					}
					else
					{
						break;
					}
				}

				if (valid)
				{
					CreateIntVector(std::move(newValues), ppValue);
				}
			}
			break;

		case Type::DoubleVector:
			{
				bool valid = true;
				Vector<double> newValues;
				const Vector<ValuePtr> &values = AsValueVector();
				for (ValuePtr oldValue : values)
				{
					ValuePtr newValue;
					valid = oldValue->Convert(Type::Double, &newValue);
					if (valid)
					{
						newValues.Push(newValue->AsDouble());
					}
					else
					{
						break;
					}
				}

				if (valid)
				{
					CreateDoubleVector(std::move(newValues), ppValue);
				}
			}
			break;

		case Type::FloatVector:
			{
				bool valid = true;
				Vector<float> newValues;
				const Vector<ValuePtr> &values = AsValueVector();
				for (ValuePtr oldValue : values)
				{
					ValuePtr newValue;
					valid = oldValue->Convert(Type::Float, &newValue);
					if (valid)
					{
						newValues.Push(newValue->AsFloat());
					}
					else
					{
						break;
					}
				}

				if (valid)
				{
					CreateFloatVector(std::move(newValues), ppValue);
				}
			}
			break;
		}
		break;
	}

	if (*ppValue)
	{
		return true;
	}

	return false;
}
Example #11
0
bool ff::Value::operator==(const Value &r) const
{
	if (this == &r)
	{
		return true;
	}

	if (GetType() != r.GetType())
	{
		return false;
	}

	switch (GetType())
	{
		case Type::Null:
			return true;

		case Type::Bool:
			return AsBool() == r.AsBool();

		case Type::Double:
			return AsDouble() == r.AsDouble();

		case Type::Float:
			return AsFloat() == r.AsFloat();

		case Type::Int:
			return AsInt() == r.AsInt();

		case Type::Object:
			return AsObject() == r.AsObject();

		case Type::Point:
			return AsPoint() == r.AsPoint();

		case Type::PointF:
			return AsPointF() == r.AsPointF();

		case Type::Rect:
			return AsRect() == r.AsRect();

		case Type::RectF:
			return AsRectF() == r.AsRectF();

		case Type::String:
			return AsString() == r.AsString();

		case Type::StringVector:
			return AsStringVector() == r.AsStringVector();

		case Type::ValueVector:
			return AsValueVector() == r.AsValueVector();

		case Type::Guid:
			return AsGuid() == r.AsGuid() ? true : false;

		case Type::IntVector:
			return AsIntVector() == r.AsIntVector();

		case Type::DoubleVector:
			return AsDoubleVector() == r.AsDoubleVector();

		case Type::FloatVector:
			return AsFloatVector() == r.AsFloatVector();

		case Type::DataVector:
			return AsDataVector() == r.AsDataVector();

		case Type::Data:
			return AsData() == r.AsData();

		case Type::SavedData:
		case Type::SavedDict:
			return AsSavedData() == r.AsSavedData();

		default:
			assert(false);
			return false;
	}
}