* Creates a new DataHandle to the data item with the key \a name in \a dc, that behaves like a T*.
...
...
@@ -57,10 +58,10 @@ namespace campvis {
,data(nullptr)
{
if(dh){
data=dynamic_cast<constT*>(dh._ptr.get());
data=dynamic_cast<T*>(dh._ptr.get());
if(data==nullptr){
if(!silent)
LDEBUGC("CAMPVis.core.ScopedTypedData (Readonly)","Found DataHandle with id '"<<name<<"', but it is of wrong type("<<typeid(dh._ptr.get()).name()<<" instead of "<<typeid(T).name()<<").");
LDEBUGC("CAMPVis.core.ScopedTypedData","["<<(isWritable?"Writable":"Readonly")<<"] Found DataHandle with id '"<<name<<"', but it is of wrong type("<<typeid(dh._ptr.get()).name()<<" instead of "<<typeid(T).name()<<").");
dh=DataHandle(0);
}
...
...
@@ -71,7 +72,7 @@ namespace campvis {
}
else{
if(!silent)
LDEBUGC("CAMPVis.core.ScopedTypedData (Readonly)","Could not find a DataHandle with id '"<<name<<"' in DataContainer '"<<dc.getName()<<"'.");
LDEBUGC("CAMPVis.core.ScopedTypedData","["<<(isWritable?"Writable":"Readonly")<<"] Could not find a DataHandle with id '"<<name<<"' in DataContainer '"<<dc.getName()<<"'.");
}
};
...
...
@@ -80,10 +81,10 @@ namespace campvis {
,dh(handle)
,data(nullptr)
{
data=dynamic_cast<constT*>(dh._ptr.get());
data=dynamic_cast<T*>(dh._ptr.get());
if(data==nullptr){
if(!silent)
LDEBUGC("CAMPVis.core.ScopedTypedData (Readonly)","DataHandle is of wrong type ("<<typeid(dh._ptr.get()).name()<<" instead of "<<typeid(T).name()<<").");
LDEBUGC("CAMPVis.core.ScopedTypedData","["<<(isWritable?"Writable":"Readonly")<<"] DataHandle is of wrong type ("<<typeid(dh._ptr.get()).name()<<" instead of "<<typeid(T).name()<<").");
dh=DataHandle(nullptr);
}
...
...
@@ -94,25 +95,26 @@ namespace campvis {
/**
* Move-Constructor that moves the lock over
* \note: Since tbb locks do not support move-construction, this implementation is not very efficient
* \note: Since tbb locks do not support move-construction, this implementation *will* release the lock during the handoff
*/
ScopedTypedData(ScopedTypedData&&other)
:AbstractData::LockType()
,dh(other.dh)
,data(other.data)
{
other.release();// force a release - otherwise we might deadlock
if(data!=nullptr){// we have a valid handle, so we need to lock it
acquire(dh._ptr->_mutex,isWritable);
}
other.dh=DataHandle(nullptr);
other.data=nullptr;
other.release();
}
~ScopedTypedData(){
if(dh)
release();// we release manually to make sure to release before the datahandle is destroyed - otherwise the mutex is destroyed before it is released
if(dh)
release();// we release manually to make sure to release before the datahandle is destroyed - otherwise the mutex might be destroyed before it is released
}
/**
...
...
@@ -131,7 +133,27 @@ namespace campvis {
returndata;
}
/**
// Note: The following enable_if construct yields an internal compiler error for VC 2013, which is why we explicitly specialize
// the whole class template below
///**
//* Implicit conversion operator to T*. Only applies for writable ScopedTypedData instances.
//* \return The data in the DataHandle, may be 0 when no DataHandle was found, or the data is of the wrong type.
* Creates a new DataHandle to the data item with the key \a name in \a dc, that behaves like a T*.
...
...
@@ -168,18 +194,18 @@ namespace campvis {
data=dynamic_cast<T*>(dh._ptr.get());
if(data==nullptr){
if(!silent)
LDEBUGC("CAMPVis.core.ScopedTypedData (Writable)","Found DataHandle with id '"<<name<<"', but it is of wrong type("<<typeid(dh._ptr.get()).name()<<" instead of "<<typeid(T).name()<<").");
LDEBUGC("CAMPVis.core.ScopedTypedData","["<<(isWritable?"Writable":"Readonly")<<"] Found DataHandle with id '"<<name<<"', but it is of wrong type("<<typeid(dh._ptr.get()).name()<<" instead of "<<typeid(T).name()<<").");
dh=DataHandle(nullptr);
dh=DataHandle(0);
}
else{// we have a valid handle, so we need to lock it
// lock(data->_mutex);
acquire(dh._ptr->_mutex,true);
// lock_shared(dh->_mutex);
acquire(dh._ptr->_mutex,isWritable);
}
}
else{
if(!silent)
LDEBUGC("CAMPVis.core.ScopedTypedData (Writable)","Could not find a DataHandle with id '"<<name<<"' in DataContainer '"<<dc.getName()<<"'.");
LDEBUGC("CAMPVis.core.ScopedTypedData","["<<(isWritable?"Writable":"Readonly")<<"] Could not find a DataHandle with id '"<<name<<"' in DataContainer '"<<dc.getName()<<"'.");
}
};
...
...
@@ -191,40 +217,41 @@ namespace campvis {
data=dynamic_cast<T*>(dh._ptr.get());
if(data==nullptr){
if(!silent)
LDEBUGC("CAMPVis.core.ScopedTypedData (Writable)","DataHandle is of wrong type ("<<typeid(dh._ptr.get()).name()<<" instead of "<<typeid(T).name()<<").");
LDEBUGC("CAMPVis.core.ScopedTypedData","["<<(isWritable?"Writable":"Readonly")<<"] DataHandle is of wrong type ("<<typeid(dh._ptr.get()).name()<<" instead of "<<typeid(T).name()<<").");
dh=DataHandle(nullptr);
}
else{// we have a valid handle, so we need to lock it
// lock(data->_mutex);
acquire(dh._ptr->_mutex,true);
acquire(dh._ptr->_mutex,isWritable);
}
};
/**
*/
* Move-Constructor that moves the lock over
* \note: Since tbb locks do not support move-construction, this implementation is not very efficient
*/
ScopedTypedData(ScopedTypedData&&other)
:AbstractData::LockType()
,dh(other.dh)
,data(other.data)
{
other.release();// force a release - otherwise we might deadlock
if(data!=nullptr){// we have a valid handle, so we need to lock it
other.release();// we need to release the other lock first because we cannot move it directly
acquire(dh._ptr->_mutex,true);
acquire(dh._ptr->_mutex,isWritable);
}
other.dh=DataHandle(nullptr);
other.data=nullptr;
}
~ScopedTypedData(){
if(dh)
release();// we release manually to make sure to release before the datahandle is destroyed - otherwise the mutex is destroyed before it is released
if(dh)
release();// we release manually to make sure to release before the datahandle is destroyed - otherwise the mutex might be destroyed before it is released
}
/**
* Implicit conversion operator to const T*.
* Implicit conversion operator to T*. Only applies for writable ScopedTypedData instances.
* \return The data in the DataHandle, may be 0 when no DataHandle was found, or the data is of the wrong type.
*/
operatorT*(){
...
...
@@ -232,31 +259,31 @@ namespace campvis {
}
/**
* Implicit arrow operator to T*.
* Implicit arrow operator to T*. Only applies for writable ScopedTypedData instances.
* \return The data in the DataHandle, may be 0 when no DataHandle was found, or the data is of the wrong type.
if(autoid=(*renderData)->getColorTexture(_fbo->getNumColorAttachments()))//_fbo->getNumColorAttachments() is the index of the texture that is to be created