Ejemplo n.º 1
0
	void Any::set(const std::string& k, const Any& v) {
		beforeRead();
		v.beforeRead();
		verifyType(TABLE);
		debugAssert(m_data != NULL);
		Table<std::string, Any>& table = *(m_data->value.t);
		table.set(k, v);
	}
Ejemplo n.º 2
0
	bool Any::operator!=(const Any& x) const {
		beforeRead();
		x.beforeRead();
		return !operator==(x);
	}
Ejemplo n.º 3
0
	bool Any::operator==(const Any& x) const {
		beforeRead();
		x.beforeRead();
		if (m_type != x.m_type) {
			return false;
		}

		switch (m_type) {
		case NONE:
			return true;

		case BOOLEAN:
			return (m_simpleValue.b == x.m_simpleValue.b);

		case NUMBER:
			return (m_simpleValue.n == x.m_simpleValue.n);

		case STRING:
			debugAssert(m_data != NULL);
			return (*(m_data->value.s) == *(x.m_data->value.s));

		case TABLE: {
			if (size() != x.size()) {
				return false;
			}
			debugAssert(m_data != NULL);
			if (m_data->name != x.m_data->name) {
				return false;
			}
			Table<std::string, Any>& cmptable = *(m_data->value.t);
			Table<std::string, Any>& xcmptable = *(x.m_data->value.t);
			for (Table<std::string, Any>::Iterator it1 = cmptable.begin(), it2 = xcmptable.begin();
				it1 != cmptable.end() && it2 != xcmptable.end();
				++it1, ++it2) {
				if (*it1 != *it2) {
					return false;
				}
			}
			return true;
		}

		case ARRAY: {
			if (size() != x.size()) {
				return false;
			}
			debugAssert(m_data != NULL);
			if (m_data->name != x.m_data->name) {
				return false;
			}

			Array<Any>& cmparray = *(m_data->value.a);
			Array<Any>& xcmparray = *(x.m_data->value.a);

			for (int ii = 0; ii < size(); ++ii) {
				if (cmparray[ii] != xcmparray[ii]) {
					return false;
				}
			}
			return true;
		}

		default:
			alwaysAssertM(false, "Unknown type.");
			return false;
		}    // switch (m_type)
	}
Ejemplo n.º 4
0
	Any::Any(const Any& x) : m_type(NONE), m_data(NULL) {
		x.beforeRead();
		*this = x;
	}