Esempio n. 1
0
/*
 * Produce a debugging string describing an NValue.
 */
std::string NValue::debug() const {
    const ValueType type = getValueType();
    if (isNull()) {
        return "<NULL>";
    }
    std::ostringstream buffer;
    std::string out_val;
    const char* ptr;
    int64_t addr;
    buffer << getTypeName(type) << "::";
    switch (type) {
    case VALUE_TYPE_BOOLEAN:
        buffer << (getBoolean() ? "true" : "false");
        break;
    case VALUE_TYPE_TINYINT:
        buffer << static_cast<int32_t>(getTinyInt());
        break;
    case VALUE_TYPE_SMALLINT:
        buffer << getSmallInt();
        break;
    case VALUE_TYPE_INTEGER:
        buffer << getInteger();
        break;
    case VALUE_TYPE_BIGINT:
    case VALUE_TYPE_TIMESTAMP:
        buffer << getBigInt();
        break;
    case VALUE_TYPE_DOUBLE:
        buffer << getDouble();
        break;
    case VALUE_TYPE_VARCHAR:
        ptr = reinterpret_cast<const char*>(getObjectValue_withoutNull());
        addr = reinterpret_cast<int64_t>(ptr);
        out_val = std::string(ptr, getObjectLength_withoutNull());
        buffer << "[" << getObjectLength_withoutNull() << "]";
        buffer << "\"" << out_val << "\"[@" << addr << "]";
        break;
    case VALUE_TYPE_VARBINARY:
        ptr = reinterpret_cast<const char*>(getObjectValue_withoutNull());
        addr = reinterpret_cast<int64_t>(ptr);
        out_val = std::string(ptr, getObjectLength_withoutNull());
        buffer << "[" << getObjectLength_withoutNull() << "]";
        buffer << "-bin[@" << addr << "]";
        break;
    case VALUE_TYPE_DECIMAL:
        buffer << createStringFromDecimal();
        break;
    default:
        buffer << "(no details)";
        break;
    }
    std::string ret(buffer.str());
    return (ret);
}
Esempio n. 2
0
const NValue& NValue::itemAtIndex(int index) const
{
    assert(m_valueType == VALUE_TYPE_ARRAY);
    const NValueList* listOfNValues = reinterpret_cast<const NValueList*>(getObjectValue_withoutNull());
    assert(index >= 0);
    assert(index < listOfNValues->m_length);
    return listOfNValues->m_values[index];
}
Esempio n. 3
0
void NValue::setArrayElements(std::vector<NValue> &args) const
{
    assert(m_valueType == VALUE_TYPE_ARRAY);
    NValueList* listOfNValues = const_cast<NValueList*>(
        reinterpret_cast<const NValueList*>(getObjectValue_withoutNull()));
    // Assign each of the elements.
    int ii = (int)args.size();
    assert(ii == listOfNValues->m_length);
    while (ii--) {
        listOfNValues->m_values[ii] = args[ii];
    }
    //TODO: An O(ln(length)) implementation vs. the current O(length) implementation of NValue::inList
    // would likely require some kind of sorting/re-org of values at this point post-update pre-lookup.
}
Esempio n. 4
0
int NValue::arrayLength() const
{
    assert(m_valueType == VALUE_TYPE_ARRAY);
    const NValueList* listOfNValues = reinterpret_cast<const NValueList*>(getObjectValue_withoutNull());
    return static_cast<int>(listOfNValues->m_length);
}