TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/host/ofx/OfxhMemory.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License :
00003  *
00004  * Copyright (c) 2007-2009, The Open Effects Association Ltd. All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *
00009  * Redistributions of source code must retain the above copyright notice,
00010  * this list of conditions and the following disclaimer.
00011  * Redistributions in binary form must reproduce the above copyright notice,
00012  * this list of conditions and the following disclaimer in the documentation
00013  * and/or other materials provided with the distribution.
00014  * Neither the name The Open Effects Association Ltd, nor the names of its
00015  * contributors may be used to endorse or promote products derived from this
00016  * software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00019  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00020  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00021  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
00022  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00023  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00024  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00025  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00026  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00027  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 // ofx host
00031 #include "OfxhMemory.hpp"
00032 
00033 // ofx
00034 #include <ofxCore.h>
00035 #include <ofxImageEffect.h>
00036 
00037 namespace tuttle {
00038 namespace host {
00039 namespace ofx {
00040 
00041 OfxhMemory::OfxhMemory()
00042         : _ptr( 0 )
00043         , _locked( false )
00044 {}
00045 
00046 OfxhMemory::~OfxhMemory()
00047 {
00048         delete [] _ptr;
00049 }
00050 
00051 bool OfxhMemory::alloc( size_t nBytes )
00052 {
00053         if( !_locked )
00054         {
00055                 if( _ptr )
00056                         freeMem();
00057                 _ptr = new char[nBytes];
00058                 return true;
00059         }
00060         else
00061                 return false;
00062 }
00063 
00064 OfxImageMemoryHandle OfxhMemory::getHandle()
00065 {
00066         return ( OfxImageMemoryHandle ) this;
00067 }
00068 
00069 void OfxhMemory::freeMem()
00070 {
00071         delete [] _ptr;
00072         _ptr = 0;
00073 }
00074 
00075 void* OfxhMemory::getPtr()
00076 {
00077         return _ptr;
00078 }
00079 
00080 void OfxhMemory::lock()
00081 {
00082         _locked = true;
00083 }
00084 
00085 void OfxhMemory::unlock()
00086 {
00087         _locked = false;
00088 }
00089 
00090 }
00091 }
00092 }
00093