Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cTemplateList.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cTemplateList_H
7 #define _INC_cTemplateList_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "../GrayLibBase.h"
13 #include "../Variant/cVariant.h"
14 #include "../Math/cRandomFloat.h"
16 
17 
18 namespace GrayLib
19 {
22  {
25  public:
28  // NOTE: Other tags for the instantiation can be in m_vVal as well
30 
31  public:
32  cTemplateEntry(float fProbability, const cVariant& vEntryArgs)
33  : m_fProbability(fProbability)
34  , m_vEntryArgs(vEntryArgs)
35  , m_iQty(0)
36  {
37  }
38  cTemplateEntry(float fProbability = 0)
39  : m_fProbability(fProbability)
40  , m_iQty(0)
41  {
42  }
43  };
44 
46  {
49 
50  private:
53  float m_fProbabilityTotal;
54 
55  public:
57  : m_fProbabilityTotal(0)
58  {
59  }
61  {
62  return m_Vals.GetSize();
63  }
64  float get_ProbabilityTotal() const
65  {
66  return m_fProbabilityTotal;
67  }
68 
69  void SetClear()
70  {
71  m_fProbabilityTotal = 0;
72  m_Vals.RemoveAll();
73  }
74 
76  {
77  return m_Vals.ElementAt(index);
78  }
80  {
81  return m_Vals.ConstElementAt(index);
82  }
83  const cTemplateEntry* GetValAtProbability(float fProbability) const;
84  const cTemplateEntry* GetValAtScale(float fRandValScale) const;
85  const cTemplateEntry* GetValRandom(cRandomFloat* pRand = nullptr) const; // &g_RandFloat
86  cStringA GetValString(void);
87 
88  bool AddValAt(ITERATE_t iIndex, float fProbability, const cVariant& vVal);
89  bool AddVal(float fProbability, const cVariant& vVal);
90  bool AddVal(const cVariant& vVal);
91 
92  HRESULT SetEntryDef(ITERATE_t iEntry, const cVariant& vVal);
93  HRESULT SetEntryQty(ITERATE_t iEntry, ITERATE_t iQty);
94  HRESULT SetEntryChance(ITERATE_t iEntry, float fChance);
95 
96  HRESULT s_LoadPropsTemplate(cIniSectionData* pSection);
97  HRESULT LoadTemplateFile(const FILECHAR_t* pszFileName);
98 
100  };
101 };
102 #endif // _INC_cTemplateList_H
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
Definition: cRandomFloat.h:21
Definition: cTemplateList.h:22
cTemplateEntry(float fProbability, const cVariant &vEntryArgs)
Definition: cTemplateList.h:32
cVariant m_vEntryArgs
the actual target of the Template. typically a SYMNAME + args. cVariantArray
Definition: cTemplateList.h:27
ITERATE_t m_iQty
extra arg for Qty of this.
Definition: cTemplateList.h:29
cTemplateEntry(float fProbability=0)
Definition: cTemplateList.h:38
float m_fProbability
probability weight of getting this. (relative to others in list)
Definition: cTemplateList.h:26
Definition: cTemplateList.h:46
const cTemplateEntry & GetValAtC(ITERATE_t index) const
Definition: cTemplateList.h:79
ITERATE_t get_EnumQty() const
Definition: cTemplateList.h:60
void SetClear()
Definition: cTemplateList.h:69
UNITTEST_FRIEND(cTemplateList)
cTemplateEntry & GetValAt(ITERATE_t index)
Definition: cTemplateList.h:75
float get_ProbabilityTotal() const
Definition: cTemplateList.h:64
cTemplateList()
Definition: cTemplateList.h:56
Definition: cVariant.h:26
void RemoveAll()
Clean up.
Definition: cArray.h:230
TYPE & ElementAt(ITERATE_t nIndex)
Definition: cArray.h:167
ITERATE_t GetSize() const noexcept
Definition: cArray.h:137
Definition: cArray.h:437
REF_t ConstElementAt(ITERATE_t nIndex) const
Definition: cArray.h:534
Definition: cIniSection.h:71
Definition: cMesh.h:22
UNITTEST2_PREDEF(cQuadtree)
int ITERATE_t
like size_t but signed
Definition: Index.h:28
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22
uint16 index
Definition: sample3.cpp:29