ResourcePtr.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   (c) Art Tevs, MPI Informatik Saarbruecken                             *
00004  *       mailto: <tevs@mpi-sb.mpg.de>                                      *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  *                                                                         *
00011  ***************************************************************************/
00012 
00013 
00014 //----------------------------------------------------------------------------------
00015 // Includes
00016 //----------------------------------------------------------------------------------
00017 #include "ResourcePtr.h"
00018 #include "Exception.h"
00019 #include "ResourceSystem.h"
00020 
00021 namespace nrEngine{
00022         
00023         //----------------------------------------------------------------------------------
00024         IResourcePtr::IResourcePtr(const IResourcePtr& resPtr){
00025                 mHolder = resPtr.getResourceHolder();
00026         }
00027 
00028         //----------------------------------------------------------------------------------
00029         bool IResourcePtr::operator==(IResourcePtr& res) const{
00030                 // check whenver given one is null
00031                 if (res.isNull()){
00032                         if (isNull())  return true;
00033                         if (!isNull()) return false;
00034                 }else{
00035                         if (isNull())  return false;            
00036                 }
00037                 
00038                 // check for holders
00039                 ResourceHolder* A = getResourceHolder().get();
00040                 ResourceHolder* B = res.getResourceHolder().get();
00041                 if (A == B) return true;
00042                 
00043                 // At this point, both holders cannot be NULL
00044                 if (A->getResource()->isResourceEmpty() || B->getResource()->isResourceEmpty()) return false;
00045                 if (A->getResource() == B->getResource()) return true;
00046                 
00047                 return false;
00048         }
00049 
00050         
00051         //----------------------------------------------------------------------------------
00052         bool IResourcePtr::operator==(const IResource* p) const{
00053                 
00054                 if (isNull()){
00055                         return (p == NULL);
00056                 }
00057                 
00058                 return (getResourceHolder()->getResource() == p);
00059         }
00060                 
00061         //----------------------------------------------------------------------------------
00062         bool IResourcePtr::operator!=(IResourcePtr& res) const{
00063                         return !operator==(res);
00064         }
00065 
00066         //----------------------------------------------------------------------------------
00067         bool IResourcePtr::operator!=(const IResource* res) const{
00068                         return !operator==(res);
00069         }
00070         
00071         //----------------------------------------------------------------------------------
00072         Result IResourcePtr::lockResource()
00073         {
00074                 if (!isNull())
00075                         if (!getResourceHolder()->lockResource())
00076                                 return RES_LOCK_STATE_STACK_IS_FULL;
00077                 else
00078                         return RES_PTR_IS_NULL;
00079                         
00080                 return OK;
00081         }
00082 
00083         //----------------------------------------------------------------------------------
00084         Result IResourcePtr::unlockResource()
00085         {
00086                 if (!isNull())
00087                         getResourceHolder()->unlockResource();
00088                 else
00089                         return RES_PTR_IS_NULL;
00090                 
00091                 return OK;
00092         }
00093         
00094         //----------------------------------------------------------------------------------
00095         Result IResourcePtr::lockEmpty()
00096         {
00097                 if (!isNull())
00098                         if (!getResourceHolder()->lockEmpty())
00099                                 return RES_LOCK_STATE_STACK_IS_FULL;
00100                 else
00101                         return RES_PTR_IS_NULL;
00102                         
00103                 return OK;
00104         }
00105 
00106         //----------------------------------------------------------------------------------
00107         Result IResourcePtr::unlockEmpty()
00108         {
00109                 if (!isNull())
00110                         getResourceHolder()->unlockEmpty();
00111                 else
00112                         return RES_PTR_IS_NULL;
00113                 
00114                 return OK;
00115         }
00116         
00117         //----------------------------------------------------------------------------------
00118         IResource* IResourcePtr::getBase() const{
00119                 NR_ASSERT(mHolder.get() != NULL && "Holder does not contain valid data");
00120                 return mHolder->getResource();
00121         }
00122 
00123 };
00124 

Generated on Wed Sep 12 23:19:42 2007 for nrEngine by  doxygen 1.5.1