Example #1
0
bool XMLElement::SetVariant(const Variant& value)
{
    if (!SetAttribute("type", value.GetTypeName()))
        return false;

    return SetVariantValue(value);
}
Example #2
0
void JSONValue::AddVariant(const Variant& value)
{
    // Create child object for variant
    JSONValue child = CreateChild(JSON_OBJECT);
    // Set type
    child.SetString("type", value.GetTypeName());
    // Set value
    child.SetVariantValue("value", value);
}
Example #3
0
void JSONValue::SetVariant(const Variant& variant, Context* context)
{
    if (!IsNull())
    {
        LOGWARNING("JsonValue is not null");
    }

    (*this)["type"] = variant.GetTypeName();
    (*this)["value"].SetVariantValue(variant, context);
}
void Spline::SetKnot(const Variant& knot, unsigned index)
{
    if (index < knots_.Size())
    {
        if (knots_.Size() > 0 && knots_[0].GetType() == knot.GetType())
            knots_[index] = knot;
        else if (knots_.Empty())
            knots_.Push(knot);
        else
            LOGERRORF("Attempted to set a Spline's Knot value of type %s where elements are already using %s",
                knot.GetTypeName().CString(), knots_[0].GetTypeName().CString());
    }
}
void Spline::AddKnot(const Variant& knot)
{
    if (knots_.Size() > 0 && knots_[0].GetType() == knot.GetType())
        knots_.Push(knot);
    else if (knots_.Empty())
        knots_.Push(knot);
    else
        LOGERRORF("Attempted to add Knot to Spline of type %s where elements are already using %s", knot.GetTypeName().CString(),
            knots_[0].GetTypeName().CString());
}
Example #6
0
void Spline::AddKnot(const Variant& knot, unsigned index) 
{ 
    if (index < 0)
        index = 0;
    else if (index > knots_.Size())
        index = knots_.Size();

    if (knots_.Size() > 0 && knots_[0].GetType() == knot.GetType())
        knots_.Insert(index, knot);
    else if (knots_.Empty())
        knots_.Push(knot);
    else
        LOGERRORF("Attempted to add Knot to Spline of type %s where elements are already using %s", knot.GetTypeName().CString(), knots_[0].GetTypeName().CString());
}
Example #7
0
bool PushVariant(lua_State *pLuaState,
		Variant &variant, bool substituteNullables) {
	switch ((VariantType) variant) {
		case V_UNDEFINED:
		case V_NULL:
		{
			if (substituteNullables)
				lua_pushstring(pLuaState, VAR_NULL_VALUE);
			else
				lua_pushnil(pLuaState);
			return true;
			break;
		}
		case V_STRING:
		{
			lua_pushstring(pLuaState, STR(variant));
			return true;
			break;
		}
		case V_INT8:
		case V_INT16:
		case V_INT32:
		case V_INT64:
		case V_UINT8:
		case V_UINT16:
		case V_UINT32:
		case V_UINT64:
		case V_DOUBLE:
		{
			lua_pushnumber(pLuaState, (double) variant);
			return true;
			break;
		}
		case V_BOOL:
		{
			lua_pushboolean(pLuaState, (bool)variant);
			return true;
			break;
		}
		case V_TIMESTAMP:
		{
			struct tm tempTm = (struct tm) variant;

			lua_createtable(pLuaState, 0, 0);

			lua_pushstring(pLuaState, VAR_TYPE);
			lua_pushstring(pLuaState, VAR_TIMESTAMP);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_YEAR);
			lua_pushnumber(pLuaState, tempTm.tm_year + 1900);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MONTH);
			lua_pushnumber(pLuaState, tempTm.tm_mon+1);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_DAY);
			lua_pushnumber(pLuaState, tempTm.tm_mday);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_HOUR);
			lua_pushnumber(pLuaState, tempTm.tm_hour);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MIN);
			lua_pushnumber(pLuaState, tempTm.tm_min);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_SEC);
			lua_pushnumber(pLuaState, tempTm.tm_sec);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_ISDST);
			lua_pushboolean(pLuaState, false);
			lua_settable(pLuaState, -3);

			return true;
			break;
		}
		case V_DATE:
		{
			struct tm tempTm = (struct tm) variant;

			lua_createtable(pLuaState, 0, 0);

			lua_pushstring(pLuaState, VAR_TYPE);
			lua_pushstring(pLuaState, VAR_DATE);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_YEAR);
			lua_pushnumber(pLuaState, tempTm.tm_year + 1900);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MONTH);
			lua_pushnumber(pLuaState, tempTm.tm_mon);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_DAY);
			lua_pushnumber(pLuaState, tempTm.tm_mday);
			lua_settable(pLuaState, -3);
			return true;
			break;
		}
		case V_TIME:
		{
			struct tm tempTm = (struct tm) variant;

			lua_createtable(pLuaState, 0, 0);

			lua_pushstring(pLuaState, VAR_TYPE);
			lua_pushstring(pLuaState, VAR_TIME);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_YEAR);
			lua_pushnumber(pLuaState, 1970);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MONTH);
			lua_pushnumber(pLuaState, 1);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_DAY);
			lua_pushnumber(pLuaState, 1);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_HOUR);
			lua_pushnumber(pLuaState, tempTm.tm_hour);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MIN);
			lua_pushnumber(pLuaState, tempTm.tm_min);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_SEC);
			lua_pushnumber(pLuaState, tempTm.tm_sec);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_ISDST);
			lua_pushboolean(pLuaState, false);
			lua_settable(pLuaState, -3);

			return true;
			break;
		}
		case V_TYPED_MAP:
		case V_MAP:
		{
			lua_createtable(pLuaState, 0, 0);

			if ((VariantType) variant == V_TYPED_MAP) {
				lua_pushstring(pLuaState, VAR_MAP_NAME);
				lua_pushstring(pLuaState, STR(variant.GetTypeName()));
				lua_settable(pLuaState, -3);
			}

			FOR_MAP(variant, string, Variant, i) {
				if (MAP_KEY(i).find(VAR_INDEX_VALUE) == 0) {
					string temp = MAP_KEY(i).substr(VAR_INDEX_VALUE_LEN,
							string::npos);
					char *error = NULL;
					double index = strtod(STR(temp), &error);
					if (error == STR(temp) + temp.size()) {
						lua_pushnumber(pLuaState, index);
					} else {
						lua_pushstring(pLuaState, STR(MAP_KEY(i)));
					}
				} else {
					lua_pushstring(pLuaState, STR(MAP_KEY(i)));
				}
				if (!PushVariant(pLuaState, MAP_VAL(i), true)) {
					FINEST("Unable to push primitive");
					return false;
				}
				lua_settable(pLuaState, -3);
			}
			return true;
			break;
		}
		default:
		{
			FATAL("Unknown type %hhu", (VariantType) variant);
			return false;
			break;
		}
	}
	return true;
}
Example #8
0
bool PushVariant(lua_State *pLuaState,
		Variant &variant, bool substituteNullables) {
	switch ((VariantType) variant) {
		case V_UNDEFINED:
		case V_NULL:
		{
			if (substituteNullables)
				lua_pushstring(pLuaState, VAR_NULL_VALUE);
			else
				lua_pushnil(pLuaState);
			return true;
			break;
		}
		case V_STRING:
		{
			lua_pushstring(pLuaState, STR(variant));
			return true;
			break;
		}
		case V_INT8:
		case V_INT16:
		case V_INT32:
		case V_INT64:
		case V_UINT8:
		case V_UINT16:
		case V_UINT32:
		case V_UINT64:
		case V_DOUBLE:
		{
			lua_pushnumber(pLuaState, (double) variant);
			return true;
			break;
		}
		case V_BOOL:
		{
			lua_pushboolean(pLuaState, (bool)variant);
			return true;
			break;
		}
		case V_TIMESTAMP:
		{
			struct tm tempTm = (struct tm) variant;

			lua_createtable(pLuaState, 0, 0);

			lua_pushstring(pLuaState, VAR_TYPE);
			lua_pushstring(pLuaState, VAR_TIMESTAMP);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_YEAR);
			lua_pushnumber(pLuaState, tempTm.tm_year + 1900);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MONTH);
			lua_pushnumber(pLuaState, tempTm.tm_mon + 1);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_DAY);
			lua_pushnumber(pLuaState, tempTm.tm_mday);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_HOUR);
			lua_pushnumber(pLuaState, tempTm.tm_hour + 1);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MIN);
			lua_pushnumber(pLuaState, tempTm.tm_min);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_SEC);
			lua_pushnumber(pLuaState, tempTm.tm_sec);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_ISDST);
			lua_pushboolean(pLuaState, false);
			lua_settable(pLuaState, -3);

			return true;
			break;
		}
		case V_DATE:
		{
			struct tm tempTm = (struct tm) variant;

			lua_createtable(pLuaState, 0, 0);

			lua_pushstring(pLuaState, VAR_TYPE);
			lua_pushstring(pLuaState, VAR_DATE);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_YEAR);
			lua_pushnumber(pLuaState, tempTm.tm_year + 1900);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MONTH);
			lua_pushnumber(pLuaState, tempTm.tm_mon + 1);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_DAY);
			lua_pushnumber(pLuaState, tempTm.tm_mday);
			lua_settable(pLuaState, -3);
			return true;
			break;
		}
		case V_TIME:
		{
			struct tm tempTm = (struct tm) variant;

			lua_createtable(pLuaState, 0, 0);

			lua_pushstring(pLuaState, VAR_TYPE);
			lua_pushstring(pLuaState, VAR_TIME);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_YEAR);
			lua_pushnumber(pLuaState, 1970);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MONTH);
			lua_pushnumber(pLuaState, 1);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_DAY);
			lua_pushnumber(pLuaState, 1);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_HOUR);
			lua_pushnumber(pLuaState, tempTm.tm_hour + 1);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MIN);
			lua_pushnumber(pLuaState, tempTm.tm_min);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_SEC);
			lua_pushnumber(pLuaState, tempTm.tm_sec);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_ISDST);
			lua_pushboolean(pLuaState, false);
			lua_settable(pLuaState, -3);

			return true;
			break;
		}
		case V_TYPED_MAP:
		case V_MAP:
		{
			lua_createtable(pLuaState, 0, 0);

			if ((VariantType) variant == V_TYPED_MAP) {
				lua_pushstring(pLuaState, VAR_MAP_NAME);
				lua_pushstring(pLuaState, STR(variant.GetTypeName()));
				lua_settable(pLuaState, -3);
			}

			FOR_MAP(variant, string, Variant, i) {
				const char *pKey = MAP_KEY(i).c_str();
				if ((MAP_KEY(i).length() == 10) && (pKey[0] == '0')
						&& (pKey[1] == 'x')) {
					uint32_t index = (uint32_t) strtol(pKey, NULL, 16);
					lua_pushnumber(pLuaState, index);
				} else {
					lua_pushstring(pLuaState, pKey);
				}
				if (!PushVariant(pLuaState, MAP_VAL(i), true)) {
					FINEST("Unable to push primitive");
					return false;
				}
				lua_settable(pLuaState, -3);
			}
			return true;
			break;
		}
		default:
		{
			FATAL("Unknown type %d", (VariantType) variant);
			return false;
			break;
		}
	}
}