22 changePointer(ptr, deleteMode);
42 DeletePointer(
m_ptr, m_mode);
68 return m_ptr != other.m_ptr;
86 void matioCpp::MatvarHandler::Ownership::dropDependencies(matvar_t *previouslyOwned)
95 if (it == m_dependencyTree.end())
100 for (matvar_t* child : it->second.dependencies)
102 dropDependencies(child);
107 m_dependencyTree.erase(previouslyOwned);
111 : m_main(pointerToDeallocate)
123 return (test && ((test == (m_main.lock()->pointer())) || (m_dependencyTree.find(test) != m_dependencyTree.end())));
133 if (*(owner->
m_ptr) != *(m_main.lock()))
137 assert(m_dependencyTree.find(dep.
parent) != m_dependencyTree.end());
139 m_dependencyTree[dep.
parent].dependencies.insert(owned);
142 m_dependencyTree[owned] = dep;
148 if (!previouslyOwned)
155 if (it == m_dependencyTree.
end())
162 if ((it->second.parent != m_main.lock()->pointer()) && (parent != m_dependencyTree.
end()))
164 parent->second.dependencies.
erase(previouslyOwned);
167 dropDependencies(previouslyOwned);
169 m_dependencyTree.erase(previouslyOwned);
177 locked->deletePointer();
185 m_dependencyTree.clear();
213 return m_ptr->valueType();
218 return m_ptr->variableType();
223 std::string errorPrefix =
"[ERROR][matioCpp::MatvarHandler::GetMatvarDuplicate] ";
243 size_t totalElements = 1;
245 for (
int i = 0; i < inputPtr->rank; ++i)
247 totalElements *= inputPtr->dims[i];
251 for (
size_t i = 0; i < totalElements; ++i)
253 matvar_t* internalPointer = Mat_VarGetCell(shallowCopy.
get(),
static_cast<int>(i));
256 vectorOfPointers[i] = GetMatvarDuplicate(internalPointer);
260 outputPtr = Mat_VarCreate(inputPtr->name, inputPtr->class_type, inputPtr->data_type, inputPtr->rank, inputPtr->dims, vectorOfPointers.
data(), 0);
266 size_t totalElements = 1;
268 for (
int i = 0; i < inputPtr->rank; ++i)
270 totalElements *= inputPtr->dims[i];
273 size_t numberOfFields = Mat_VarGetNumberOfFields(shallowCopy.
get());
277 size_t innerIndex = 0;
278 for (
size_t i = 0; i < totalElements; ++i)
280 for (
size_t field = 0; field < numberOfFields; ++field)
282 matvar_t* internalPointer = Mat_VarGetStructFieldByIndex(shallowCopy.
get(), field, i);
285 vectorOfPointers[innerIndex] = GetMatvarDuplicate(internalPointer);
290 assert(innerIndex == totalElements * numberOfFields);
292 outputPtr = Mat_VarCreate(inputPtr->name, inputPtr->class_type, inputPtr->data_type, inputPtr->rank, inputPtr->dims, vectorOfPointers.
data(), 0);
296 outputPtr = Mat_VarDuplicate(inputPtr, 1);
305 PointerInfo::DeletePointer(pointerToDelete, mode);
void drop(matvar_t *previouslyOwned)
Drop a previously owned pointer and deleted if necessary.
bool isOwning(matvar_t *test)
Check if an input pointer is owned by this ownership object.
void own(matvar_t *owned, const MatvarHandler *owner, matioCpp::DeleteMode mode)
Add a pointer to the list of owned pointers.
Ownership(std::weak_ptr< PointerInfo > pointerToDeallocate)
Constructor.
void dropAll()
Drops all the previously owned pointers and free those that need to be deallocated,...
matvar_t * pointer()
Get the matvar pointer.
PointerInfo()
The deletion mode.
void deletePointer()
Delete the matvar pointer.
ValueType valueType() const
Get the value type.
VariableType variableType() const
Get the variable type.
bool operator!=(const PointerInfo &other) const
Comparison operator.
void changePointer(matvar_t *ptr, DeleteMode deleteMode)
Change the input pointer.
DeleteMode deleteMode() const
Get the deletion mode.
~PointerInfo()
Destructor.
static void DeletePointer(matvar_t *ptr, DeleteMode deleteMode)
Delete the given pointer given the mode.
static matvar_t * GetMatvarDuplicate(const matvar_t *inputPtr)
Get a duplicate of the input matvar pointer/.
static void DeleteMatvar(matvar_t *pointerToDelete, DeleteMode mode=DeleteMode::Delete)
Delete the specified Matvar.
ValueType valueType() const
Get the value type of the pointer.
MatvarHandler()
Default constructor.
std::shared_ptr< PointerInfo > m_ptr
Shared pointer to a PointerInfo.
VariableType variableType() const
Get the variable type of the pointer.
static SharedMatvar GetMatvarShallowDuplicate(const matvar_t *inputPtr)
Get the shallow duplicate of an input Matvar.
virtual matvar_t * get() const final
Docs inherited.
DeleteMode
The delete mode of matvar_t pointers.
@ ShallowDelete
The handler does not delete the pointer.
@ Delete
The handler deletes the pointer but not the data.
VariableType
Define the type of variable.
bool get_types_from_matvart(const matvar_t *input, VariableType &outputVariableType, ValueType &outputValueType)
Get the VariableType and the ValueType from a matvar_t pointer.
ValueType
The list of types for an element of a certain variable type.
matioCpp::DeleteMode mode
The set of dependencies.
matvar_t * parent
Deletion mode for the dependency.