123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- #pragma once
- #include "ReferenceCounter.h"
- namespace Framework
- {
- template<class T, class V> class CharMap : public virtual ReferenceCounter
- {
- private:
- V value;
- T** entries;
- public:
- CharMap()
- : ReferenceCounter()
- {
- entries = new T*[256];
- for (int i = 0; i < 256; i++)
- entries[i] = 0;
- value = 0;
- }
- ~CharMap()
- {
- for (int i = 0; i < 256; i++)
- {
- if (entries[i]) entries[i]->release();
- }
- delete[] entries;
- }
- T* get(unsigned char c)
- {
- return entries[(int)c]
- ? dynamic_cast<T*>(entries[(int)c]->getThis())
- : 0;
- }
- T* z(unsigned char c) const
- {
- return entries[(int)c];
- }
- void set(unsigned char c, T* t)
- {
- if (entries[(int)c]) entries[(int)c]->release();
- entries[(int)c] = t;
- }
- void setValue(V v)
- {
- value = v;
- }
- V getValue() const
- {
- return value;
- }
- };
- template<class T, class V> class RCCharMap : public virtual ReferenceCounter
- {
- private:
- V* value;
- T** entries;
- public:
- RCCharMap()
- : ReferenceCounter()
- {
- entries = new T*[256];
- for (int i = 0; i < 256; i++)
- entries[i] = 0;
- value = 0;
- }
- ~RCCharMap()
- {
- for (int i = 0; i < 256; i++)
- {
- if (entries[i]) entries[i]->release();
- }
- delete[] entries;
- if (value) value->release();
- }
- T* get(unsigned char c)
- {
- return entries[(int)c]
- ? dynamic_cast<T*>(entries[(int)c]->getThis())
- : 0;
- }
- T* z(unsigned char c) const
- {
- return entries[(int)c];
- }
- void set(unsigned char c, T* t)
- {
- if (entries[(int)c]) entries[(int)c]->release();
- entries[(int)c] = t;
- }
- void setValue(V* v)
- {
- if (value) value->release();
- value = v;
- }
- V* getValue()
- {
- return value ? dynamic_cast<V*>(value->getThis()) : 0;
- }
- V* zValue()
- {
- return value;
- }
- };
- } // namespace Framework
|