Drizzled Public API Documentation

CSObject.cc
00001 /* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
00002  *
00003  * PrimeBase Media Stream for MySQL
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00018  *
00019  * Original author: Paul McCullagh (H&G2JCtL)
00020  * Continued development: Barry Leslie
00021  *
00022  * 2007-05-20
00023  *
00024  * A basic syncronized object.
00025  *
00026  */
00027 
00028 #include "CSConfig.h"
00029 
00030 #include <assert.h>
00031 
00032 #include "CSGlobal.h"
00033 #include "CSDefs.h"
00034 #include "CSObject.h"
00035 #include "CSMemory.h"
00036 
00037 #ifdef DEBUG
00038 #undef retain
00039 #undef release
00040 #endif
00041 
00042 /*
00043  * ---------------------------------------------------------------
00044  * BASIC OBJECTS
00045  */
00046 
00047 #ifdef DEBUG
00048 void CSObject::retain(const char *func, const char *file, uint32_t line)
00049 {
00050   CSException::throwAssertion(func, file, line, "Non-referenced object cannot be referenced");
00051 }
00052 #else
00053 void CSObject::retain()
00054 {
00055   CSException::throwAssertion(CS_CONTEXT, "Non-referenced object cannot be referenced");
00056 }
00057 #endif
00058 
00059 #ifdef DEBUG
00060 void CSObject::release(const char *, const char *, uint32_t )
00061 #else
00062 void CSObject::release()
00063 #endif
00064 {
00065   delete this;
00066 }
00067 
00068 CSObject *CSObject::getKey() { CSException::throwCoreError(CS_CONTEXT, CS_ERR_IMPL_MISSING, __FUNC__); return NULL; }
00069 
00070 int CSObject::compareKey(CSObject *)  { CSException::throwCoreError(CS_CONTEXT, CS_ERR_IMPL_MISSING, __FUNC__); return 0; }
00071 
00072 uint32_t CSObject::hashKey()  { CSException::throwCoreError(CS_CONTEXT, CS_ERR_IMPL_MISSING, __FUNC__); return 0; }
00073 
00074 CSObject *CSObject::getHashLink() { CSException::throwCoreError(CS_CONTEXT, CS_ERR_IMPL_MISSING, __FUNC__); return NULL; }
00075 
00076 void CSObject::setHashLink(CSObject *) { CSException::throwCoreError(CS_CONTEXT, CS_ERR_IMPL_MISSING, __FUNC__); }
00077 
00078 CSObject *CSObject::getNextLink() { CSException::throwCoreError(CS_CONTEXT, CS_ERR_IMPL_MISSING, __FUNC__); return NULL; }
00079 
00080 CSObject *CSObject::getPrevLink() { CSException::throwCoreError(CS_CONTEXT, CS_ERR_IMPL_MISSING, __FUNC__); return NULL; }
00081 
00082 void CSObject::setNextLink(CSObject *) { CSException::throwCoreError(CS_CONTEXT, CS_ERR_IMPL_MISSING, __FUNC__); }
00083 
00084 void CSObject::setPrevLink(CSObject *) { CSException::throwCoreError(CS_CONTEXT, CS_ERR_IMPL_MISSING, __FUNC__); }
00085 
00086 /*
00087  * ---------------------------------------------------------------
00088  * STATIC OBJECTS
00089  */
00090 
00091 #ifdef DEBUG
00092 void CSStaticObject::retain(const char *, const char *, uint32_t )
00093 #else
00094 void CSStaticObject::retain()
00095 #endif
00096 {
00097 }
00098 
00099 #ifdef DEBUG
00100 void CSStaticObject::release(const char *, const char *, uint32_t )
00101 #else
00102 void CSStaticObject::release()
00103 #endif
00104 {
00105   finalize();
00106 }
00107 
00108 /*
00109  * ---------------------------------------------------------------
00110  * REFERENCE OBJECTS
00111  */
00112 
00113 CSRefObject::CSRefObject():
00114 CSObject(),
00115 iRefCount(1)
00116 {
00117 #ifdef DEBUG
00118   iTrackMe = 0;
00119   cs_mm_track_memory(NULL, NULL, 0, this, true, iRefCount, iTrackMe);
00120 #endif
00121 }
00122 
00123 CSRefObject::~CSRefObject()
00124 {
00125   ASSERT(iRefCount == 0);
00126 }
00127 
00128 #ifdef DEBUG
00129 void CSRefObject::retain(const char *func, const char *file, uint32_t line)
00130 #else
00131 void CSRefObject::retain()
00132 #endif
00133 {
00134   if (!iRefCount)
00135     CSException::throwAssertion(CS_CONTEXT, "Freed object being retained.");
00136     
00137   iRefCount++;
00138 #ifdef DEBUG
00139   cs_mm_track_memory(func, file, line, this, true, iRefCount, iTrackMe);
00140 #endif
00141 }
00142 
00143 #ifdef DEBUG
00144 void CSRefObject::release(const char *func, const char *file, uint32_t line)
00145 #else
00146 void CSRefObject::release()
00147 #endif
00148 {
00149   bool terminate;
00150 
00151 #ifdef DEBUG
00152   cs_mm_track_memory(func, file, line, this, false, iRefCount, iTrackMe);
00153 #endif
00154   iRefCount--;
00155   if (!iRefCount)
00156     terminate = true;
00157   else
00158     terminate = false;
00159 
00160   if (terminate)
00161     delete this;
00162 }
00163 
00164 #ifdef DEBUG
00165 void CSRefObject::startTracking()
00166 {
00167   iTrackMe = 1;
00168   cs_mm_track_memory(NULL, NULL, 0, this, true, iRefCount, iTrackMe);
00169 }
00170 #endif
00171 
00172 /*
00173  * ---------------------------------------------------------------
00174  * SHARED REFERENCE OBJECTS
00175  */
00176 
00177 CSSharedRefObject::CSSharedRefObject():
00178 CSObject(),
00179 CSSync(),
00180 iRefCount(1)
00181 {
00182 #ifdef DEBUG
00183   iTrackMe = 0;
00184   cs_mm_track_memory(NULL, NULL, 0, this, true, iRefCount, iTrackMe);
00185 #endif
00186 }
00187 
00188 CSSharedRefObject::~CSSharedRefObject()
00189 {
00190   ASSERT(iRefCount == 0);
00191 }
00192 
00193 #ifdef DEBUG
00194 void CSSharedRefObject::retain(const char *func, const char *file, uint32_t line)
00195 #else
00196 void CSSharedRefObject::retain()
00197 #endif
00198 {
00199   lock();
00200   iRefCount++;
00201 #ifdef DEBUG
00202   cs_mm_track_memory(func, file, line, this, true, iRefCount, iTrackMe);
00203 #endif
00204   unlock();
00205 }
00206 
00207 #ifdef DEBUG
00208 void CSSharedRefObject::release(const char *func, const char *file, uint32_t line)
00209 #else
00210 void CSSharedRefObject::release()
00211 #endif
00212 {
00213   bool terminate;
00214 
00215   lock();
00216 #ifdef DEBUG
00217   cs_mm_track_memory(func, file, line, this, false, iRefCount, iTrackMe);
00218 #endif
00219   iRefCount--;
00220   if (!iRefCount)
00221     terminate = true;
00222   else
00223     terminate = false;
00224   unlock();
00225 
00226   if (terminate)
00227     delete this;
00228 }
00229 
00230 #ifdef DEBUG
00231 void CSSharedRefObject::startTracking()
00232 {
00233   iTrackMe = 1;
00234   cs_mm_track_memory(NULL, NULL, 0, this, true, iRefCount, iTrackMe);
00235 }
00236 #endif
00237 
00238 #ifdef DEBUG
00239 /*
00240 void CSSharedRefObject::retain(const char *func, const char *file, uint32_t line)
00241 {
00242   lock();
00243   iRefCount++;
00244   cs_mm_print_track(func, file, line, this, true, iRefCount);
00245   unlock();
00246 }
00247 
00248 void CSSharedRefObject::release(const char *func, const char *file, uint32_t line)
00249 {
00250   bool terminate;
00251 
00252   lock();
00253   cs_mm_track_memory(func, file, line, this, false, iRefCount, iTrackMe);
00254   iRefCount--;
00255   if (!iRefCount)
00256     terminate = true;
00257   else
00258     terminate = false;
00259   unlock();
00260 
00261   if (terminate)
00262     delete this;
00263 }
00264 */
00265 #endif
00266 
00267