Value.h File Reference


Detailed Description

A general-purpose data container.

#include <support/SupportDefs.h>
#include <support/TypeFuncs.h>
#include <support/StaticValue.h>
#include <support/IByteStream.h>
#include <support/ITextStream.h>
#include <support/IBinder.h>
#include <support/ByteOrder.h>
#include <support/TypeConstants.h>
#include <support/KeyID.h>
#include <string.h>
#include <stdint.h>

Go to the source code of this file.

Classes

class  SSimpleStatusValue
 Convenience for creating a value containing a status code. More...
class  SSimpleValue
 Convenience for creating simple data values. More...
class  SValue
 A general-purpose data container, also known as a variant. More...

Type-specific Optimizations and Sequence Marshalling

Some higher level TypeFuncs that need to know about SValue BArrayAsValue & BArrayConstruct

These are some implementations of the generic type functions to optimize the performance of SVector, SSortedVector, SKeyedVector, and other type-specific functions when used with these types.

In addition, a these provide the custom marshalling code needed for these types to marshal/unmarshal an SVector of the type (called by PerformAsValue and PerformSetFromValue). These are needed for IDL sequences; they are specialized for plain old data, but to marshal an SVector of a user type, you must use one of the implementation macros or write your own implementation.

Options:

Please note that sequences do not support SVector< wptr<TYPE> >.

#define B_IMPLEMENT_FLATTEN_FUNCS(TYPE)
#define B_IMPLEMENT_IINTERFACE_FLATTEN_FUNCS(TYPE)
#define B_IMPLEMENT_SFLATTENABLE_FLATTEN_FUNCS(TYPE)
#define B_IMPLEMENT_SIMPLE_TYPE_FLATTEN_FUNCS(TYPE, TYPECODE)
 Optimization for simple types that can be flattened/restored by just a copy.
SValue BArrayAsValue (const SValue *from, size_t count)
SValue BArrayAsValue (const sptr< IBinder > *from, size_t count)
SSharedBufferBArrayAsValueHelper (void *&toPtr, size_t count, size_t elementSize, type_code typeCode)
status_t BArrayConstruct (SValue *to, const SValue &value, size_t count)
status_t BArrayConstruct (sptr< IBinder > *to, const SValue &value, size_t count)
const void * BArrayConstructHelper (const SValue &value, size_t count, size_t elementSize, type_code typeCode)

Defines

#define B_0_0_FLOAT   B_0_0_FLOAT
#define B_0_1_FLOAT   B_0_1_FLOAT
#define B_0_25_FLOAT   B_0_25_FLOAT
#define B_0_2_FLOAT   B_0_2_FLOAT
#define B_0_3_FLOAT   B_0_3_FLOAT
#define B_0_4_FLOAT   B_0_4_FLOAT
#define B_0_5_FLOAT   B_0_5_FLOAT
#define B_0_6_FLOAT   B_0_6_FLOAT
#define B_0_75_FLOAT   B_0_75_FLOAT
#define B_0_7_FLOAT   B_0_7_FLOAT
#define B_0_8_FLOAT   B_0_8_FLOAT
#define B_0_9_FLOAT   B_0_9_FLOAT
#define B_0_INT32   B_0_INT32
#define B_10_INT32   B_10_INT32
#define B_1_0_FLOAT   B_1_0_FLOAT
#define B_1_INT32   B_1_INT32
#define B_2_INT32   B_2_INT32
#define B_3_INT32   B_3_INT32
#define B_4_INT32   B_4_INT32
#define B_5_INT32   B_5_INT32
#define B_6_INT32   B_6_INT32
#define B_7_INT32   B_7_INT32
#define B_8_INT32   B_8_INT32
#define B_9_INT32   B_9_INT32

Enumerations

enum  { B_NO_VALUE_FLATTEN = 0x00000001, B_NO_VALUE_RECURSION = 0x00000002 }
 Flags for SValue operations. More...
enum  { B_EDIT_VALUE_DATA = 0x00000001 }
 Flags for SValue::LockData(). More...
enum  { B_PRINT_VALUE_TYPES = 0x00010000, B_PRINT_CATALOG_CONTENTS = 0x00020000, B_PRINT_BINDER_INTERFACES = 0x00040000, B_PRINT_BINDER_CONTENTS = 0x00080000 }
 Additional flags for PrintToStream(). More...

Functions

 B_CONST_FLOAT_VALUE (B_1_0_FLOAT, 1.0f,)
 B_CONST_FLOAT_VALUE (B_0_9_FLOAT, 0.9f,)
 B_CONST_FLOAT_VALUE (B_0_8_FLOAT, 0.8f,)
 B_CONST_FLOAT_VALUE (B_0_75_FLOAT, 0.75f,)
 B_CONST_FLOAT_VALUE (B_0_7_FLOAT, 0.7f,)
 B_CONST_FLOAT_VALUE (B_0_6_FLOAT, 0.6f,)
 B_CONST_FLOAT_VALUE (B_0_5_FLOAT, 0.5f,)
 B_CONST_FLOAT_VALUE (B_0_4_FLOAT, 0.4f,)
 B_CONST_FLOAT_VALUE (B_0_3_FLOAT, 0.3f,)
 B_CONST_FLOAT_VALUE (B_0_25_FLOAT, 0.25f,)
 B_CONST_FLOAT_VALUE (B_0_2_FLOAT, 0.2f,)
 B_CONST_FLOAT_VALUE (B_0_1_FLOAT, 0.1f,)
 B_CONST_FLOAT_VALUE (B_0_0_FLOAT, 0.0f,)
 B_CONST_INT32_VALUE (B_10_INT32, 10,)
 B_CONST_INT32_VALUE (B_9_INT32, 9,)
 B_CONST_INT32_VALUE (B_8_INT32, 8,)
 B_CONST_INT32_VALUE (B_7_INT32, 7,)
 B_CONST_INT32_VALUE (B_6_INT32, 6,)
 B_CONST_INT32_VALUE (B_5_INT32, 5,)
 B_CONST_INT32_VALUE (B_4_INT32, 4,)
 B_CONST_INT32_VALUE (B_3_INT32, 3,)
 B_CONST_INT32_VALUE (B_2_INT32, 2,)
 B_CONST_INT32_VALUE (B_1_INT32, 1,)
 B_CONST_INT32_VALUE (B_0_INT32, 0,)
 B_CONST_STRING_VALUE_LARGE (B_VALUE_VALUE,"value",)
 B_CONST_STRING_VALUE_SMALL (B_EMPTY_STRING,"",)
int32_t BCompare (const SValue &v1, const SValue &v2)
void BMoveAfter (SValue *to, SValue *from, size_t count)
void BMoveBefore (SValue *to, SValue *from, size_t count)
void BSwap (SValue &v1, SValue &v2)
_IMPEXP_SUPPORT const sptr<
ITextOutput > & 
operator<< (const sptr< ITextOutput > &io, const SValue &value)
void swap (SValue &x, SValue &y)

Variables

const static_bool_value B_FALSE_BOOL = { B_PACK_SMALL_TYPE(B_BOOL_TYPE, sizeof(int8_t)), false }
const static_small_value B_NULL_VALUE = { B_PACK_SMALL_TYPE(B_NULL_TYPE, 0), "" }
const static_bool_value B_TRUE_BOOL = { B_PACK_SMALL_TYPE(B_BOOL_TYPE, sizeof(int8_t)), true }
const static_small_value B_UNDEFINED_VALUE = { B_UNDEFINED_TYPE, "" }
const static_small_value B_WILD_VALUE = { B_PACK_SMALL_TYPE(B_WILD_TYPE, 0), "" }


Define Documentation

#define B_IMPLEMENT_FLATTEN_FUNCS TYPE   ) 
 

Value:

inline SValue BArrayAsValue(const TYPE* from, size_t count)                     \
    {                                                                               \
        SValue result;                                                              \
        for (size_t i = 0; i < count; i++) {                                        \
            result.JoinItem(SSimpleValue<int32_t>(i), from->AsValue());             \
            from++;                                                                 \
        }                                                                           \
        return result;                                                              \
    }                                                                               \
    inline status_t BArrayConstruct(TYPE* to, const SValue& value, size_t count)    \
    {                                                                               \
        for (size_t i = 0; i < count; i++) {                                        \
        *to = TYPE(value[SSimpleValue<int32_t>(i)]);                                \
            to++;                                                                   \
        }                                                                           \
        return B_OK;                                                                \
    }                                                                               \

#define B_IMPLEMENT_IINTERFACE_FLATTEN_FUNCS TYPE   ) 
 

Value:

inline SValue BArrayAsValue(const sptr<TYPE>* from, size_t count)                       \
    {                                                                                       \
        SValue result;                                                                      \
        for (size_t i = 0; i < count; i++) {                                                \
            result.JoinItem(SSimpleValue<int32_t>(i), SValue::Binder((*from)->AsBinder())); \
            from++;                                                                         \
        }                                                                                   \
        return result;                                                                      \
    }                                                                                       \
    inline status_t BArrayConstruct(sptr<TYPE>* to, const SValue& value, size_t count)      \
    {                                                                                       \
        BConstruct(to, count);                                                              \
        for (size_t i = 0; i < count; i++) {                                                \
            /* We know that only objects of TYPE are in sequence */                         \
            *to = TYPE::AsInterfaceNoInspect(value[SSimpleValue<int32_t>(i)]);              \
            to++;                                                                           \
        }                                                                                   \
        return B_OK;                                                                        \
    }                                                                                       \

#define B_IMPLEMENT_SFLATTENABLE_FLATTEN_FUNCS TYPE   ) 
 

Value:

inline SValue BArrayAsValue(const TYPE* from, size_t count)                     \
    {                                                                               \
        SValue result;                                                              \
        for (size_t i = 0; i < count; i++) {                                        \
            result.JoinItem(SSimpleValue<int32_t>(i), from->AsValue());             \
            from++;                                                                 \
        }                                                                           \
        return result;                                                              \
    }                                                                               \
    inline status_t BArrayConstruct(TYPE* to, const SValue& value, size_t count)    \
    {                                                                               \
        BConstruct(to, count);                                                      \
        for (size_t i = 0; i < count; i++) {                                        \
            to->SetFromValue(value[SSimpleValue<int32_t>(i)]);                      \
            to++;                                                                   \
        }                                                                           \
        return B_OK;                                                                \
    }                                                                               \

#define B_IMPLEMENT_SIMPLE_TYPE_FLATTEN_FUNCS TYPE,
TYPECODE   ) 
 

Value:

inline SValue BArrayAsValue(const TYPE* from, size_t count)                                 \
    {                                                                                           \
        void* voidPtr = NULL;                                                                   \
        SSharedBuffer* buffer = BArrayAsValueHelper(voidPtr, count, sizeof(TYPE), TYPECODE);    \
        TYPE* toPtr = static_cast<TYPE*>(voidPtr);                                              \
        BCopy(toPtr, from, count);                                                              \
        SValue value(B_FIXED_ARRAY_TYPE, buffer);                                               \
        buffer->DecUsers();                                                                     \
        return value;                                                                           \
    }                                                                                           \
    inline status_t BArrayConstruct(TYPE* to, const SValue& value, size_t count)                            \
    {                                                                                                       \
        const TYPE* fromPtr = NULL;                                                                         \
        fromPtr = static_cast<const TYPE*>(BArrayConstructHelper(value, count, sizeof(TYPE), TYPECODE));    \
        if (fromPtr != NULL) {                                                                              \
            BCopy(to, fromPtr, count);                                                                      \
        }                                                                                                   \
        else {                                                                                              \
            return B_BAD_DATA;                                                                              \
        }                                                                                                   \
        return B_OK;                                                                                        \
    }                                                                                                       \
Optimization for simple types that can be flattened/restored by just a copy.

Note:
Ignores endianness issues.


Function Documentation

SValue BArrayAsValue const SValue from,
size_t  count
 

SValue BArrayAsValue const sptr< IBinder > *  from,
size_t  count
[inline]
 

SSharedBuffer* BArrayAsValueHelper void *&  toPtr,
size_t  count,
size_t  elementSize,
type_code  typeCode
 

status_t BArrayConstruct SValue to,
const SValue value,
size_t  count
 

status_t BArrayConstruct sptr< IBinder > *  to,
const SValue value,
size_t  count
[inline]
 

const void* BArrayConstructHelper const SValue value,
size_t  count,
size_t  elementSize,
type_code  typeCode