
/*
 * Copyright 2006 The Android Open Source Project
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */


#ifndef SkMemberInfo_DEFINED
#define SkMemberInfo_DEFINED

#if defined SK_BUILD_CONDENSED
    #define SK_USE_CONDENSED_INFO 0
#endif

#include "SkDisplayType.h"
#include "SkScript.h"
#include "SkString.h"
#include "SkIntArray.h"

class SkAnimateMaker;
class SkDisplayable;
class SkScriptEngine;

// temporary hacks until name change is more complete
#define SkFloat SkScalar
#define SkInt SkS32

struct SkMemberInfo {
    //!!! alternative:
    // if fCount == 0, record is member property
    // then fType can be type, so caller doesn't have to check
#if SK_USE_CONDENSED_INFO == 0
    const char* fName;  // may be NULL for anonymous functions
    size_t fOffset; // if negative, is index into member pointer table (for properties and functions)
    SkDisplayTypes fType;
    int fCount;         // for properties, actual type (count is always assumed to be 1)
#else
    unsigned char fName;
    signed char fOffset;
    unsigned char fType;
    signed char fCount;
#endif
    SkDisplayTypes arrayType() const {
        SkASSERT(fType == SkType_Array);
        return (SkDisplayTypes) fCount;  // hack, but worth it?
    }
    int functionIndex() const {
        SkASSERT(fType == SkType_MemberFunction);
        return (signed) fOffset > 0 ? -1 + (int) fOffset : -1 - (int) fOffset;
    }
    bool getArrayValue(const SkDisplayable* displayable, int index, SkOperand* value) const;
    int getCount() const {
        return fType == SkType_MemberProperty || fType == SkType_Array ||
            fType == SkType_MemberFunction ? 1 : fCount;
    }
    const SkMemberInfo* getInherited() const;
    size_t getSize(const SkDisplayable* ) const;
    void getString(const SkDisplayable* , SkString** string) const;
    SkDisplayTypes getType() const {
        return fType == SkType_MemberProperty || fType == SkType_Array ||
            fType == SkType_MemberFunction ? (SkDisplayTypes) fCount : (SkDisplayTypes) fType;
    }
    void getValue(const SkDisplayable* , SkOperand values[], int count) const;
    bool isEnum() const;
    const char* mapEnums(const char* match, int* value) const;
    void* memberData(const SkDisplayable* displayable) const {
        SkASSERT(fType != SkType_MemberProperty &&  fType != SkType_MemberFunction);
        return (void*) ((const char*) displayable + fOffset);
    }
    int propertyIndex() const {
        SkASSERT(fType == SkType_MemberProperty);
        return (signed) fOffset > 0 ? -1 + (int) fOffset : -1 - (int) fOffset;
    }
    SkDisplayTypes propertyType() const {
        SkASSERT(fType == SkType_MemberProperty || fType == SkType_Array);
        return (SkDisplayTypes) fCount;  // hack, but worth it?
    }
    void setMemberData(SkDisplayable* displayable, const void* child, size_t size) const {
        SkASSERT(fType != SkType_MemberProperty &&  fType != SkType_MemberFunction);
        memcpy((char*) displayable + fOffset, child, size);
    }
    void setString(SkDisplayable* , SkString* ) const;
    void setValue(SkDisplayable* , const SkOperand values[], int count) const;
    bool setValue(SkAnimateMaker& , SkTDOperandArray* storage,
        int storageOffset, int maxStorage, SkDisplayable* ,
        SkDisplayTypes outType, const char value[], size_t len) const;
    bool setValue(SkAnimateMaker& , SkTDOperandArray* storage,
        int storageOffset, int maxStorage, SkDisplayable* ,
        SkDisplayTypes outType, SkString& str) const;
//  void setValue(SkDisplayable* , const char value[], const char name[]) const;
    bool writeValue(SkDisplayable* displayable, SkTDOperandArray* arrayStorage,
        int storageOffset, int maxStorage, void* untypedStorage, SkDisplayTypes outType,
        SkScriptValue& scriptValue) const;
#if SK_USE_CONDENSED_INFO == 0
    static const SkMemberInfo* Find(const SkMemberInfo [], int count, int* index);
    static const SkMemberInfo* Find(const SkMemberInfo [], int count, const char** name);
#else
    static const SkMemberInfo* Find(SkDisplayTypes type, int* index);
    static const SkMemberInfo* Find(SkDisplayTypes type, const char** name);
#endif
    static size_t GetSize(SkDisplayTypes type); // size of simple types only
//  static bool SetValue(void* value, const char* name, SkDisplayTypes , int count);
};

#define SK_MEMBER(_member, _type) \
    { #_member, SK_OFFSETOF(BASE_CLASS, _member), SkType_##_type, \
    sizeof(((BASE_CLASS*) 1)->_member) / sizeof(SkScalar) }

#define SK_MEMBER_ALIAS(_member, _alias, _type) \
    { #_member, SK_OFFSETOF(BASE_CLASS, _alias), SkType_##_type, \
    sizeof(((BASE_CLASS*) 1)->_alias) / sizeof(SkScalar) }

#define SK_MEMBER_ARRAY(_member, _type) \
    { #_member, SK_OFFSETOF(BASE_CLASS, _member), SkType_Array, \
    (int) SkType_##_type }

#define SK_MEMBER_INHERITED \
    { (const char*) INHERITED::fInfo, 0, SkType_BaseClassInfo, INHERITED::fInfoCount }

// #define SK_MEMBER_KEY_TYPE(_member, _type)
//  {#_member, (size_t) -1, SkType_##_type, 0}

#define SK_FUNCTION(_member) \
    k_##_member##Function

#define SK_PROPERTY(_member) \
    k_##_member##Property

#define SK_MEMBER_DYNAMIC_FUNCTION(_member, _type) \
    {#_member, (size_t) (+1 + SK_FUNCTION(_member)), SkType_MemberFunction, \
    (int) SkType_##_type }

#define SK_MEMBER_DYNAMIC_PROPERTY(_member, _type) \
    {#_member, (size_t) (1 + SK_PROPERTY(_member)), SkType_MemberProperty, \
    (int) SkType_##_type }

#define SK_MEMBER_FUNCTION(_member, _type) \
    {#_member, (size_t) (-1 - SK_FUNCTION(_member)), SkType_MemberFunction, \
    (int) SkType_##_type }

#define SK_MEMBER_PROPERTY(_member, _type) \
    {#_member, (size_t) (-1 - SK_PROPERTY(_member)), SkType_MemberProperty, \
    (int) SkType_##_type }

#if SK_USE_CONDENSED_INFO == 0

#define DECLARE_PRIVATE_MEMBER_INFO(_type) \
public: \
    static const SkMemberInfo fInfo[]; \
    static const int fInfoCount; \
    virtual const SkMemberInfo* getMember(int index); \
    virtual const SkMemberInfo* getMember(const char name[]); \
    typedef Sk##_type BASE_CLASS

#define DECLARE_MEMBER_INFO(_type) \
public: \
    static const SkMemberInfo fInfo[]; \
    static const int fInfoCount; \
    virtual const SkMemberInfo* getMember(int index); \
    virtual const SkMemberInfo* getMember(const char name[]); \
    virtual SkDisplayTypes getType() const { return SkType_##_type; } \
    typedef Sk##_type BASE_CLASS

#define DECLARE_DRAW_MEMBER_INFO(_type) \
public: \
    static const SkMemberInfo fInfo[]; \
    static const int fInfoCount; \
    virtual const SkMemberInfo* getMember(int index); \
    virtual const SkMemberInfo* getMember(const char name[]); \
    virtual SkDisplayTypes getType() const { return SkType_##_type; } \
    typedef SkDraw##_type BASE_CLASS

#define DECLARE_DISPLAY_MEMBER_INFO(_type) \
public: \
    static const SkMemberInfo fInfo[]; \
    static const int fInfoCount; \
    virtual const SkMemberInfo* getMember(int index); \
    virtual const SkMemberInfo* getMember(const char name[]); \
    virtual SkDisplayTypes getType() const { return SkType_##_type; } \
    typedef SkDisplay##_type BASE_CLASS

#define DECLARE_EMPTY_MEMBER_INFO(_type) \
public: \
    virtual SkDisplayTypes getType() const { return SkType_##_type; }

#define DECLARE_EXTRAS_MEMBER_INFO(_type) \
public: \
    static const SkMemberInfo fInfo[]; \
    static const int fInfoCount; \
    virtual const SkMemberInfo* getMember(int index); \
    virtual const SkMemberInfo* getMember(const char name[]); \
    SkDisplayTypes fType; \
    virtual SkDisplayTypes getType() const { return fType; } \
    typedef _type BASE_CLASS

#define DECLARE_NO_VIRTUALS_MEMBER_INFO(_type) \
public: \
    static const SkMemberInfo fInfo[]; \
    static const int fInfoCount; \
    typedef Sk##_type BASE_CLASS

#define DEFINE_GET_MEMBER(_class) \
    const SkMemberInfo* _class::getMember(int index) { \
        const SkMemberInfo* result = SkMemberInfo::Find(fInfo, SK_ARRAY_COUNT(fInfo), &index); \
        return result; \
    } \
    const SkMemberInfo* _class::getMember(const char name[]) { \
        const SkMemberInfo* result = SkMemberInfo::Find(fInfo, SK_ARRAY_COUNT(fInfo), &name); \
        return result; \
    } \
    const int _class::fInfoCount = SK_ARRAY_COUNT(fInfo)

#define DEFINE_NO_VIRTUALS_GET_MEMBER(_class) \
    const int _class::fInfoCount = SK_ARRAY_COUNT(fInfo)

#else

#define DECLARE_PRIVATE_MEMBER_INFO(_type) \
public: \
    typedef Sk##_type BASE_CLASS

#define DECLARE_MEMBER_INFO(_type) \
public: \
    virtual const SkMemberInfo* getMember(int index) { \
        return SkDisplayType::GetMember(NULL, SkType_##_type, &index); } \
    virtual const SkMemberInfo* getMember(const char name[]) { \
        return SkDisplayType::GetMember(NULL, SkType_##_type, &name); } \
    virtual SkDisplayTypes getType() const { return SkType_##_type; } \
    typedef Sk##_type BASE_CLASS

#define DECLARE_DRAW_MEMBER_INFO(_type) \
public: \
    virtual const SkMemberInfo* getMember(int index) { \
        return SkDisplayType::GetMember(NULL, SkType_##_type, &index); } \
    virtual const SkMemberInfo* getMember(const char name[]) { \
        return SkDisplayType::GetMember(NULL, SkType_##_type, &name); } \
    virtual SkDisplayTypes getType() const { return SkType_##_type; } \
    typedef SkDraw##_type BASE_CLASS

#define DECLARE_DISPLAY_MEMBER_INFO(_type) \
public: \
    virtual const SkMemberInfo* getMember(int index) { \
        return SkDisplayType::GetMember(NULL, SkType_##_type, &index); } \
    virtual const SkMemberInfo* getMember(const char name[]) { \
        return SkDisplayType::GetMember(NULL, SkType_##_type, &name); } \
    virtual SkDisplayTypes getType() const { return SkType_##_type; } \
    typedef SkDisplay##_type BASE_CLASS

#define DECLARE_EXTRAS_MEMBER_INFO(_type) \
public: \
    virtual const SkMemberInfo* getMember(int index) { \
        return SkDisplayType::GetMember(NULL, SkType_##_type, &index); } \
    virtual const SkMemberInfo* getMember(const char name[]) { \
        return SkDisplayType::GetMember(NULL, fType, &name); } \
    SkDisplayTypes fType; \
    virtual SkDisplayTypes getType() const { return fType; } \
    typedef _type BASE_CLASS

#define DECLARE_NO_VIRTUALS_MEMBER_INFO(_type) \
public: \
    typedef Sk##_type BASE_CLASS

#define DEFINE_GET_MEMBER(_class)
#define DEFINE_NO_VIRTUALS_GET_MEMBER(_class)

#endif

#endif // SkMemberInfo_DEFINED

