Clover Git
OpenCL 1.1 software implementation

object.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011, Denis Steckelmacher <steckdenis@yahoo.fr>
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *     * Redistributions of source code must retain the above copyright
00008  *       notice, this list of conditions and the following disclaimer.
00009  *     * Redistributions in binary form must reproduce the above copyright
00010  *       notice, this list of conditions and the following disclaimer in the
00011  *       documentation and/or other materials provided with the distribution.
00012  *     * Neither the name of the copyright holder nor the
00013  *       names of its contributors may be used to endorse or promote products
00014  *       derived from this software without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
00020  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  */
00027 
00033 #include "object.h"
00034 
00035 using namespace Coal;
00036 
00037 static std::list<Object *>& getKnownObjects()
00038 {
00039     static std::list<Object *> known_objects;
00040     return known_objects;
00041 }
00042 
00043 
00044 Object::Object(Type type, Object *parent)
00045 : p_references(1), p_parent(parent), p_type(type), p_release_parent(true)
00046 {
00047     if (parent)
00048         parent->reference();
00049 
00050     // Add object in the list of known objects
00051     getKnownObjects().push_front(this);
00052     p_it = getKnownObjects().begin();
00053 }
00054 
00055 Object::~Object()
00056 {
00057     if (p_parent && p_parent->dereference() && p_release_parent)
00058         delete p_parent;
00059 
00060     // Remove object from the list of known objects
00061     getKnownObjects().erase(p_it);
00062 }
00063 
00064 void Object::reference()
00065 {
00066     p_references++;
00067 }
00068 
00069 bool Object::dereference()
00070 {
00071     p_references--;
00072     return (p_references == 0);
00073 }
00074 
00075 void Object::setReleaseParent (bool release)
00076 {
00077     p_release_parent = release;
00078 }
00079 
00080 unsigned int Object::references() const
00081 {
00082     return p_references;
00083 }
00084 
00085 Object *Object::parent() const
00086 {
00087     return p_parent;
00088 }
00089 
00090 Object::Type Object::type() const
00091 {
00092     return p_type;
00093 }
00094 
00095 bool Object::isA(Object::Type type) const
00096 {
00097     // Check for null values
00098     if (this == 0)
00099         return false;
00100 
00101     // Check that the value isn't garbage or freed pointer
00102     std::list<Object *>::const_iterator it = getKnownObjects().begin(),
00103                                         e = getKnownObjects().end();
00104     while (it != e)
00105     {
00106         if (*it == this)
00107             return this->type() == type;
00108 
00109         ++it;
00110     }
00111 
00112     return false;
00113 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines