- Main Page
- Related Pages
- Classes
- Files
- Examples

- File List
- File Members

# skype-ptr-vector.cpp

Go to the documentation of this file.

    00001
    00002 #include "skype-ptr-vector.h"
    00003
    00004 /** \cond INTERNAL */
    00005 class SEPtrVector::Data
    00006 {
    00007 public:
    00008         unsigned int ref;
    00009         void** list;
    00010         size_t size;
    00011 };
    00012 /** \endcond */
    00013
    00014 SEPtrVector::SEPtrVector()
    00015                 :d(0)
    00016 {
    00017
    00018 }
    00019
    00020 SEPtrVector::SEPtrVector(size_t s)
    00021 {
    00022         if (0 == s) {
    00023                 d = 0;
    00024                 return;
    00025         }
    00026
    00027         d = new Data();
    00028
    00029         d->size = s;
    00030         d->list = new void*[s];
    00031         d->ref = 1;
    00032 }
    00033
    00034 SEPtrVector::SEPtrVector(const SEPtrVector& pv)
    00035                 :d(0)
    00036 {
    00037         *this = pv;
    00038 }
    00039
    00040 SEPtrVector::~SEPtrVector()
    00041 {
    00042         d_unref();
    00043 }
    00044
    00045 void SEPtrVector::setnewsize(size_t s)
    00046 {
    00047 //  d_unref();
    00048
    00049         void** tmp = new void*[s];
    00050         unsigned int i = 0;
    00051         while (i < size() && i < s) {
    00052                 tmp[i] = d->list[i];
    00053                 i++;
    00054         }
    00055
    00056         if (d) {
    00057                 delete[] d->list;
    00058                 delete d;
    00059         }
    00060
    00061         d = new Data();
    00062         d->size = s;
    00063         d->list = tmp;
    00064
    00065 //  d_ref();
    00066 }
    00067
    00068 size_t SEPtrVector::size() const
    00069 {
    00070         if (0 == d)
    00071                 return 0;
    00072
    00073         return d->size;
    00074 }
    00075
    00076 void*& SEPtrVector::operator[](size_t n) const
    00077 {
    00078         static void* null = 0;
    00079
    00080         if ((0 == d) || (n >= size()))
    00081                 return null;
    00082
    00083         return d->list[n];
    00084 }
    00085
    00086 SEPtrVector& SEPtrVector::operator=(const SEPtrVector& pv)
    00087 {
    00088         const_cast<SEPtrVector&>(pv).d_ref();
    00089         d_unref();
    00090
    00091         d = pv.d;
    00092
    00093
    00094         return *this;
    00095 }
    00096
    00097 /** \cond INTERNAL */
    00098 void SEPtrVector::d_ref()
    00099 {
    00100         if (0 == d)
    00101                 return;
    00102
    00103         d->ref++;
    00104 }
    00105
    00106 void SEPtrVector::d_unref()
    00107 {
    00108         if (0 == d)
    00109                 return;
    00110
    00111         if (d->ref > 1)
    00112                 d->ref--;
    00113         else {
    00114                 delete[] d->list;
    00115
    00116                 delete d;
    00117
    00118                 d = 0;
    00119         }
    00120 }
    00121 /** \endcond */

All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

(c) Skype Technologies S.A. Confidential/Proprietary

Last updated: Fri Jan 27 2012