BVB Source Codes

CRYENGINE Show CompositeData.h Source code

Return Download CRYENGINE: download CompositeData.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #ifndef __COMPOSITEDATA_H__
  4. #define __COMPOSITEDATA_H__
  5.  
  6. #pragma once
  7.  
  8. #include <CryCore/BoostHelpers.h>
  9.  
  10. // basic types are CONCRETE types which does NOT contain references like
  11. // pointers or references, or more specifically dynamically allocated strings
  12. // their value sizes can be determined by simply doing sizeof(T); also
  13. // {&T, sizeof(T)} should be enough to retrieve the value bytes or set it; AND
  14. // the condition must be satisfied that sizeof(T) <= 255.
  15. enum EBasicTypes4CC
  16. {
  17.         eBT_i08  = '_i08',
  18.         eBT_i16  = '_i16',
  19.         eBT_i32  = '_i32',
  20.         eBT_i64  = '_i64',
  21.         eBT_u08  = '_u08',
  22.         eBT_u16  = '_u16',
  23.         eBT_u32  = '_u32',
  24.         eBT_u64  = '_u64',
  25.         eBT_f32  = '_f32',
  26.         eBT_f64  = '_f64',
  27.         eBT_str  = '_str', // 255 characters maximum, one byte prefix for length
  28.  
  29.         eBT_vec3 = 'vec3', // Vec3<f32>
  30.         eBT_ang3 = 'ang3', // Ang3<f32>
  31.         eBT_mtrx = 'mtrx', // Matrix34<f32>
  32.         eBT_quat = 'quat', // Quat<f32>
  33.         eBT_qutt = 'qutt', // QuatT<f32>
  34. };
  35.  
  36. typedef boost::mpl::vector<int8, uint8, int16, uint16, int32, uint32, int64, uint64, f32, f64, string, Vec3, Ang3, Matrix34, Quat, QuatT> TBasicTypes;
  37. typedef boost::make_variant_over<TBasicTypes>::type                                                                                       TBasicType;
  38.  
  39. template<typename T>
  40. static inline T ComposeValue(const uint8* data, size_t size)
  41. {
  42.         CRY_ASSERT(sizeof(T) == size);
  43.         T t = T();
  44.         memcpy(&t, data, size);
  45.         return t;
  46. }
  47.  
  48. template<>
  49. inline string ComposeValue<string>(const uint8* data, size_t size)
  50. {
  51.         return string((const char*)data, size);
  52. }
  53.  
  54. static inline TBasicType ComposeValue(const IMetadata* metadata)
  55. {
  56.         TBasicType v;
  57.         uint8 dt[255];
  58.         uint8 sz = sizeof(dt);
  59.         if (!metadata->GetValue(dt, &sz))
  60.                 return v;
  61.         switch (metadata->GetValueType())
  62.         {
  63.         case eBT_i08:
  64.                 v = TBasicType(ComposeValue<int8>(dt, sz));
  65.                 break;
  66.         case eBT_u08:
  67.                 v = TBasicType(ComposeValue<uint8>(dt, sz));
  68.                 break;
  69.         case eBT_i16:
  70.                 v = TBasicType(ComposeValue<int16>(dt, sz));
  71.                 break;
  72.         case eBT_u16:
  73.                 v = TBasicType(ComposeValue<uint16>(dt, sz));
  74.                 break;
  75.         case eBT_i32:
  76.                 v = TBasicType(ComposeValue<int32>(dt, sz));
  77.                 break;
  78.         case eBT_u32:
  79.                 v = TBasicType(ComposeValue<uint32>(dt, sz));
  80.                 break;
  81.         case eBT_i64:
  82.                 v = TBasicType(ComposeValue<int64>(dt, sz));
  83.                 break;
  84.         case eBT_u64:
  85.                 v = TBasicType(ComposeValue<uint64>(dt, sz));
  86.                 break;
  87.         case eBT_f32:
  88.                 v = TBasicType(ComposeValue<f32>(dt, sz));
  89.                 break;
  90.         case eBT_f64:
  91.                 v = TBasicType(ComposeValue<f64>(dt, sz));
  92.                 break;
  93.         case eBT_str:
  94.                 v = TBasicType(ComposeValue<string>(dt, sz));
  95.                 break;
  96.         case eBT_vec3:
  97.                 v = TBasicType(ComposeValue<Vec3>(dt, sz));
  98.                 break;
  99.         case eBT_ang3:
  100.                 v = TBasicType(ComposeValue<Ang3>(dt, sz));
  101.                 break;
  102.         case eBT_mtrx:
  103.                 v = TBasicType(ComposeValue<Matrix34>(dt, sz));
  104.                 break;
  105.         case eBT_quat:
  106.                 v = TBasicType(ComposeValue<Quat>(dt, sz));
  107.                 break;
  108.         case eBT_qutt:
  109.                 v = TBasicType(ComposeValue<QuatT>(dt, sz));
  110.                 break;
  111.         default:
  112.                 break;
  113.         }
  114.         return v;
  115. }
  116.  
  117. /*
  118.    CCompositeData data;
  119.    data.Compose(metadata);
  120.    data.GetField(eDT_name).GetValue().GetPtr<string>()->c_str();
  121.    data.GetField(eDT_item).GetField(eDT_name).GetPtr<string>()->c_str();
  122.  */
  123.  
  124. class CCompositeData
  125. {
  126. public:
  127.         CCompositeData() : m_tag(0) {}
  128.         ~CCompositeData() {}
  129.  
  130.         void Compose(const IMetadata* metadata)
  131.         {
  132.                 m_tag = metadata->GetTag();
  133.                 m_value = ::ComposeValue(metadata);
  134.  
  135.                 for (size_t i = 0; i < metadata->GetNumFields(); ++i)
  136.                 {
  137.                         const IMetadata* pMetadata = metadata->GetFieldByIndex(i);
  138.                         CCompositeData data;
  139.                         data.Compose(pMetadata);
  140.                         m_fields.push_back(data);
  141.                 }
  142.         }
  143.  
  144.         const TBasicType& GetValue() const
  145.         {
  146.                 return m_value;
  147.         }
  148.  
  149.         const CCompositeData& GetField(uint32 tag, size_t count = 1) const
  150.         {
  151.                 size_t n = 0;
  152.                 for (size_t i = 0; i < m_fields.size(); ++i)
  153.                         if (m_fields[i].m_tag == tag && ++n == count)
  154.                                 return m_fields[i];
  155.  
  156.                 static const CCompositeData dummy;
  157.                 return dummy;
  158.         }
  159.  
  160. private:
  161.         uint32                      m_tag;
  162.         TBasicType                  m_value;
  163.  
  164.         std::vector<CCompositeData> m_fields;
  165. };
  166.  
  167. #endif
  168.  
downloadCompositeData.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top