1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     ut_ResMetaData.h
4 
5   Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Revision: 17182 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NW_UT_RES_META_DATA_H_
17 #define NW_UT_RES_META_DATA_H_
18 
19 #include <nw/ut/ut_Inlines.h>
20 #include <nw/ut/ut_ResTypes.h>
21 #include <nw/ut/ut_ResUtil.h>
22 #include <nw/math/math_ResTypes.h>
23 #include <nw/ut/ut_ResTypeInfo.h>
24 
25 namespace nw {
26 namespace ut {
27 
28 //! @details :private
29 struct ResMetaDataData
30 {
31     nw::ut::ResTypeInfo typeInfo;
32     nw::ut::BinString toKey;
33     nw::ut::ResS32 m_DataType;
34 };
35 
36 //! @details :private
37 struct ResIntArrayMetaDataData : public ResMetaDataData
38 {
39     nw::ut::ResS32  m_ValuesCount;
40     nw::ut::ResS32  m_Values[1]; // ValueCount分の値が格納されている
41 };
42 
43 //! @details :private
44 struct ResFloatArrayMetaDataData : public ResMetaDataData
45 {
46     nw::ut::ResS32  m_ValuesCount;
47     nw::ut::ResF32  m_Values[1]; // ValueCount分の値が格納されている
48 };
49 
50 //! @details :private
51 struct ResStringArrayMetaDataData : public ResMetaDataData
52 {
53     nw::ut::ResU32  m_Encoding;
54     nw::ut::ResS32  m_ValuesCount;
55     nw::ut::BinString  m_Values[1]; // ValueCount分の値が格納されている
56 };
57 
58 //! @details :private
59 class ResMetaData : public nw::ut::ResCommon< ResMetaDataData >
60 {
61 public:
62     enum { TYPE_INFO = NW_UT_RES_TYPE_INFO(ResMetaData) };
63 
64     enum DataType
65     {
66         DATATYPE_FLOAT_ARRAY = 0,
67         DATATYPE_INT_ARRAY,
68         DATATYPE_STRING_ARRAY,
69         DATATYPE_UNKOWN = -1
70     };
71 
72     NW_RES_CTOR( ResMetaData )
73 
NW_RES_FIELD_STRING_DECL(Key)74     NW_RES_FIELD_STRING_DECL( Key ) // GetKey()
75     NW_RES_FIELD_PRIMITIVE_DECL( s32, DataType ) // GetDataType(), SetDataType()
76 
77     nw::ut::ResTypeInfo     GetTypeInfo() const { return ref().typeInfo; }
78 };
79 
80 //! @details :private
81 class ResIntArrayMetaData : public ResMetaData
82 {
83 public:
84     enum { TYPE_INFO = NW_UT_RES_TYPE_INFO(ResIntArrayMetaData) };
85 
NW_RES_CTOR_INHERIT(ResIntArrayMetaData,ResMetaData)86     NW_RES_CTOR_INHERIT( ResIntArrayMetaData, ResMetaData )
87 
88     s32 GetValuesCount() const { return ref().m_ValuesCount; }
GetValues()89     const s32* GetValues() const { return &(ref().m_Values[0]); }
GetValues()90     s32* GetValues() { return &(ref().m_Values[0]); }
91 
GetValues(int idx)92     s32  GetValues(int idx) const { return ref().m_Values[idx]; }
SetValues(int idx,s32 value)93     void SetValues(int idx, s32 value) { ref().m_Values[idx] = value; }
94 
GetTypeInfo()95     nw::ut::ResTypeInfo     GetTypeInfo() const { return ref().typeInfo; }
96 };
97 
98 //! @details :private
99 class ResFloatArrayMetaData : public ResMetaData
100 {
101 public:
102     enum { TYPE_INFO = NW_UT_RES_TYPE_INFO(ResFloatArrayMetaData) };
103 
NW_RES_CTOR_INHERIT(ResFloatArrayMetaData,ResMetaData)104     NW_RES_CTOR_INHERIT( ResFloatArrayMetaData, ResMetaData )
105 
106     s32 GetValuesCount() const { return ref().m_ValuesCount; }
107 
GetValues()108     const f32* GetValues() const { return &(ref().m_Values[0]); }
GetValues()109     f32* GetValues() { return &(ref().m_Values[0]); }
110 
GetValues(int idx)111     f32  GetValues(int idx) const { return ref().m_Values[idx]; }
SetValues(int idx,f32 value)112     void SetValues(int idx, f32 value) { ref().m_Values[idx] = value; }
113 
GetTypeInfo()114     nw::ut::ResTypeInfo     GetTypeInfo() const { return ref().typeInfo; }
115 };
116 
117 //! @details :private
118 class ResStringArrayMetaData : public ResMetaData
119 {
120 public:
121     enum { TYPE_INFO = NW_UT_RES_TYPE_INFO(ResStringArrayMetaData) };
122 
123     enum Encoding
124     {
125         ENCODING_ASCII   = 0,
126         ENCODING_UTF8    = 1,
127         ENCODING_UTF16LE = 2,
128         ENCODING_UTF16BE = 3
129     };
130 
NW_RES_CTOR_INHERIT(ResStringArrayMetaData,ResMetaData)131     NW_RES_CTOR_INHERIT( ResStringArrayMetaData, ResMetaData )
132 
133     NW_RES_FIELD_PRIMITIVE_DECL( s32, Encoding ) // GetEncoding()
134 
135     s32 GetValuesCount() const { return ref().m_ValuesCount; }
136 
GetValues(int idx)137     const char* GetValues(int idx) const { return ref().m_Values[idx].to_ptr(); }
GetWValues(int idx)138     const wchar_t* GetWValues(int idx) const { return reinterpret_cast<const wchar_t*>(ref().m_Values[idx].to_ptr()); }
139 
GetTypeInfo()140     nw::ut::ResTypeInfo     GetTypeInfo() const { return ref().typeInfo; }
141 };
142 
143 
144 } /* namespace ut */
145 } /* namespace nw */
146 
147 #endif //  NW_UT_RES_META_DATA_H_
148