Commit c04b7838 authored by Alexey.Musinov's avatar Alexey.Musinov Committed by Alexander Trofimov

refactoring

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@59881 954022d7-b5bf-4e40-9824-e11837661b57
parent db1692b5
...@@ -7,136 +7,249 @@ ...@@ -7,136 +7,249 @@
#include "string.h" #include "string.h"
#endif #endif
#if 1 //__APPLE__
#include <vector>
template <class T> template <class T>
class CArray class CArray
{ {
public: public:
// Construction/destruction // Construction/destruction
CArray() : m_aT(NULL), m_nSize(0), m_nAllocSize(0) CArray()
{ } { }
~CArray() ~CArray()
{ { }
if (m_aT)
delete []m_aT; CArray(const CArray<T>& src)
} {
int nSrcSize = src.GetCount();
CArray(const CArray<T>& src) : m_aT(NULL), m_nSize(0), m_nAllocSize(0)
{
int nSrcSize = src.GetCount();
if (0 != nSrcSize) if (0 != nSrcSize)
{ {
m_aT = new T[nSrcSize]; for (int i = 0; i < nSrcSize; i++)
if (m_aT != NULL) Add(src[i]);
{ }
m_nAllocSize = nSrcSize; }
for (int i = 0; i < nSrcSize; i++) CArray<T>& operator=(const CArray<T>& src)
Add(src[i]); {
} int nSrcSize = src.GetCount();
}
} RemoveAll();
CArray<T>& operator=(const CArray<T>& src)
{ for (int i = 0; i < nSrcSize; i++)
int nSrcSize = src.GetCount(); Add(src[i]);
RemoveAll(); return *this;
m_aT = new T[nSrcSize]; }
if (m_aT != NULL)
m_nAllocSize = nSrcSize; // Operations
int GetSize() const
for (int i = 0; i < nSrcSize; i++) {
Add(src[i]); return (int)m_aT.size();
}
return *this; int GetCount() const
} {
return (int)m_aT.size();
// Operations }
int GetSize() const
{ INT SetCount(int nAllocSize)
return m_nSize; {
} RemoveAll();
int GetCount() const
{ for (int i = 0; i < nAllocSize; i++)
return m_nSize; Add();
}
return TRUE;
INT SetCount(int nAllocSize) }
{
RemoveAll(); INT Add()
if (nAllocSize != m_nAllocSize) {
{ T element;
int nNewAllocSize = nAllocSize; m_aT.push_back(element);
m_aT = new T[nNewAllocSize];
if (NULL == m_aT)
return FALSE;
m_nSize = nAllocSize;
}
return TRUE;
}
INT Add()
{
if (m_nSize == m_nAllocSize)
{
int nNewAllocSize = (m_nAllocSize == 0) ? 1 : (m_nSize * 2);
T* newT = new T[nNewAllocSize];
if (NULL == newT)
return FALSE;
m_nAllocSize = nNewAllocSize;
if (m_nSize != 0)
{
for (int i = 0; i < m_nSize; ++i)
newT[i] = m_aT[i];
}
RELEASEARRAYOBJECTS(m_aT);
m_aT = newT;
}
m_nSize++; return TRUE;
return TRUE; }
}
INT Add(const T& t)
{
m_aT.push_back(t);
INT Add(const T& t) return TRUE;
{ }
if (m_nSize == m_nAllocSize) INT RemoveAt(int nIndex)
{ {
int nNewAllocSize = (m_nAllocSize == 0) ? 1 : (m_nSize * 2); m_aT.erase(m_aT.begin() + nIndex);
return TRUE;
T* newT = new T[nNewAllocSize]; }
INT RemoveAt(int nIndex, int nCount)
{
m_aT.erase(m_aT.begin() + nIndex, m_aT.begin() + nIndex + nCount);
return TRUE;
}
void RemoveAll()
{
m_aT.clear();
}
const T& operator[] (int nIndex) const
{
if (nIndex < 0 || nIndex >= (int)m_aT.size())
{
return m_aT[0]; // exeption
}
return m_aT[nIndex];
}
T& operator[] (int nIndex)
{
if (nIndex < 0 || nIndex >= (int)m_aT.size())
{
return m_aT[0]; // exeption
}
return m_aT[nIndex];
}
private:
std::vector<T> m_aT;
};
if (NULL == newT) #else
return FALSE;
m_nAllocSize = nNewAllocSize;
if (m_nSize != 0) // NOTE: при определенных условиях ловим исключения в деструкторе класса (T)CArray()::~CArray()
{
for (int i = 0; i < m_nSize; ++i)
newT[i] = m_aT[i];
}
RELEASEARRAYOBJECTS(m_aT);
m_aT = newT;
}
m_aT[m_nSize++] = t; template <class T>
return TRUE; class CArray
} {
INT RemoveAt(int nIndex) public:
{ // Construction/destruction
if (nIndex < 0 || nIndex >= m_nSize) CArray() : m_aT(NULL), m_nSize(0), m_nAllocSize(0)
return FALSE; { }
m_aT[nIndex].~T();
if (nIndex != (m_nSize - 1)) ~CArray()
{
if (m_aT)
delete []m_aT;
}
CArray(const CArray<T>& src) : m_aT(NULL), m_nSize(0), m_nAllocSize(0)
{
int nSrcSize = src.GetCount();
if (0 != nSrcSize)
{
m_aT = new T[nSrcSize];
if (m_aT != NULL)
{
m_nAllocSize = nSrcSize;
for (int i = 0; i < nSrcSize; i++)
Add(src[i]);
}
}
}
CArray<T>& operator=(const CArray<T>& src)
{
int nSrcSize = src.GetCount();
RemoveAll();
m_aT = new T[nSrcSize];
if (m_aT != NULL)
m_nAllocSize = nSrcSize;
for (int i = 0; i < nSrcSize; i++)
Add(src[i]);
return *this;
}
// Operations
int GetSize() const
{
return m_nSize;
}
int GetCount() const
{
return m_nSize;
}
INT SetCount(int nAllocSize)
{
RemoveAll();
if (nAllocSize != m_nAllocSize)
{
int nNewAllocSize = nAllocSize;
m_aT = new T[nNewAllocSize];
if (NULL == m_aT)
return FALSE;
m_nSize = nAllocSize;
}
return TRUE;
}
INT Add()
{
if (m_nSize == m_nAllocSize)
{
int nNewAllocSize = (m_nAllocSize == 0) ? 1 : (m_nSize * 2);
T* newT = new T[nNewAllocSize];
if (NULL == newT)
return FALSE;
m_nAllocSize = nNewAllocSize;
if (m_nSize != 0)
{
for (int i = 0; i < m_nSize; ++i)
newT[i] = m_aT[i];
}
RELEASEARRAYOBJECTS(m_aT);
m_aT = newT;
}
m_nSize++;
return TRUE;
}
INT Add(const T& t)
{
if (m_nSize == m_nAllocSize)
{
int nNewAllocSize = (m_nAllocSize == 0) ? 1 : (m_nSize * 2);
T* newT = new T[nNewAllocSize];
if (NULL == newT)
return FALSE;
m_nAllocSize = nNewAllocSize;
if (m_nSize != 0)
{
for (int i = 0; i < m_nSize; ++i)
newT[i] = m_aT[i];
}
RELEASEARRAYOBJECTS(m_aT);
m_aT = newT;
}
m_aT[m_nSize++] = t;
return TRUE;
}
INT RemoveAt(int nIndex)
{
if (nIndex < 0 || nIndex >= m_nSize)
return FALSE;
m_aT[nIndex].~T();
if (nIndex != (m_nSize - 1))
{ {
#ifdef WIN32 #ifdef WIN32
memmove_s((void*)(m_aT + nIndex), (m_nSize - nIndex) * sizeof(T), (void*)(m_aT + nIndex + 1), (m_nSize - (nIndex + 1)) * sizeof(T)); memmove_s((void*)(m_aT + nIndex), (m_nSize - nIndex) * sizeof(T), (void*)(m_aT + nIndex + 1), (m_nSize - (nIndex + 1)) * sizeof(T));
...@@ -144,72 +257,74 @@ public: ...@@ -144,72 +257,74 @@ public:
memmove((void*)(m_aT + nIndex), (void*)(m_aT + nIndex + 1), (m_nSize - (nIndex + 1)) * sizeof(T)); memmove((void*)(m_aT + nIndex), (void*)(m_aT + nIndex + 1), (m_nSize - (nIndex + 1)) * sizeof(T));
#endif #endif
} }
m_nSize--; m_nSize--;
return TRUE; return TRUE;
} }
INT RemoveAt(int nIndex, int nCount) INT RemoveAt(int nIndex, int nCount)
{ {
if (nIndex < 0 || nIndex >= m_nSize || nCount < 1) if (nIndex < 0 || nIndex >= m_nSize || nCount < 1)
return FALSE; return FALSE;
if ((nIndex + nCount) > m_nSize) if ((nIndex + nCount) > m_nSize)
nCount = m_nSize - nIndex; nCount = m_nSize - nIndex;
for (int i = 0; i < nCount; ++i) for (int i = 0; i < nCount; ++i)
m_aT[nIndex + i].~T(); m_aT[nIndex + i].~T();
if ((nIndex + nCount) != m_nSize) if ((nIndex + nCount) != m_nSize)
{ {
#ifdef WIN32 #ifdef WIN32
memmove_s((void*)(m_aT + nIndex), (m_nSize - nIndex - nCount + 1) * sizeof(T), (void*)(m_aT + nIndex + nCount), (m_nSize - (nIndex + nCount)) * sizeof(T)); memmove_s((void*)(m_aT + nIndex), (m_nSize - nIndex - nCount + 1) * sizeof(T), (void*)(m_aT + nIndex + nCount), (m_nSize - (nIndex + nCount)) * sizeof(T));
#else #else
memmove((void*)(m_aT + nIndex), (void*)(m_aT + nIndex + nCount), (m_nSize - (nIndex + nCount)) * sizeof(T)); memmove((void*)(m_aT + nIndex), (void*)(m_aT + nIndex + nCount), (m_nSize - (nIndex + nCount)) * sizeof(T));
#endif #endif
} }
m_nSize -= nCount; m_nSize -= nCount;
return TRUE; return TRUE;
} }
void RemoveAll() void RemoveAll()
{ {
if (m_aT != NULL) if (m_aT != NULL)
{ {
for(int i = 0; i < m_nSize; i++) for(int i = 0; i < m_nSize; i++)
m_aT[i].~T(); m_aT[i].~T();
RELEASEARRAYOBJECTS(m_aT); RELEASEARRAYOBJECTS(m_aT);
} }
m_nSize = 0; m_nSize = 0;
m_nAllocSize = 0; m_nAllocSize = 0;
} }
const T& operator[] (int nIndex) const const T& operator[] (int nIndex) const
{ {
if (nIndex < 0 || nIndex >= m_nSize) if (nIndex < 0 || nIndex >= m_nSize)
{ {
return m_aT[0]; // exeption return m_aT[0]; // exeption
} }
return m_aT[nIndex]; return m_aT[nIndex];
} }
T& operator[] (int nIndex) T& operator[] (int nIndex)
{ {
if (nIndex < 0 || nIndex >= m_nSize) if (nIndex < 0 || nIndex >= m_nSize)
{ {
return m_aT[0]; // exeption return m_aT[0]; // exeption
} }
return m_aT[nIndex]; return m_aT[nIndex];
} }
T* GetData() const T* GetData() const
{ {
return m_aT; return m_aT;
} }
private: private:
T* m_aT; T* m_aT;
int m_nSize; int m_nSize;
int m_nAllocSize; int m_nAllocSize;
}; };
#endif
#endif // !defined(_GRAPHICS_ARRAY_H) #endif // !defined(_GRAPHICS_ARRAY_H)
#ifndef _BUILD_IRENDERER_H_ #ifndef _BUILD_IRENDERER_H_
#define _BUILD_IRENDERER_H_ #define _BUILD_IRENDERER_H_
#pragma once #pragma once
...@@ -7,33 +7,57 @@ ...@@ -7,33 +7,57 @@
#include "Matrix.h" #include "Matrix.h"
#include <string> #include <string>
#include <libkern/OSAtomic.h>
class IGrObject class IGrObject
{ {
protected: protected:
ULONG m_lRef;
#ifdef __APPLE__
volatile int32_t m_lRef;
#else
ULONG m_lRef;
#endif
public: public:
IGrObject() IGrObject()
{ {
m_lRef = 1; m_lRef = 1;
} }
virtual ~IGrObject() virtual ~IGrObject()
{ {
} }
virtual ULONG AddRef() #ifdef __APPLE__
{ virtual ULONG AddRef()
++m_lRef; {
return m_lRef; OSAtomicIncrement32(&m_lRef);
} return (ULONG)m_lRef;
}
virtual ULONG Release() virtual ULONG Release()
{ {
ULONG ret = --m_lRef; int32_t ret = OSAtomicDecrement32(&m_lRef);
if (0 == m_lRef) if (0 == m_lRef)
delete this; delete this;
return ret;
} return (ULONG)ret;
}
#else
virtual ULONG AddRef()
{
++m_lRef;
return m_lRef;
}
virtual ULONG Release()
{
ULONG ret = --m_lRef;
if (0 == m_lRef)
delete this;
return ret;
}
#endif
}; };
// тип в DrawPath // тип в DrawPath
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment