mirror of
https://github.com/nasa/trick.git
synced 2025-01-07 05:38:46 +00:00
Merge in the er7_utils integrators
Wasn't supposed to add the CheckpointHelper. refs #180
This commit is contained in:
parent
2c794060f4
commit
1c5f682297
@ -1 +0,0 @@
|
||||
libSTLHelper.a
|
@ -1,198 +0,0 @@
|
||||
/*
|
||||
* Alloc.cpp
|
||||
*
|
||||
* Created on: Aug 24, 2015
|
||||
* Author: tbrain
|
||||
*/
|
||||
|
||||
#include "Alloc.hh"
|
||||
|
||||
namespace CheckpointHelper
|
||||
{
|
||||
#if (defined TRICK_VER) && (TRICK_VER >= 10)
|
||||
std::string treatAllocName(const std::string & nameIn)
|
||||
{
|
||||
std::string treatedName(nameIn);
|
||||
|
||||
// Always remove "&"
|
||||
std::size_t found = treatedName.find('&');
|
||||
if (found != std::string::npos)
|
||||
{
|
||||
treatedName.erase(0, 1);
|
||||
}
|
||||
|
||||
found = treatedName.find('.');
|
||||
while (found != std::string::npos)
|
||||
{
|
||||
treatedName.replace(found, 1, "_");
|
||||
found = treatedName.find('.');
|
||||
}
|
||||
found = treatedName.find('[');
|
||||
while (found != std::string::npos)
|
||||
{
|
||||
treatedName.replace(found, 1, "_");
|
||||
found = treatedName.find('[');
|
||||
}
|
||||
found = treatedName.find(']');
|
||||
while (found != std::string::npos)
|
||||
{
|
||||
treatedName.replace(found, 1, "_");
|
||||
found = treatedName.find(']');
|
||||
}
|
||||
found = treatedName.find(' ');
|
||||
while (found != std::string::npos)
|
||||
{
|
||||
treatedName.replace(found, 1, "_");
|
||||
found = treatedName.find(' ');
|
||||
}
|
||||
found = treatedName.find('+');
|
||||
while (found != std::string::npos)
|
||||
{
|
||||
treatedName.replace(found, 1, "_");
|
||||
found = treatedName.find('+');
|
||||
}
|
||||
found = treatedName.find(':');
|
||||
while (found != std::string::npos)
|
||||
{
|
||||
treatedName.replace(found, 1, "_");
|
||||
found = treatedName.find(':');
|
||||
}
|
||||
found = treatedName.find('(');
|
||||
while (found != std::string::npos)
|
||||
{
|
||||
treatedName.replace(found, 1, "_");
|
||||
found = treatedName.find('(');
|
||||
}
|
||||
found = treatedName.find(')');
|
||||
while (found != std::string::npos)
|
||||
{
|
||||
treatedName.replace(found, 1, "_");
|
||||
found = treatedName.find(')');
|
||||
}
|
||||
|
||||
// Check for linked-list, we want to prevent very long names
|
||||
found = treatedName.rfind("AUTOLIST");
|
||||
if (found == std::string::npos)
|
||||
{
|
||||
found = treatedName.rfind("_0__");
|
||||
if (found != std::string::npos)
|
||||
{
|
||||
size_t newParamNamePos = found + 4;
|
||||
std::string newParamName = treatedName.substr(newParamNamePos);
|
||||
size_t remChars = treatedName.length() - newParamNamePos;
|
||||
if (remChars <= found)
|
||||
{
|
||||
std::string prevParamName = treatedName.substr(found - remChars, remChars);
|
||||
if (prevParamName.compare(newParamName) == 0)
|
||||
{
|
||||
treatedName = treatedName.substr(0, found);
|
||||
treatedName += "_AUTOLIST1";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t afterListPos = treatedName.rfind("_0__");
|
||||
std::stringstream iss(treatedName.substr(found + 8, afterListPos));
|
||||
int currIdx = 0;
|
||||
iss >> currIdx;
|
||||
++currIdx;
|
||||
iss.str("");
|
||||
iss << currIdx;
|
||||
treatedName = treatedName.substr(0, found + 8);
|
||||
treatedName += iss.str();
|
||||
}
|
||||
|
||||
return treatedName;
|
||||
}
|
||||
|
||||
bool updateAllocName(void * parentPtr, void * ptr, const std::string & name, const std::string & funcName,
|
||||
bool printError)
|
||||
{
|
||||
bool success = false;
|
||||
if (parentPtr != 0x0)
|
||||
{
|
||||
ALLOC_INFO * info = trick_MM->get_alloc_info_of(parentPtr);
|
||||
if (info != 0x0)
|
||||
{
|
||||
if (info->name != 0x0)
|
||||
{
|
||||
std::string pathName = trick_MM->ref_name_from_address(parentPtr);
|
||||
pathName = treatAllocName(pathName);
|
||||
std::stringstream ss;
|
||||
std::string treatedName = treatAllocName(name);
|
||||
ss << pathName << "_" << treatedName;
|
||||
trick_MM->set_name_at(ptr, ss.str().c_str());
|
||||
success = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (printError)
|
||||
{
|
||||
if (ptr == 0x0)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Could not name an allocation with name " << name << " because the allocated ptr is NULL. "
|
||||
<< "Allocation call invoked from " << funcName << std::endl;
|
||||
message_publish(1, ss.str().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Could not name the allocation at " << ptr << " because it's parent data structure at "
|
||||
<< parentPtr
|
||||
<< " has no name registered with Trick MemoryManager. Allocation call invoked from " << funcName
|
||||
<< std::endl;
|
||||
message_publish(1, ss.str().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (printError)
|
||||
{
|
||||
if (ptr == 0x0)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Could not name an allocation with name " << name << " because the allocated ptr is NULL. "
|
||||
<< "Allocation call invoked from " << funcName << std::endl;
|
||||
message_publish(1, ss.str().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Could not name the allocation at " << ptr << " because it's parent data structure at "
|
||||
<< parentPtr << " was not found by Trick MemoryManagerAllocation call invoked from " << funcName
|
||||
<< std::endl;
|
||||
message_publish(1, ss.str().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (printError)
|
||||
{
|
||||
if (ptr == 0x0)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Could not name an allocation with name " << name
|
||||
<< " because the parent and allocated pointers are NULL. " << "Allocation call invoked from "
|
||||
<< funcName << std::endl;
|
||||
message_publish(1, ss.str().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Could not name the allocation at " << ptr << " because it's parent pointer is NULL. "
|
||||
<< "Allocation call invoked from " << funcName << std::endl;
|
||||
message_publish(1, ss.str().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
#endif
|
||||
}
|
@ -1,472 +0,0 @@
|
||||
/*******************************************************************************
|
||||
|
||||
PURPOSE:
|
||||
(alloc template for allocating and reallocating elements.)
|
||||
|
||||
LIBRARY DEPENDENCY:
|
||||
((Alloc.cpp))
|
||||
|
||||
PROGRAMMERS:
|
||||
(((Thomas Brain) (Metecs) (May 2013) (--)))
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CHECKPOINTHELPER_alloc_HH_
|
||||
#define CHECKPOINTHELPER_alloc_HH_
|
||||
#if (defined TRICK_VER) && (TRICK_VER >= 10)
|
||||
#include "sim_services/MemoryManager/include/MemoryManager.hh"
|
||||
#include "sim_services/Message/include/message_proto.h"
|
||||
#endif
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include "Manager.hh"
|
||||
|
||||
namespace CheckpointHelper
|
||||
{
|
||||
|
||||
extern Manager * helperManager;
|
||||
|
||||
#if (defined TRICK_VER) && (TRICK_VER >= 10)
|
||||
typedef TRICK_TYPE MM_TYPE;
|
||||
|
||||
std::string treatAllocName(const std::string & nameIn);
|
||||
bool updateAllocName(void * parentPtr, void * ptr, const std::string & name, const std::string & funcName,
|
||||
bool printError);
|
||||
|
||||
template<class T>
|
||||
void delete_alloc(T ** x, const std::string & whereAt, bool external)
|
||||
{
|
||||
if (!external)
|
||||
{
|
||||
if (trick_MM->is_alloced(*x))
|
||||
{
|
||||
trick_MM->delete_var((void *) *x);
|
||||
if (helperManager != 0x0)
|
||||
{
|
||||
helperManager->removeConstructorAlloc(*x);
|
||||
}
|
||||
*x = 0x0;
|
||||
}
|
||||
else if (*x != 0x0)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "CheckpointHelper::delete_alloc ERROR attempting to delete ptr at " << whereAt
|
||||
<< " that is not allocated.\n";
|
||||
message_publish(MSG_WARNING, ss.str().c_str());
|
||||
*x = 0x0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (trick_MM->is_alloced(*x))
|
||||
{
|
||||
trick_MM->delete_extern_var((void *) *x);
|
||||
if (helperManager != 0x0)
|
||||
{
|
||||
helperManager->removeConstructorAlloc(*x);
|
||||
size_t numEntries = helperManager->getExternNum(*x);
|
||||
helperManager->removeExternAlloc(*x);
|
||||
for (int ii = numEntries - 1; ii >= 0; --ii)
|
||||
{
|
||||
(*x)[ii].~T();
|
||||
}
|
||||
free(*x);
|
||||
*x = 0x0;
|
||||
}
|
||||
}
|
||||
else if (*x != 0x0)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "CheckpointHelper::delete_alloc ERROR attempting to delete external ptr at " << whereAt
|
||||
<< " that is not allocated.\n";
|
||||
message_publish(MSG_WARNING, ss.str().c_str());
|
||||
*x = 0x0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class U, class T>
|
||||
void operatornew_alloc(void * parentPtr, T ** x, int n, const std::string & TYPE, const std::string & name,
|
||||
const std::string & funcNameIn)
|
||||
{
|
||||
if (n)
|
||||
{
|
||||
if (trick_MM->is_alloced(*x))
|
||||
{
|
||||
int orig_size = trick_MM->get_size((char *) *x);
|
||||
if (n > orig_size)
|
||||
{
|
||||
helperManager->removeConstructorAlloc(*x);
|
||||
*x = (U *) trick_MM->resize_array((void *) *x, n);
|
||||
helperManager->addConstructorAlloc(parentPtr, *x, name, funcNameIn);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ALLOC_INFO * info = trick_MM->get_alloc_info_of(x);
|
||||
if (info != 0x0)
|
||||
{
|
||||
if (info->name != 0x0)
|
||||
{
|
||||
*x = static_cast<U *>(trick_MM->declare_operatornew_var(TYPE, sizeof(U) * n, sizeof(U)));
|
||||
std::string pathName = trick_MM->ref_name_from_address(x);
|
||||
pathName = treatAllocName(pathName);
|
||||
trick_MM->set_name_at(*x, pathName.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
*x = static_cast<U *>(trick_MM->declare_operatornew_var(TYPE, sizeof(U) * n, sizeof(U)));
|
||||
if (helperManager != 0x0)
|
||||
{
|
||||
helperManager->addConstructorAlloc(parentPtr, *x, name, funcNameIn);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*x = static_cast<U *>(trick_MM->declare_operatornew_var(TYPE, sizeof(U) * n, sizeof(U)));
|
||||
if (helperManager != 0x0)
|
||||
{
|
||||
helperManager->addConstructorAlloc(parentPtr, *x, name, funcNameIn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
template<class U, class T>
|
||||
void alloc(void * parentPtr, T ** x, TRICK_TYPE type, const std::string & TYPE_NAME, int n_stars,
|
||||
const std::string & name, int n_cdims, int cdims[8], bool external, const std::string & funcNameIn)
|
||||
{
|
||||
if (cdims[0])
|
||||
{
|
||||
if (trick_MM->is_alloced(*x))
|
||||
{
|
||||
int orig_size = trick_MM->get_size((char *) *x);
|
||||
if (cdims[0] > orig_size)
|
||||
{
|
||||
helperManager->removeConstructorAlloc(*x);
|
||||
*x = (U *) trick_MM->resize_array((void *) *x, cdims[0]);
|
||||
helperManager->addConstructorAlloc(parentPtr, *x, name, funcNameIn);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ALLOC_INFO * info = trick_MM->get_alloc_info_of(x);
|
||||
if (info != 0x0)
|
||||
{
|
||||
if (info->name != 0x0)
|
||||
{
|
||||
std::string pathName = trick_MM->ref_name_from_address(x);
|
||||
pathName = treatAllocName(pathName);
|
||||
if (external)
|
||||
{
|
||||
if (*x == 0x0)
|
||||
{
|
||||
*x = reinterpret_cast<U *>(calloc(cdims[0], sizeof(U)));
|
||||
new (*x) U[cdims[0]]();
|
||||
if (helperManager != 0x0)
|
||||
{
|
||||
helperManager->addExternAlloc(*x, cdims[0]);
|
||||
}
|
||||
}
|
||||
trick_MM->declare_extern_var(*x, type, TYPE_NAME, n_stars, pathName, n_cdims, cdims);
|
||||
}
|
||||
else
|
||||
{
|
||||
*x = (U *) trick_MM->declare_var(type, TYPE_NAME, n_stars, pathName, n_cdims, cdims);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (external)
|
||||
{
|
||||
if (*x == 0x0)
|
||||
{
|
||||
*x = reinterpret_cast<U *>(calloc(cdims[0], sizeof(U)));
|
||||
new (*x) U[cdims[0]]();
|
||||
if (helperManager != 0x0)
|
||||
{
|
||||
helperManager->addExternAlloc(*x, cdims[0]);
|
||||
}
|
||||
}
|
||||
trick_MM->declare_extern_var(*x, type, TYPE_NAME, n_stars, "", n_cdims, cdims);
|
||||
}
|
||||
else
|
||||
{
|
||||
*x = (U *) trick_MM->declare_var(type, TYPE_NAME, n_stars, "", n_cdims, cdims);
|
||||
}
|
||||
if (helperManager != 0x0)
|
||||
{
|
||||
helperManager->addConstructorAlloc(parentPtr, *x, name, funcNameIn);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (external)
|
||||
{
|
||||
if (*x == 0x0)
|
||||
{
|
||||
*x = reinterpret_cast<U *>(calloc(cdims[0], sizeof(U)));
|
||||
new (*x) U[cdims[0]]();
|
||||
if (helperManager != 0x0)
|
||||
{
|
||||
helperManager->addExternAlloc(*x, cdims[0]);
|
||||
}
|
||||
}
|
||||
trick_MM->declare_extern_var(*x, type, TYPE_NAME, n_stars, "", n_cdims, cdims);
|
||||
}
|
||||
else
|
||||
{
|
||||
*x = (U *) trick_MM->declare_var(type, TYPE_NAME, n_stars, "", n_cdims, cdims);
|
||||
}
|
||||
if (helperManager != 0x0)
|
||||
{
|
||||
helperManager->addConstructorAlloc(parentPtr, *x, name, funcNameIn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
template<class U, class T>
|
||||
void alloc(void * parentPtr, T ** x, int n, const std::string & TYPE, const std::string & name, bool external,
|
||||
const std::string & funcNameIn)
|
||||
{
|
||||
int cdims[8] =
|
||||
{ n, 0, 0, 0, 0, 0, 0, 0 };
|
||||
std::string treatedTYPE = TYPE;
|
||||
size_t ret;
|
||||
while ((ret = treatedTYPE.find(' ')) != std::string::npos)
|
||||
{
|
||||
treatedTYPE.erase(ret);
|
||||
}
|
||||
while ((ret = treatedTYPE.find('*')) != std::string::npos)
|
||||
{
|
||||
treatedTYPE.erase(ret);
|
||||
}
|
||||
CheckpointHelper::alloc<U>(parentPtr, x, TRICK_OPAQUE_TYPE, treatedTYPE, 0, name, 1, cdims, external, funcNameIn);
|
||||
}
|
||||
|
||||
template<class U, class T>
|
||||
void alloc(void * parentPtr, T *** x, int n, const std::string & TYPE, const std::string & name, bool external,
|
||||
const std::string & funcNameIn)
|
||||
{
|
||||
int cdims[8] =
|
||||
{ n, 0, 0, 0, 0, 0, 0, 0 };
|
||||
std::string treatedTYPE = TYPE;
|
||||
size_t ret;
|
||||
while ((ret = treatedTYPE.find(' ')) != std::string::npos)
|
||||
{
|
||||
treatedTYPE.erase(ret);
|
||||
}
|
||||
while ((ret = treatedTYPE.find('*')) != std::string::npos)
|
||||
{
|
||||
treatedTYPE.erase(ret);
|
||||
}
|
||||
CheckpointHelper::alloc<U>(parentPtr, x, TRICK_OPAQUE_TYPE, treatedTYPE, 1, name, 1, cdims, external, funcNameIn);
|
||||
}
|
||||
|
||||
template<class U, class T>
|
||||
void alloc(void * parentPtr, T **** x, int n, const std::string & TYPE, const std::string & name, bool external,
|
||||
const std::string & funcNameIn)
|
||||
{
|
||||
int cdims[8] =
|
||||
{ n, 0, 0, 0, 0, 0, 0, 0 };
|
||||
std::string treatedTYPE = TYPE;
|
||||
size_t ret;
|
||||
while ((ret = treatedTYPE.find(' ')) != std::string::npos)
|
||||
{
|
||||
treatedTYPE.erase(ret);
|
||||
}
|
||||
while ((ret = treatedTYPE.find('*')) != std::string::npos)
|
||||
{
|
||||
treatedTYPE.erase(ret);
|
||||
}
|
||||
CheckpointHelper::alloc<U>(parentPtr, x, TRICK_OPAQUE_TYPE, treatedTYPE, 2, name, 1, cdims, external, funcNameIn);
|
||||
}
|
||||
|
||||
#define CHECKPOINTHELPER_PRIM_ALLOC_TEMPS( primType, trickType ) \
|
||||
template<> \
|
||||
inline void alloc<primType>(void * parentPtr, primType ** x, int n, const std::string & TYPE, const std::string & name, \
|
||||
bool external, const std::string & funcNameIn) \
|
||||
{ \
|
||||
int cdims[8] = { n, 0, 0, 0, 0, 0, 0, 0 }; \
|
||||
CheckpointHelper::alloc<primType>(parentPtr, x, trickType, "", 0, name, 1, cdims, external, funcNameIn); \
|
||||
} \
|
||||
\
|
||||
template<> \
|
||||
inline void alloc<primType *, primType>(void * parentPtr, primType *** x, int n, const std::string & TYPE, const std::string & name, \
|
||||
bool external, const std::string & funcNameIn) \
|
||||
{ \
|
||||
int cdims[8] = { n, 0, 0, 0, 0, 0, 0, 0 }; \
|
||||
CheckpointHelper::alloc<primType *>(parentPtr, x, trickType, "", 1, name, 1, cdims, external, funcNameIn); \
|
||||
} \
|
||||
\
|
||||
template<> \
|
||||
inline void alloc<primType **, primType>(void * parentPtr, primType **** x, int n, const std::string & TYPE, const std::string & name, \
|
||||
bool external, const std::string & funcNameIn) \
|
||||
{ \
|
||||
int cdims[8] = { n, 0, 0, 0, 0, 0, 0, 0 }; \
|
||||
CheckpointHelper::alloc<primType **>(parentPtr, x, trickType, "", 2, name, 1, cdims, external, funcNameIn); \
|
||||
}
|
||||
|
||||
CHECKPOINTHELPER_PRIM_ALLOC_TEMPS(double, TRICK_DOUBLE)
|
||||
CHECKPOINTHELPER_PRIM_ALLOC_TEMPS(char, TRICK_CHARACTER)
|
||||
CHECKPOINTHELPER_PRIM_ALLOC_TEMPS(unsigned char, TRICK_UNSIGNED_CHARACTER)
|
||||
CHECKPOINTHELPER_PRIM_ALLOC_TEMPS(std::string, TRICK_STRING)
|
||||
CHECKPOINTHELPER_PRIM_ALLOC_TEMPS(int, TRICK_INTEGER)
|
||||
CHECKPOINTHELPER_PRIM_ALLOC_TEMPS(unsigned int, TRICK_UNSIGNED_INTEGER)
|
||||
CHECKPOINTHELPER_PRIM_ALLOC_TEMPS(long, TRICK_LONG)
|
||||
CHECKPOINTHELPER_PRIM_ALLOC_TEMPS(unsigned long, TRICK_UNSIGNED_LONG)
|
||||
CHECKPOINTHELPER_PRIM_ALLOC_TEMPS(float, TRICK_FLOAT)
|
||||
CHECKPOINTHELPER_PRIM_ALLOC_TEMPS(long long, TRICK_LONG_LONG)
|
||||
CHECKPOINTHELPER_PRIM_ALLOC_TEMPS(unsigned long long, TRICK_UNSIGNED_LONG_LONG)
|
||||
CHECKPOINTHELPER_PRIM_ALLOC_TEMPS(bool, TRICK_BOOLEAN)
|
||||
CHECKPOINTHELPER_PRIM_ALLOC_TEMPS(wchar_t, TRICK_WCHAR)
|
||||
|
||||
#else
|
||||
|
||||
typedef int MM_TYPE;
|
||||
|
||||
template<class T>
|
||||
void alloc( void * parentPtr, T ** x, int n, std::string TYPE, std::string name )
|
||||
{
|
||||
(void) parentPtr;
|
||||
(void) x;
|
||||
(void) n;
|
||||
(void) TYPE;
|
||||
(void) name;
|
||||
|
||||
*x = new T[n];
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void delete_alloc(T ** x)
|
||||
{
|
||||
if (x != 0x0)
|
||||
{
|
||||
if(*x != 0x0)
|
||||
{
|
||||
delete[] *x;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CHECKPOINTHELPER_STRINGIFY
|
||||
#define CHECKPOINTHELPER_STRINGIFY(x) #x
|
||||
#endif
|
||||
#ifndef CHECKPOINTHELPER_TOSTRING
|
||||
#define CHECKPOINTHELPER_TOSTRING(x) CHECKPOINTHELPER_STRINGIFY(x)
|
||||
#endif
|
||||
|
||||
#ifndef CHECKPOINTHELPER_FILELINE
|
||||
#define CHECKPOINTHELPER_FILELINE __FILE__ ":" CHECKPOINTHELPER_TOSTRING(__LINE__)
|
||||
#endif
|
||||
|
||||
// get number of arguments with __NARG__
|
||||
#define __NARG__(...) __NARG_I_(__VA_ARGS__,__RSEQ_N())
|
||||
#define __NARG_I_(...) __ARG_N(__VA_ARGS__)
|
||||
#define __ARG_N( \
|
||||
_1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
|
||||
_11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
|
||||
_21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
|
||||
_31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
|
||||
_41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
|
||||
_51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
|
||||
_61,_62,_63,N,...) N
|
||||
#define __RSEQ_N() \
|
||||
63,62,61,60, \
|
||||
59,58,57,56,55,54,53,52,51,50, \
|
||||
49,48,47,46,45,44,43,42,41,40, \
|
||||
39,38,37,36,35,34,33,32,31,30, \
|
||||
29,28,27,26,25,24,23,22,21,20, \
|
||||
19,18,17,16,15,14,13,12,11,10, \
|
||||
9,8,7,6,5,4,3,2,1,0
|
||||
|
||||
// general definition for any function name
|
||||
#define _VFUNC_(name, n) name##n
|
||||
#define _VFUNC(name, n) _VFUNC_(name, n)
|
||||
#define VFUNC(func, ...) _VFUNC(func, __NARG__(__VA_ARGS__)) (__VA_ARGS__)
|
||||
|
||||
// definition our overloaded macros
|
||||
#define CHECKPOINTHELPER_ALLOC_WCSTR6(parent, item, num, type, name, cstr) \
|
||||
CheckpointHelper::operatornew_alloc<type>(parent, &item, num, #type, name, CHECKPOINTHELPER_FILELINE); \
|
||||
for(int ii = 0; ii < num; ++ii) { \
|
||||
new (&item[ii]) type cstr; \
|
||||
}
|
||||
|
||||
#define CHECKPOINTHELPER_ALLOC_WCSTR5(item, num, type, name, cstr) \
|
||||
CheckpointHelper::operatornew_alloc<type>(this, &item, num, #type, name, CHECKPOINTHELPER_FILELINE); \
|
||||
for(int ii = 0; ii < num; ++ii) { \
|
||||
new (&item[ii]) type cstr; \
|
||||
}
|
||||
|
||||
#define CHECKPOINTHELPER_ALLOC_WCSTR4(item, num, type, cstr) \
|
||||
CheckpointHelper::operatornew_alloc<type>(this, &item, num, #type, #item, CHECKPOINTHELPER_FILELINE); \
|
||||
for(int ii = 0; ii < num; ++ii) { \
|
||||
new (&item[ii]) type cstr; \
|
||||
}
|
||||
|
||||
#define CHECKPOINTHELPER_ALLOC_WCSTR3(item, type, cstr) \
|
||||
CheckpointHelper::operatornew_alloc<type>(this, &item, 1, #type, #item, CHECKPOINTHELPER_FILELINE); \
|
||||
new (item) type cstr;
|
||||
|
||||
#define CHECKPOINTHELPER_ALLOC5(parent, item, num, type, name) CheckpointHelper::alloc<type>(parent, &item, num, #type, name, false, CHECKPOINTHELPER_FILELINE)
|
||||
#define CHECKPOINTHELPER_ALLOC4(item, num, type, name) CheckpointHelper::alloc<type>(this, &item, num, #type, name, false, CHECKPOINTHELPER_FILELINE)
|
||||
#define CHECKPOINTHELPER_ALLOC3(item, num, type) CheckpointHelper::alloc<type>(this, &item, num, #type, #item, false, CHECKPOINTHELPER_FILELINE)
|
||||
#define CHECKPOINTHELPER_ALLOC2(item, type) CheckpointHelper::alloc<type>(this, &item, 1, #type, #item, false, CHECKPOINTHELPER_FILELINE)
|
||||
|
||||
#define CHECKPOINTHELPER_EXTERN_ALLOC_WCSTR6(parent, item, num, type, name, cstr) \
|
||||
item = reinterpret_cast<type *>(calloc(num, sizeof(type))); \
|
||||
for(int ii = 0; ii < num; ++ii) { \
|
||||
new (&item[ii]) type cstr; \
|
||||
} \
|
||||
CheckpointHelper::alloc<type>(parent, &item, num, #type, name, true, CHECKPOINTHELPER_FILELINE)
|
||||
|
||||
#define CHECKPOINTHELPER_EXTERN_ALLOC_WCSTR5(item, num, type, name, cstr) \
|
||||
item = reinterpret_cast<type *>(calloc(num, sizeof(type))); \
|
||||
for(int ii = 0; ii < num; ++ii) { \
|
||||
new (&item[ii]) type cstr; \
|
||||
} \
|
||||
CheckpointHelper::alloc<type>(this, &item, num, #type, name, true, CHECKPOINTHELPER_FILELINE)
|
||||
|
||||
#define CHECKPOINTHELPER_EXTERN_ALLOC_WCSTR4(item, num, type, cstr) \
|
||||
item = reinterpret_cast<type *>(calloc(num, sizeof(type))); \
|
||||
for(int ii = 0; ii < num; ++ii) { \
|
||||
new (&item[ii]) type cstr; \
|
||||
} \
|
||||
CheckpointHelper::alloc<type>(this, &item, num, #type, #item, true, CHECKPOINTHELPER_FILELINE)
|
||||
|
||||
#define CHECKPOINTHELPER_EXTERN_ALLOC_WCSTR3(item, type, cstr) \
|
||||
item = reinterpret_cast<type *>(calloc(1, sizeof(type))); \
|
||||
new (item) type cstr; \
|
||||
CheckpointHelper::alloc<type>(this, &item, 1, #type, #item, true, CHECKPOINTHELPER_FILELINE)
|
||||
|
||||
#define CHECKPOINTHELPER_EXTERN_ALLOC5(parent, item, num, type, name) CheckpointHelper::alloc<type>(parent, &item, num, #type, name, true, CHECKPOINTHELPER_FILELINE)
|
||||
#define CHECKPOINTHELPER_EXTERN_ALLOC4(item, num, type, name) CheckpointHelper::alloc<type>(this, &item, num, #type, name, true, CHECKPOINTHELPER_FILELINE)
|
||||
#define CHECKPOINTHELPER_EXTERN_ALLOC3(item, num, type) CheckpointHelper::alloc<type>(this, &item, num, #type, #item, true, CHECKPOINTHELPER_FILELINE)
|
||||
#define CHECKPOINTHELPER_EXTERN_ALLOC2(item, type) CheckpointHelper::alloc<type>(this, &item, 1, #type, #item, true, CHECKPOINTHELPER_FILELINE)
|
||||
|
||||
#define CHECKPOINTHELPER_ALLOC_WCSTR(...) VFUNC(CHECKPOINTHELPER_ALLOC_WCSTR, __VA_ARGS__)
|
||||
#define CHECKPOINTHELPER_ALLOC(...) VFUNC(CHECKPOINTHELPER_ALLOC, __VA_ARGS__)
|
||||
#define CHECKPOINTHELPER_EXTERN_ALLOC_WCSTR(...) VFUNC(CHECKPOINTHELPER_EXTERN_ALLOC_WCSTR, __VA_ARGS__)
|
||||
#define CHECKPOINTHELPER_EXTERN_ALLOC(...) VFUNC(CHECKPOINTHELPER_EXTERN_ALLOC, __VA_ARGS__)
|
||||
|
||||
#define CHECKPOINTHELPER_DELETE(item) CheckpointHelper::delete_alloc(&item, CHECKPOINTHELPER_FILELINE " " #item, false)
|
||||
#define CHECKPOINTHELPER_EXTERN_DELETE(item) CheckpointHelper::delete_alloc(&item, CHECKPOINTHELPER_FILELINE " " #item, true)
|
||||
|
||||
}
|
||||
|
||||
#endif /* STLHELPER_alloc_HH_ */
|
@ -1,24 +0,0 @@
|
||||
##include "er7_utils/CheckpointHelper/Manager.hh"
|
||||
##include "er7_utils/CheckpointHelper/CheckpointItem.hh"
|
||||
##include "er7_utils/CheckpointHelper/InputAllocsChkptRestart.hh"
|
||||
|
||||
class CheckpointHelperSimObject : public Trick::SimObject {
|
||||
public:
|
||||
CheckpointHelper::Manager manager;
|
||||
CheckpointHelper::InputAllocsChkptRestart inputAllocs;
|
||||
|
||||
CheckpointHelperSimObject() {
|
||||
P1 ("initialization") manager.processConstructorAllocs();
|
||||
|
||||
("checkpoint") manager.checkpoint();
|
||||
("checkpoint") inputAllocs.writeChkptFile();
|
||||
|
||||
P59000 ("preload_checkpoint") inputAllocs.loadChkptFile();
|
||||
("preload_checkpoint") manager.processConstructorAllocs();
|
||||
("restart") manager.restart();
|
||||
}
|
||||
};
|
||||
|
||||
CheckpointHelperSimObject checkpointHelper;
|
||||
|
||||
|
@ -1,39 +0,0 @@
|
||||
/*******************************************************************************
|
||||
|
||||
PURPOSE:
|
||||
(CheckpointItem is the abstract class to be used for automatic registration and
|
||||
checkpointing of items. This package provides STL container equivalents deriving
|
||||
from this classn.)
|
||||
|
||||
LIBRARY DEPENDENCY:
|
||||
((CheckpointItem.cpp)
|
||||
(Manager.cpp))
|
||||
|
||||
PROGRAMMERS:
|
||||
(((Thomas Brain) (Metecs) (May 2013) (--)))
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include "Manager.hh"
|
||||
#include "CheckpointItem.hh"
|
||||
|
||||
namespace CheckpointHelper
|
||||
{
|
||||
|
||||
CheckpointItem::CheckpointItem()
|
||||
{
|
||||
if (helperManager != NULL)
|
||||
{
|
||||
helperManager->addItem(*this);
|
||||
}
|
||||
}
|
||||
|
||||
CheckpointItem::~CheckpointItem()
|
||||
{
|
||||
if (helperManager != NULL)
|
||||
{
|
||||
helperManager->removeItem(*this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,287 +0,0 @@
|
||||
/*******************************************************************************
|
||||
|
||||
PURPOSE:
|
||||
(CheckpointItem is the abstract class to be used for automatic registration and
|
||||
checkpointing of items. This package provides STL container equivalents deriving
|
||||
from this classn.)
|
||||
|
||||
LIBRARY DEPENDENCY:
|
||||
((CheckpointItem.cpp))
|
||||
|
||||
PROGRAMMERS:
|
||||
(((Thomas Brain) (Metecs) (May 2013) (--)))
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CHECKPOINTHELPER_CHECKPOINTITEM_HH_
|
||||
#define CHECKPOINTHELPER_CHECKPOINTITEM_HH_
|
||||
|
||||
#include <queue>
|
||||
#include <stack>
|
||||
#include "Alloc.hh"
|
||||
|
||||
namespace CheckpointHelper
|
||||
{
|
||||
|
||||
class Manager;
|
||||
|
||||
extern Manager * helperManager;
|
||||
|
||||
class CheckpointItem
|
||||
{
|
||||
friend class InputProcessor;
|
||||
friend void init_attrCheckpointHelper__CheckpointItem();
|
||||
public:
|
||||
CheckpointItem();
|
||||
virtual ~CheckpointItem();
|
||||
|
||||
virtual void checkpoint() = 0;
|
||||
virtual void restart() = 0;
|
||||
};
|
||||
|
||||
#if (defined TRICK_VER) && (TRICK_VER >= 10)
|
||||
template<typename U, class V, class T>
|
||||
void chkpt_seq(T & obj)
|
||||
{
|
||||
int numObjs = obj.size();
|
||||
if (numObjs)
|
||||
{
|
||||
CheckpointHelper::alloc<V>(0x0, obj.chkpt, obj.size(), obj.mmstr, "", false, CHECKPOINTHELPER_FILELINE);
|
||||
int ii = 0;
|
||||
for (U it = obj.begin(), end = obj.end(); it != end; ++it, ++ii)
|
||||
{
|
||||
(*obj.chkpt)[ii] = *it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class V, class T>
|
||||
void chkpt_unsafevec(T & obj)
|
||||
{
|
||||
int numObjs = obj.size();
|
||||
if (numObjs)
|
||||
{
|
||||
CheckpointHelper::alloc<V>(0x0, obj.chkpt, obj.size(), obj.mmstr, "", false, CHECKPOINTHELPER_FILELINE);
|
||||
for (int ii = 0; ii != numObjs; ++ii)
|
||||
{
|
||||
(*obj.chkpt)[ii] = obj[ii];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename U, class T>
|
||||
void restart_seq(T & obj)
|
||||
{
|
||||
obj.clear();
|
||||
if ((*obj.chkpt) != NULL)
|
||||
{
|
||||
int numObjs = trick_MM->get_size((char *) (*obj.chkpt));
|
||||
for (int ii = 0; ii < numObjs; ++ii)
|
||||
{
|
||||
U it = obj.end();
|
||||
obj.insert(it, (*obj.chkpt)[ii]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void restart_unsafevec(T & obj)
|
||||
{
|
||||
obj.clear();
|
||||
if ((*obj.chkpt) != 0x0)
|
||||
{
|
||||
int numObjs = trick_MM->get_size((char *) (*obj.chkpt));
|
||||
for (int ii = 0; ii != numObjs; ++ii)
|
||||
{
|
||||
obj.addElement((*obj.chkpt)[ii]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename U, class V, class T>
|
||||
void chkpt_queue(T & obj)
|
||||
{
|
||||
U temp_queue(obj);
|
||||
int numObjs = temp_queue.size();
|
||||
if (numObjs)
|
||||
{
|
||||
CheckpointHelper::alloc<V>(0x0, obj.chkpt, temp_queue.size(), obj.mmstr, "", false, CHECKPOINTHELPER_FILELINE);
|
||||
for (int ii = 0, end = temp_queue.size(); ii != end; ++ii)
|
||||
{
|
||||
(*obj.chkpt)[ii] = temp_queue.front();
|
||||
temp_queue.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void restart_queue(T & obj)
|
||||
{
|
||||
while (!obj.empty())
|
||||
{
|
||||
obj.pop();
|
||||
}
|
||||
if ((*obj.chkpt) != NULL)
|
||||
{
|
||||
int numObjs = trick_MM->get_size((char *) (*obj.chkpt));
|
||||
for (int ii = 0; ii < numObjs; ++ii)
|
||||
{
|
||||
obj.push((*obj.chkpt)[ii]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename U, class V, class T>
|
||||
void chkpt_stack(T & obj)
|
||||
{
|
||||
U temp_stack(obj);
|
||||
int numObjs = temp_stack.size();
|
||||
if (numObjs)
|
||||
{
|
||||
CheckpointHelper::alloc<V>(0x0, obj.chkpt, temp_stack.size(), obj.mmstr, "", false, CHECKPOINTHELPER_FILELINE);
|
||||
for (int ii = 0, end = temp_stack.size(); ii != end; ++ii)
|
||||
{
|
||||
(*obj.chkpt)[ii] = temp_stack.top();
|
||||
temp_stack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void restart_stack(T & obj)
|
||||
{
|
||||
while (!obj.empty())
|
||||
{
|
||||
obj.pop();
|
||||
}
|
||||
if ((*obj.chkpt) != NULL)
|
||||
{
|
||||
int numObjs = trick_MM->get_size((char *) (*obj.chkpt));
|
||||
for (int ii = numObjs - 1; ii != -1; --ii)
|
||||
{
|
||||
obj.push((*obj.chkpt)[ii]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void chkpt_pair(T & obj)
|
||||
{
|
||||
(*obj.chkptFirst) = obj.first;
|
||||
(*obj.chkptSecond) = obj.second;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void restart_pair(T & obj)
|
||||
{
|
||||
obj.first = (*obj.chkptFirst);
|
||||
obj.second = (*obj.chkptSecond);
|
||||
}
|
||||
|
||||
template<typename U, class V, class X, class T>
|
||||
void chkpt_map(T &obj)
|
||||
{
|
||||
int numObjs = obj.size();
|
||||
if (numObjs)
|
||||
{
|
||||
CheckpointHelper::alloc<V>(0x0, obj.chkptKeys, obj.size(), obj.mmstrKey, "", false, CHECKPOINTHELPER_FILELINE);
|
||||
CheckpointHelper::alloc<X>(0x0, obj.chkptValues, obj.size(), obj.mmstrValue, "", false,
|
||||
CHECKPOINTHELPER_FILELINE);
|
||||
int ii = 0;
|
||||
for (U it = obj.begin(), end = obj.end(); it != end; ++it, ++ii)
|
||||
{
|
||||
(*obj.chkptKeys)[ii] = it->first;
|
||||
(*obj.chkptValues)[ii] = it->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename U, class T>
|
||||
void restart_map(T &obj)
|
||||
{
|
||||
obj.clear();
|
||||
if ((*obj.chkptKeys) != NULL)
|
||||
{
|
||||
int numObjs = trick_MM->get_size((char*) (*obj.chkptKeys));
|
||||
for (int ii = 0; ii < numObjs; ++ii)
|
||||
{
|
||||
obj.insert(std::make_pair((*obj.chkptKeys)[ii], (*obj.chkptValues)[ii]));
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
template<typename U, class V, class T>
|
||||
void chkpt_seq( T & obj )
|
||||
{
|
||||
(void) obj;
|
||||
}
|
||||
|
||||
template<class V, class T>
|
||||
void chkpt_unsafevec( T & obj )
|
||||
{
|
||||
(void) obj;
|
||||
}
|
||||
|
||||
template<typename U, class T>
|
||||
void restart_seq( T & obj )
|
||||
{
|
||||
(void) obj;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void restart_unsafevec( T & obj )
|
||||
{
|
||||
(void) obj;
|
||||
}
|
||||
|
||||
template<typename U, class V, class T>
|
||||
void chkpt_queue( T & obj )
|
||||
{
|
||||
(void) obj;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void restart_queue( T & obj )
|
||||
{
|
||||
(void) obj;
|
||||
}
|
||||
|
||||
template<typename U, class V, class T>
|
||||
void chkpt_stack( T & obj )
|
||||
{
|
||||
(void) obj;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void restart_stack( T & obj )
|
||||
{
|
||||
(void) obj;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void chkpt_pair( T & obj )
|
||||
{
|
||||
(void) obj;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void restart_pair( T & obj )
|
||||
{
|
||||
(void) obj;
|
||||
}
|
||||
|
||||
template<typename U, class V, class X, class T>
|
||||
void chkpt_map( T & obj )
|
||||
{
|
||||
(void) obj;
|
||||
}
|
||||
|
||||
template<typename U, class T>
|
||||
void restart_map( T &obj )
|
||||
{
|
||||
(void) obj;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* STLHELPER_STL_HH_ */
|
@ -1,78 +0,0 @@
|
||||
/*******************************************************************************
|
||||
|
||||
PURPOSE:
|
||||
(List for checkpointable deque container.)
|
||||
|
||||
PROGRAMMERS:
|
||||
(((Thomas Brain) (Metecs) (May 2013) (--)))
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CHECKPOINTHELPER_DEQUE_HH_
|
||||
#define CHECKPOINTHELPER_DEQUE_HH_
|
||||
|
||||
#include "CheckpointItem.hh"
|
||||
#include <deque>
|
||||
|
||||
namespace CheckpointHelper
|
||||
{
|
||||
|
||||
template<class T>
|
||||
class deque: public CheckpointItem, public std::deque<T>
|
||||
{
|
||||
public:
|
||||
T ** chkpt;
|
||||
std::string mmstr;
|
||||
|
||||
deque(T ** chkptIn, std::string mmstrIn) :
|
||||
chkpt(chkptIn), mmstr(mmstrIn)
|
||||
{
|
||||
*chkpt = 0x0;
|
||||
}
|
||||
|
||||
deque<T>& operator=(const std::deque<T>& pr)
|
||||
{
|
||||
std::deque<T>::operator=(pr);
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ~deque()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void checkpoint()
|
||||
{
|
||||
chkpt_seq<typename std::deque<T>::iterator, T>(*this);
|
||||
}
|
||||
virtual void restart()
|
||||
{
|
||||
restart_seq<typename std::deque<T>::iterator>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
#define STLDEQUE( type, varName ) \
|
||||
type* _##varName; \
|
||||
CheckpointHelper::deque<type> varName
|
||||
#else
|
||||
#define STLDEQUE( type, varName ) \
|
||||
type* _##varName
|
||||
#endif
|
||||
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
#ifndef STL_CSTR1
|
||||
#define STL_CSTR1( varName, type ) \
|
||||
varName( &_##varName, #type )
|
||||
#endif
|
||||
#else
|
||||
#ifndef STL_CSTR1
|
||||
#define STL_CSTR1( varName, type ) \
|
||||
_##varName()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define STLDEQUECSTR STL_CSTR1
|
||||
|
||||
#endif /* STLHELPER_DEQUE_HH_ */
|
@ -1,54 +0,0 @@
|
||||
/*******************************************************************************
|
||||
|
||||
PURPOSE:
|
||||
(DoublePtrCollect is a checkpointable dynamic collect to replace Trick's
|
||||
collect mechanism for collected "double *"'s.)
|
||||
|
||||
PROGRAMMERS:
|
||||
(((Thomas Brain) (Metecs) (Aug 2012) (--)))
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CHECKPOINTHELPER_CHECKPOINTABLECOLLECT_HH_
|
||||
#define CHECKPOINTHELPER_CHECKPOINTABLECOLLECT_HH_
|
||||
#include "Vector.hh"
|
||||
#include <algorithm>
|
||||
|
||||
namespace CheckpointHelper
|
||||
{
|
||||
|
||||
class DoublePtrCollect
|
||||
{
|
||||
public:
|
||||
DoublePtrCollect() : STLVECTORCSTR( collect, double *)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~DoublePtrCollect()
|
||||
{
|
||||
}
|
||||
|
||||
void add_collect(double * vIn)
|
||||
{
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
collect.push_back(vIn);
|
||||
#endif
|
||||
}
|
||||
|
||||
void remove_collect(double * vIn)
|
||||
{
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
std::vector<double *>::iterator it = std::find(collect.begin(), collect.end(), vIn);
|
||||
if (it != collect.end())
|
||||
{
|
||||
collect.erase(it);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
STLVECTOR( double *, collect);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* STLHELPER_CHECKPOINTABLECOLLECT_HH_ */
|
@ -1,65 +0,0 @@
|
||||
/*******************************************************************************
|
||||
|
||||
PURPOSE:
|
||||
(Jobs to call python routine to checkpoint/restart input file allocations.)
|
||||
|
||||
PROGRAMMERS:
|
||||
(((Thomas Brain) (Metecs) (March 2014) (--)))
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CHECKPOINTHELPER_INPUTALLOCSCHKPTRESTART_HH_
|
||||
#define CHECKPOINTHELPER_INPUTALLOCSCHKPTRESTART_HH_
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "sim_services/InputProcessor/include/InputProcessor.hh"
|
||||
#include "sim_services/CheckPointRestart/include/CheckPointRestart.hh"
|
||||
|
||||
extern Trick::InputProcessor * the_ip;
|
||||
extern Trick::CheckPointRestart * the_cpr;
|
||||
|
||||
namespace CheckpointHelper
|
||||
{
|
||||
|
||||
class InputAllocsChkptRestart
|
||||
{
|
||||
public:
|
||||
InputAllocsChkptRestart()
|
||||
{
|
||||
}
|
||||
virtual ~InputAllocsChkptRestart()
|
||||
{
|
||||
}
|
||||
|
||||
void writeChkptFile()
|
||||
{
|
||||
std::string cFile = the_cpr->get_output_file();
|
||||
cFile += "_inputAllocs.py";
|
||||
std::stringstream ss;
|
||||
ss << "if \"externAllocs\" in globals():" << std::endl;
|
||||
ss << " externAllocs.writeChkptFile(\"" << cFile << "\")" << std::endl;
|
||||
ss << " trick.message_publish(1, \"Dumped input allocations checkpoint " << cFile << ".\\n\")" << std::endl;
|
||||
ss << "else:" << std::endl;
|
||||
ss << " trick.message_publish(1, \"externAllocs not defined: skipping input allocations checkpoint\\n\")"
|
||||
<< std::endl;
|
||||
the_ip->parse(ss.str().c_str());
|
||||
}
|
||||
|
||||
void loadChkptFile()
|
||||
{
|
||||
std::string cFile = the_cpr->get_load_file();
|
||||
cFile += "_inputAllocs.py";
|
||||
std::stringstream ss;
|
||||
ss << "try:" << std::endl;
|
||||
ss << " execfile(\"" << cFile << "\")" << std::endl;
|
||||
ss << " trick.message_publish(1, \"Loaded " << cFile << " input allocations checkpoint.\\n\")" << std::endl;
|
||||
ss << "except IOError:" << std::endl;
|
||||
ss << " trick.message_publish(1, \"" << cFile << " was not found. Skipping input allocations restoration.\\n\")"
|
||||
<< std::endl;
|
||||
the_ip->parse(ss.str().c_str());
|
||||
}
|
||||
};
|
||||
|
||||
} /* namespace STLHelper */
|
||||
#endif /* STLHELPER_INPUTALLOCSCHKPTRESTART_HH_ */
|
@ -1,78 +0,0 @@
|
||||
/*******************************************************************************
|
||||
|
||||
PURPOSE:
|
||||
(List for checkpointable list container.)
|
||||
|
||||
PROGRAMMERS:
|
||||
(((Thomas Brain) (Metecs) (May 2013) (--)))
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CHECKPOINTHELPER_LIST_HH_
|
||||
#define CHECKPOINTHELPER_LIST_HH_
|
||||
|
||||
#include "CheckpointItem.hh"
|
||||
#include <list>
|
||||
|
||||
namespace CheckpointHelper
|
||||
{
|
||||
|
||||
template<class T>
|
||||
class list: public CheckpointItem, public std::list<T>
|
||||
{
|
||||
public:
|
||||
T ** chkpt;
|
||||
std::string mmstr;
|
||||
|
||||
list(T ** chkptIn, std::string mmstrIn) :
|
||||
chkpt(chkptIn), mmstr(mmstrIn)
|
||||
{
|
||||
*chkpt = 0x0;
|
||||
}
|
||||
|
||||
list<T>& operator=(const std::list<T>& pr)
|
||||
{
|
||||
std::list<T>::operator=(pr);
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ~list()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void checkpoint()
|
||||
{
|
||||
chkpt_seq<typename std::list<T>::iterator, T>(*this);
|
||||
}
|
||||
virtual void restart()
|
||||
{
|
||||
restart_seq<typename std::list<T>::iterator>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
#define STLLIST( type, varName ) \
|
||||
type* _##varName; \
|
||||
CheckpointHelper::list<type> varName
|
||||
#else
|
||||
#define STLLIST( type, varName ) \
|
||||
type* _##varName
|
||||
#endif
|
||||
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
#ifndef STL_CSTR1
|
||||
#define STL_CSTR1( varName, type ) \
|
||||
varName( &_##varName, #type )
|
||||
#endif
|
||||
#else
|
||||
#ifndef STL_CSTR1
|
||||
#define STL_CSTR1( varName, type ) \
|
||||
_##varName()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define STLLISTCSTR STL_CSTR1
|
||||
|
||||
#endif /* STLHELPER_LIST_HH_ */
|
@ -1,236 +0,0 @@
|
||||
/*******************************************************************************
|
||||
|
||||
PURPOSE:
|
||||
(Manager for globally calling checkpoint and restart methods of STLs)
|
||||
|
||||
LIBRARY DEPENDENCY:
|
||||
((Manager.cpp)
|
||||
(CheckpointItem.cpp))
|
||||
|
||||
PROGRAMMERS:
|
||||
(((Thomas Brain) (Metecs) (May 2013) (--)))
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include "Alloc.hh"
|
||||
#include "Manager.hh"
|
||||
#if (defined TRICK_VER) && (TRICK_VER >= 10)
|
||||
#include "sim_services/Message/include/message_proto.h"
|
||||
#endif
|
||||
#include "CheckpointItem.hh"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
namespace CheckpointHelper
|
||||
{
|
||||
|
||||
Manager * helperManager = 0x0;
|
||||
|
||||
Manager::Manager()
|
||||
{
|
||||
_checkpointObjects = NULL;
|
||||
if (helperManager == 0x0)
|
||||
{
|
||||
helperManager = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "WARNING: Only one instance of CheckpointHelper::Manager is allowed. Invalid Manager instance at "
|
||||
<< this << std::endl;
|
||||
}
|
||||
pthread_mutex_init(&allocQueueMutex, 0x0);
|
||||
pthread_mutex_init(&objListMutex, 0x0);
|
||||
pthread_mutex_init(&externMapMutex, 0x0);
|
||||
}
|
||||
|
||||
Manager::~Manager()
|
||||
{
|
||||
if (helperManager != 0x0)
|
||||
{
|
||||
helperManager = 0x0;
|
||||
}
|
||||
}
|
||||
#if (defined TRICK_VER) && (TRICK_VER >= 10)
|
||||
|
||||
void Manager::checkpoint()
|
||||
{
|
||||
processConstructorAllocs();
|
||||
pthread_mutex_lock(&objListMutex);
|
||||
int numObjs = checkpointObjects.size();
|
||||
if (numObjs)
|
||||
{
|
||||
alloc<CheckpointItem *>(this, &_checkpointObjects, numObjs, "CheckpointHelper::CheckpointItem", "", false,
|
||||
CHECKPOINTHELPER_FILELINE);
|
||||
int ii = 0;
|
||||
for (std::list<CheckpointItem *>::iterator it = checkpointObjects.begin(), end = checkpointObjects.end();
|
||||
it != end; ++it, ++ii)
|
||||
{
|
||||
CheckpointItem * item = *it;
|
||||
item->checkpoint();
|
||||
_checkpointObjects[ii] = item;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&objListMutex);
|
||||
}
|
||||
void Manager::restart()
|
||||
{
|
||||
pthread_mutex_lock(&allocQueueMutex);
|
||||
constructorAllocs.clear();
|
||||
pthread_mutex_unlock(&allocQueueMutex);
|
||||
pthread_mutex_lock(&objListMutex);
|
||||
checkpointObjects.clear();
|
||||
if (_checkpointObjects != NULL)
|
||||
{
|
||||
int numObjs = trick_MM->get_size((char *) _checkpointObjects);
|
||||
for (int ii = 0; ii < numObjs; ++ii)
|
||||
{
|
||||
CheckpointItem * item = _checkpointObjects[ii];
|
||||
checkpointObjects.push_back(_checkpointObjects[ii]);
|
||||
item->restart();
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&objListMutex);
|
||||
}
|
||||
|
||||
#else
|
||||
void Manager::checkpoint()
|
||||
{
|
||||
}
|
||||
void Manager::restart()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void Manager::addItem(CheckpointItem & stlIn)
|
||||
{
|
||||
pthread_mutex_lock(&objListMutex);
|
||||
std::list<CheckpointItem *>::iterator it = find(checkpointObjects.begin(), checkpointObjects.end(), &stlIn);
|
||||
if (it == checkpointObjects.end())
|
||||
{
|
||||
checkpointObjects.push_back(&stlIn);
|
||||
}
|
||||
pthread_mutex_unlock(&objListMutex);
|
||||
}
|
||||
|
||||
void Manager::removeItem(CheckpointItem & stlIn)
|
||||
{
|
||||
pthread_mutex_lock(&objListMutex);
|
||||
std::list<CheckpointItem *>::iterator it = find(checkpointObjects.begin(), checkpointObjects.end(), &stlIn);
|
||||
if (it != checkpointObjects.end())
|
||||
{
|
||||
checkpointObjects.erase(it);
|
||||
}
|
||||
pthread_mutex_unlock(&objListMutex);
|
||||
}
|
||||
|
||||
Manager::AllocEntry::AllocEntry(void * parentPtrIn, void * ptrIn, const std::string nameIn,
|
||||
const std::string funcNameIn) :
|
||||
parentPtr(parentPtrIn), ptr(ptrIn), name(nameIn), funcName(funcNameIn)
|
||||
{
|
||||
}
|
||||
|
||||
void Manager::addConstructorAlloc(void* parentPtr, void* ptr, const std::string name, const std::string funcNameIn)
|
||||
{
|
||||
pthread_mutex_lock(&allocQueueMutex);
|
||||
constructorAllocs.push_back(AllocEntry(parentPtr, ptr, name, funcNameIn));
|
||||
pthread_mutex_unlock(&allocQueueMutex);
|
||||
}
|
||||
|
||||
void Manager::removeConstructorAlloc(void * ptrIn)
|
||||
{
|
||||
pthread_mutex_lock(&allocQueueMutex);
|
||||
std::deque<AllocEntry>::iterator it = std::find(constructorAllocs.begin(), constructorAllocs.end(), ptrIn);
|
||||
if (it != constructorAllocs.end())
|
||||
{
|
||||
constructorAllocs.erase(it);
|
||||
}
|
||||
pthread_mutex_unlock(&allocQueueMutex);
|
||||
}
|
||||
|
||||
void Manager::processConstructorAllocs()
|
||||
{
|
||||
pthread_mutex_lock(&allocQueueMutex);
|
||||
std::deque<AllocEntry> preQueue;
|
||||
std::deque<AllocEntry> postQueue;
|
||||
while (!constructorAllocs.empty())
|
||||
{
|
||||
#if (defined TRICK_VER) && (TRICK_VER >= 10)
|
||||
AllocEntry & entry = constructorAllocs.front();
|
||||
|
||||
if (!updateAllocName(entry.parentPtr, entry.ptr, entry.name, entry.funcName, false))
|
||||
{
|
||||
postQueue.push_back(AllocEntry(entry.parentPtr, entry.ptr, entry.name, entry.funcName));
|
||||
}
|
||||
#endif
|
||||
constructorAllocs.pop_front();
|
||||
}
|
||||
pthread_mutex_unlock(&allocQueueMutex);
|
||||
|
||||
size_t preSize = preQueue.size();
|
||||
size_t postSize = postQueue.size();
|
||||
|
||||
while (preSize != postSize)
|
||||
{
|
||||
preQueue = postQueue;
|
||||
preSize = preQueue.size();
|
||||
postQueue.clear();
|
||||
while (!preQueue.empty())
|
||||
{
|
||||
#if (defined TRICK_VER) && (TRICK_VER >= 10)
|
||||
AllocEntry & entry = preQueue.front();
|
||||
|
||||
if (!updateAllocName(entry.parentPtr, entry.ptr, entry.name, entry.funcName, false))
|
||||
{
|
||||
postQueue.push_back(AllocEntry(entry.parentPtr, entry.ptr, entry.name, entry.funcName));
|
||||
}
|
||||
#endif
|
||||
preQueue.pop_front();
|
||||
}
|
||||
postSize = postQueue.size();
|
||||
}
|
||||
|
||||
while (!postQueue.empty())
|
||||
{
|
||||
#if (defined TRICK_VER) && (TRICK_VER >= 10)
|
||||
AllocEntry & entry = postQueue.front();
|
||||
|
||||
updateAllocName(entry.parentPtr, entry.ptr, entry.name, entry.funcName, true);
|
||||
#endif
|
||||
postQueue.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
void Manager::addExternAlloc(void* ptr, size_t numElems)
|
||||
{
|
||||
pthread_mutex_lock(&externMapMutex);
|
||||
externMemAllocs[ptr] = numElems;
|
||||
pthread_mutex_unlock(&externMapMutex);
|
||||
}
|
||||
|
||||
void Manager::removeExternAlloc(void* ptr)
|
||||
{
|
||||
pthread_mutex_lock(&externMapMutex);
|
||||
externMemAllocs.erase(ptr);
|
||||
pthread_mutex_unlock(&externMapMutex);
|
||||
}
|
||||
|
||||
size_t Manager::getExternNum(void* ptr)
|
||||
{
|
||||
pthread_mutex_lock(&externMapMutex);
|
||||
size_t num;
|
||||
std::map<void *, size_t>::iterator it = externMemAllocs.find(ptr);
|
||||
if (it != externMemAllocs.end())
|
||||
{
|
||||
num = it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
num = 0;
|
||||
}
|
||||
pthread_mutex_unlock(&externMapMutex);
|
||||
return num;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,78 +0,0 @@
|
||||
/*******************************************************************************
|
||||
|
||||
PURPOSE:
|
||||
(Manager for globally calling checkpoint and restart methods of STLs)
|
||||
|
||||
LIBRARY DEPENDENCY:
|
||||
((Manager.cpp))
|
||||
|
||||
PROGRAMMERS:
|
||||
(((Thomas Brain) (Metecs) (May 2013) (--)))
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CHECKPOINTHELPER_MANAGER_HH_
|
||||
#define CHECKPOINTHELPER_MANAGER_HH_
|
||||
|
||||
#include <deque>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <pthread.h>
|
||||
|
||||
namespace CheckpointHelper
|
||||
{
|
||||
|
||||
class CheckpointItem;
|
||||
|
||||
class Manager
|
||||
{
|
||||
friend class InputProcessor;
|
||||
friend void init_attrCheckpointHelper__Manager();
|
||||
public:
|
||||
Manager();
|
||||
virtual ~Manager();
|
||||
|
||||
class AllocEntry
|
||||
{
|
||||
public:
|
||||
AllocEntry(void * parentPtrIn, void * ptrIn, const std::string nameIn, const std::string funcNameIn);
|
||||
void * parentPtr;
|
||||
void * ptr;
|
||||
std::string name;
|
||||
std::string funcName;
|
||||
|
||||
bool operator==(void * ptrComp)
|
||||
{
|
||||
return this->ptr == ptrComp;
|
||||
}
|
||||
};
|
||||
|
||||
void addConstructorAlloc(void * parentPtr, void * ptr, const std::string name, const std::string funcNameIn);
|
||||
void removeConstructorAlloc(void * ptr);
|
||||
void processConstructorAllocs();
|
||||
|
||||
void checkpoint();
|
||||
void restart();
|
||||
|
||||
void addItem(CheckpointItem & stlIn);
|
||||
void removeItem(CheckpointItem & stlIn);
|
||||
|
||||
void addExternAlloc(void * ptr, size_t numElems);
|
||||
void removeExternAlloc(void * ptr);
|
||||
size_t getExternNum(void * ptr);
|
||||
|
||||
protected:
|
||||
std::list<CheckpointItem *> checkpointObjects;
|
||||
CheckpointItem ** _checkpointObjects;
|
||||
std::deque<AllocEntry> constructorAllocs;
|
||||
pthread_mutex_t allocQueueMutex; /* ** Do not checkpoint */
|
||||
pthread_mutex_t objListMutex; /* ** Do not checkpoint */
|
||||
pthread_mutex_t externMapMutex; /* ** Do not checkpoint */
|
||||
std::map<void *, size_t> externMemAllocs;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* STLHELPER_MANAGER_HH_ */
|
@ -1,121 +0,0 @@
|
||||
/*******************************************************************************
|
||||
|
||||
PURPOSE:
|
||||
(Map for checkpointable map container.)
|
||||
|
||||
PROGRAMMERS:
|
||||
(((Thomas Brain) (Metecs) (May 2013) (--)))
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CHECKPOINTHELPER_MAP_HH_
|
||||
#define CHECKPOINTHELPER_MAP_HH_
|
||||
|
||||
#include "CheckpointItem.hh"
|
||||
#include <map>
|
||||
|
||||
namespace CheckpointHelper
|
||||
{
|
||||
|
||||
template<class T, class U>
|
||||
class map: public CheckpointItem, public std::map<T, U>
|
||||
{
|
||||
public:
|
||||
T ** chkptKeys;
|
||||
U ** chkptValues;
|
||||
std::string mmstrKey;
|
||||
std::string mmstrValue;
|
||||
|
||||
map(T ** chkptKeysIn, U **chkptValuesIn, std::string mmstrKeyIn, std::string mmstrValueIn) :
|
||||
chkptKeys(chkptKeysIn), chkptValues(chkptValuesIn), mmstrKey(mmstrKeyIn), mmstrValue(mmstrValueIn)
|
||||
{
|
||||
*chkptKeys = 0x0;
|
||||
*chkptValues = 0x0;
|
||||
}
|
||||
|
||||
map<T, U>& operator=(const std::map<T, U>& pr)
|
||||
{
|
||||
std::map<T, U>::operator=(pr);
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ~map()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void checkpoint()
|
||||
{
|
||||
chkpt_map<typename std::map<T, U>::iterator, T, U>(*this);
|
||||
}
|
||||
virtual void restart()
|
||||
{
|
||||
restart_map<typename std::map<T, U>::iterator>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, class U>
|
||||
class multimap: public CheckpointHelper::CheckpointItem, public std::multimap<T, U>
|
||||
{
|
||||
public:
|
||||
T ** chkptKeys;
|
||||
U ** chkptValues;
|
||||
std::string mmstrKey;
|
||||
std::string mmstrValue;
|
||||
|
||||
multimap(T ** chkptKeysIn, U **chkptValuesIn, std::string mmstrKeyIn, std::string mmstrValueIn) :
|
||||
chkptKeys(chkptKeysIn), chkptValues(chkptValuesIn), mmstrKey(mmstrKeyIn), mmstrValue(mmstrValueIn)
|
||||
{
|
||||
*chkptKeys = 0x0;
|
||||
*chkptValues = 0x0;
|
||||
}
|
||||
|
||||
virtual ~multimap()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void checkpoint()
|
||||
{
|
||||
chkpt_map<typename std::multimap<T, U>::iterator, T, U>(*this);
|
||||
}
|
||||
virtual void restart()
|
||||
{
|
||||
restart_map<typename std::multimap<T, U>::iterator>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
#define STLMAP( type1, type2, varName ) \
|
||||
type1* _##varName##T1; \
|
||||
type2* _##varName##T2; \
|
||||
CheckpointHelper::map<type1, type2> varName
|
||||
#define STLMULTIMAP( type1, type2, varName ) \
|
||||
type1* _##varName##T1; \
|
||||
type2* _##varName##T2; \
|
||||
CheckpointHelper::multimap<type1, type2> varName
|
||||
#else
|
||||
#define STLMAP( type1, type2, varName ) \
|
||||
type1* _##varName##T1; \
|
||||
type2* _##varName##T2;
|
||||
#define STLMULTIMAP( type1, type2, varName ) \
|
||||
type1* _##varName##T1; \
|
||||
type2* _##varName##T2;
|
||||
#endif
|
||||
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
#ifndef STL_CSTR2
|
||||
#define STL_CSTR2( varName, type1, type2 ) \
|
||||
varName( &_##varName##T1, &_##varName##T2, #type1, #type2 )
|
||||
#endif
|
||||
#else
|
||||
#ifndef STL_CSTR2
|
||||
#define STL_CSTR2( varName, type1, type2 ) \
|
||||
_##varName##T1(), _##varName##T2()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define STLMAPCSTR STL_CSTR2
|
||||
#define STLMULTIMAPCSTR STL_CSTR2
|
||||
|
||||
#endif /* STLHELPER_MAP_HH_ */
|
@ -1,83 +0,0 @@
|
||||
/*******************************************************************************
|
||||
|
||||
PURPOSE:
|
||||
(Pair for checkpointable pair container.)
|
||||
|
||||
PROGRAMMERS:
|
||||
(((Thomas Brain) (Metecs) (May 2013) (--)))
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CHECKPOINTHELPER_PAIR_HH_
|
||||
#define CHECKPOINTHELPER_PAIR_HH_
|
||||
|
||||
#include "CheckpointItem.hh"
|
||||
#include <utility>
|
||||
|
||||
namespace CheckpointHelper
|
||||
{
|
||||
|
||||
template<class T, class U>
|
||||
class pair: public CheckpointItem, public std::pair<T, U>
|
||||
{
|
||||
public:
|
||||
T * chkptFirst;
|
||||
U * chkptSecond;
|
||||
std::string mmstrKey;
|
||||
std::string mmstrValue;
|
||||
|
||||
pair(T * chkptKeysIn, U * chkptValuesIn, std::string mmstrKeyIn, std::string mmstrValueIn) :
|
||||
chkptFirst(chkptKeysIn), chkptSecond(chkptValuesIn), mmstrKey(mmstrKeyIn), mmstrValue(mmstrValueIn)
|
||||
{
|
||||
*chkptFirst = 0x0;
|
||||
*chkptSecond = 0x0;
|
||||
}
|
||||
|
||||
pair<T, U>& operator=(const std::pair<T, U>& pr)
|
||||
{
|
||||
std::pair<T, U>::operator=(pr);
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ~pair()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void checkpoint()
|
||||
{
|
||||
chkpt_pair(*this);
|
||||
}
|
||||
virtual void restart()
|
||||
{
|
||||
restart_pair(*this);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
#define STLPAIR( type1, type2, varName ) \
|
||||
type1 _##varName##T1; \
|
||||
type2 _##varName##T2; \
|
||||
CheckpointHelper::pair<type1, type2> varName
|
||||
#else
|
||||
#define STLPAIR( type1, type2, varName ) \
|
||||
type1 _##varName##T1; \
|
||||
type2 _##varName##T2;
|
||||
#endif
|
||||
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
#ifndef STL_CSTR2
|
||||
#define STL_CSTR2( varName, type1, type2 ) \
|
||||
varName( &_##varName##T1, &_##varName##T2, #type1, #type2 )
|
||||
#endif
|
||||
#else
|
||||
#ifndef STL_CSTR2
|
||||
#define STL_CSTR2( varName, type1, type2 ) \
|
||||
_##varName##T1(), _##varName##T2()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define STLPAIRCSTR STL_CSTR2
|
||||
|
||||
#endif /* STLHELPER_PAIR_HH_ */
|
@ -1,78 +0,0 @@
|
||||
/*******************************************************************************
|
||||
|
||||
PURPOSE:
|
||||
(Queue for checkpointable queue container.)
|
||||
|
||||
PROGRAMMERS:
|
||||
(((Thomas Brain) (Metecs) (May 2013) (--)))
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CHECKPOINTHELPER_QUEUE_HH_
|
||||
#define CHECKPOINTHELPER_QUEUE_HH_
|
||||
|
||||
#include "CheckpointItem.hh"
|
||||
#include <queue>
|
||||
|
||||
namespace CheckpointHelper
|
||||
{
|
||||
|
||||
template<class T>
|
||||
class queue: public CheckpointItem, public std::queue<T>
|
||||
{
|
||||
public:
|
||||
T ** chkpt;
|
||||
std::string mmstr;
|
||||
|
||||
queue(T ** chkptIn, std::string mmstrIn) :
|
||||
chkpt(chkptIn), mmstr(mmstrIn)
|
||||
{
|
||||
*chkpt = 0x0;
|
||||
}
|
||||
|
||||
queue<T>& operator=(const std::queue<T>& pr)
|
||||
{
|
||||
std::queue<T>::operator=(pr);
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ~queue()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void checkpoint()
|
||||
{
|
||||
chkpt_queue<typename std::queue<T>, T>(*this);
|
||||
}
|
||||
virtual void restart()
|
||||
{
|
||||
restart_queue(*this);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
#define STLQUEUE( type, varName ) \
|
||||
type* _##varName; \
|
||||
CheckpointHelper::queue<type> varName
|
||||
#else
|
||||
#define STLQUEUE( type, varName ) \
|
||||
type* _##varName
|
||||
#endif
|
||||
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
#ifndef STL_CSTR1
|
||||
#define STL_CSTR1( varName, type ) \
|
||||
varName( &_##varName, #type )
|
||||
#endif
|
||||
#else
|
||||
#ifndef STL_CSTR1
|
||||
#define STL_CSTR1( varName, type ) \
|
||||
_##varName()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define STLQUEUECSTR STL_CSTR1
|
||||
|
||||
#endif /* STLHELPER_QUEUE_HH_ */
|
@ -1,117 +0,0 @@
|
||||
/*******************************************************************************
|
||||
|
||||
PURPOSE:
|
||||
(Set for checkpointable set container.)
|
||||
|
||||
PROGRAMMERS:
|
||||
(((Thomas Brain) (Metecs) (May 2013) (--)))
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CHECKPOINTHELPER_SET_HH_
|
||||
#define CHECKPOINTHELPER_SET_HH_
|
||||
|
||||
#include "CheckpointItem.hh"
|
||||
#include <set>
|
||||
|
||||
namespace CheckpointHelper
|
||||
{
|
||||
|
||||
template<class T>
|
||||
class set: public CheckpointItem, public std::set<T>
|
||||
{
|
||||
public:
|
||||
T ** chkpt;
|
||||
std::string mmstr;
|
||||
|
||||
set(T ** chkptIn, std::string mmstrIn) :
|
||||
chkpt(chkptIn), mmstr(mmstrIn)
|
||||
{
|
||||
*chkpt = 0x0;
|
||||
}
|
||||
|
||||
set<T>& operator=(const std::set<T>& pr)
|
||||
{
|
||||
std::set<T>::operator=(pr);
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ~set()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void checkpoint()
|
||||
{
|
||||
chkpt_seq<typename std::set<T>::iterator, T>(*this);
|
||||
}
|
||||
virtual void restart()
|
||||
{
|
||||
restart_seq<typename std::set<T>::iterator>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class multiset: public CheckpointHelper::CheckpointItem, public std::multiset<T>
|
||||
{
|
||||
public:
|
||||
T ** chkpt;
|
||||
std::string mmstr;
|
||||
|
||||
multiset(T ** chkptIn, std::string mmstrIn) :
|
||||
chkpt(chkptIn), mmstr(mmstrIn)
|
||||
{
|
||||
*chkpt = 0x0;
|
||||
}
|
||||
|
||||
multiset<T>& operator=(const std::multiset<T>& pr)
|
||||
{
|
||||
std::multiset<T>::operator=(pr);
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ~multiset()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void checkpoint()
|
||||
{
|
||||
chkpt_seq<typename std::multiset<T>::iterator, T>(*this);
|
||||
}
|
||||
virtual void restart()
|
||||
{
|
||||
restart_seq<typename std::multiset<T>::iterator>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
#define STLSET( type, varName ) \
|
||||
type* _##varName; \
|
||||
CheckpointHelper::set<type> varName
|
||||
#define STLMULTISET( type, varName ) \
|
||||
type* _##varName; \
|
||||
CheckpointHelper::multiset<type> varName
|
||||
#else
|
||||
#define STLSET( type, varName ) \
|
||||
type* _##varName
|
||||
#define STLMULTISET( type, varName ) \
|
||||
type* _##varName;
|
||||
#endif
|
||||
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
#ifndef STL_CSTR1
|
||||
#define STL_CSTR1( varName, type ) \
|
||||
varName( &_##varName, #type )
|
||||
#endif
|
||||
#else
|
||||
#ifndef STL_CSTR1
|
||||
#define STL_CSTR1( varName, type ) \
|
||||
_##varName()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define STLSETCSTR STL_CSTR1
|
||||
#define STLMULTISETCSTR STL_CSTR1
|
||||
|
||||
#endif /* STLHELPER_SET_HH_ */
|
@ -1,78 +0,0 @@
|
||||
/*******************************************************************************
|
||||
|
||||
PURPOSE:
|
||||
(Stack for checkpointable stack container.)
|
||||
|
||||
PROGRAMMERS:
|
||||
(((Thomas Brain) (Metecs) (May 2013) (--)))
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CHECKPOINTHELPER_STACK_HH_
|
||||
#define CHECKPOINTHELPER_STACK_HH_
|
||||
|
||||
#include "CheckpointItem.hh"
|
||||
#include <stack>
|
||||
|
||||
namespace CheckpointHelper
|
||||
{
|
||||
|
||||
template<class T>
|
||||
class stack: public CheckpointItem, public std::stack<T>
|
||||
{
|
||||
public:
|
||||
T ** chkpt;
|
||||
std::string mmstr;
|
||||
|
||||
stack(T ** chkptIn, std::string mmstrIn) :
|
||||
chkpt(chkptIn), mmstr(mmstrIn)
|
||||
{
|
||||
*chkpt = 0x0;
|
||||
}
|
||||
|
||||
stack<T>& operator=(const std::stack<T>& pr)
|
||||
{
|
||||
std::stack<T>::operator=(pr);
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ~stack()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void checkpoint()
|
||||
{
|
||||
chkpt_stack<typename std::stack<T>, T>(*this);
|
||||
}
|
||||
virtual void restart()
|
||||
{
|
||||
restart_stack(*this);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
#define STLSTACK( type, varName ) \
|
||||
type* _##varName; \
|
||||
CheckpointHelper::stack<type> varName
|
||||
#else
|
||||
#define STLSTACK( type, varName ) \
|
||||
type* _##varName
|
||||
#endif
|
||||
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
#ifndef STL_CSTR1
|
||||
#define STL_CSTR1( varName, type ) \
|
||||
varName( &_##varName, #type )
|
||||
#endif
|
||||
#else
|
||||
#ifndef STL_CSTR1
|
||||
#define STL_CSTR1( varName, type ) \
|
||||
_##varName()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define STLSTACKCSTR STL_CSTR1
|
||||
|
||||
#endif /* STLHELPER_STACK_HH_ */
|
@ -1,83 +0,0 @@
|
||||
/*******************************************************************************
|
||||
|
||||
PURPOSE:
|
||||
(Definition of Unsafevector container class. Minimal protections and
|
||||
forced-inlining for this container to acheive maximum performance..)
|
||||
|
||||
PROGRAMMERS:
|
||||
(((Thomas Brain) (Metecs) (Apr 2014) (--)))
|
||||
|
||||
ICG:(No.)
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CHECKPOINTHELPER_UNSAFECHKPTVECTOR_HH_
|
||||
#define CHECKPOINTHELPER_UNSAFECHKPTVECTOR_HH_
|
||||
#include "Unsafevector.hh"
|
||||
#include "CheckpointItem.hh"
|
||||
|
||||
#define stlhelper_inline inline __attribute__((always_inline))
|
||||
#define stlhelper_force_optimize __attribute__((optimize("-O3")))
|
||||
|
||||
//#define stlhelper_inline inline
|
||||
//#define stlhelper_force_optimize
|
||||
|
||||
namespace CheckpointHelper
|
||||
{
|
||||
|
||||
template<class T>
|
||||
class UnsafeChkptVector: public Unsafevector<T>, public CheckpointItem
|
||||
{
|
||||
public:
|
||||
T ** chkpt;
|
||||
std::string mmstr;
|
||||
|
||||
stlhelper_inline UnsafeChkptVector(T ** chkptIn, std::string mmstrIn) :
|
||||
chkpt(chkptIn), mmstr(mmstrIn)
|
||||
{
|
||||
*chkpt = 0x0;
|
||||
}
|
||||
|
||||
stlhelper_inline UnsafeChkptVector(const UnsafeChkptVector<T> & other) :
|
||||
Unsafevector<T>(other), chkpt(other.chkpt), mmstr(other.mmstrIn)
|
||||
{
|
||||
*chkpt = 0x0;
|
||||
}
|
||||
|
||||
virtual void checkpoint()
|
||||
{
|
||||
chkpt_unsafevec<T>(*this);
|
||||
}
|
||||
|
||||
virtual void restart()
|
||||
{
|
||||
restart_unsafevec(*this);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
#define STLUNSAFECHKPTVECTOR( type, varName ) \
|
||||
type* _##varName; \
|
||||
CheckpointHelper::UnsafeChkptVector<type> varName
|
||||
#else
|
||||
#define STLUNSAFECHKPTVECTOR( type, varName ) \
|
||||
type* _##varName
|
||||
#endif
|
||||
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
#ifndef STL_CSTR1
|
||||
#define STL_CSTR1( varName, type ) \
|
||||
varName( &_##varName, #type )
|
||||
#endif
|
||||
#else
|
||||
#ifndef STL_CSTR1
|
||||
#define STL_CSTR1( varName, type ) \
|
||||
_##varName()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define STLUNSAFECHKPTVECTORCSTR STL_CSTR1
|
||||
|
||||
#endif /* UNSAFEVECTOR_HH_ */
|
@ -1,173 +0,0 @@
|
||||
/*******************************************************************************
|
||||
|
||||
PURPOSE:
|
||||
(Definition of Unsafemap container class. Minimal protections and
|
||||
forced-inlining for this container to acheive maximum performance..)
|
||||
|
||||
PROGRAMMERS:
|
||||
(((Thomas Brain) (Metecs) (Apr 2014) (--)))
|
||||
|
||||
ICG:(No.)
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CHECKPOINTHELPER_UNSAFEMAP_HH_
|
||||
#define CHECKPOINTHELPER_UNSAFEMAP_HH_
|
||||
#include <stdlib.h>
|
||||
#include "Unsafevector.hh"
|
||||
|
||||
namespace CheckpointHelper
|
||||
{
|
||||
|
||||
template<class U, class T>
|
||||
class Unsafemap
|
||||
{
|
||||
public:
|
||||
stlhelper_inline Unsafemap()
|
||||
{
|
||||
}
|
||||
|
||||
stlhelper_inline ~Unsafemap()
|
||||
{
|
||||
int vsize = m.size();
|
||||
for (int ii = 0; ii < vsize; ++ii)
|
||||
{
|
||||
internal * it = m[ii];
|
||||
delete it;
|
||||
}
|
||||
}
|
||||
|
||||
class internal
|
||||
{
|
||||
public:
|
||||
stlhelper_inline internal() :
|
||||
first(), second()
|
||||
{
|
||||
}
|
||||
stlhelper_inline internal(const U & firstIn) :
|
||||
first(firstIn), second()
|
||||
{
|
||||
}
|
||||
|
||||
U first;
|
||||
T second;
|
||||
};
|
||||
|
||||
Unsafevector<internal *> m;
|
||||
|
||||
stlhelper_inline static int comparekeys(const void * a, const void * b)
|
||||
{
|
||||
U & key = *((U*) a);
|
||||
internal * bPtr = *((internal **) b);
|
||||
if (key < bPtr->first)
|
||||
return -1;
|
||||
if (key == bPtr->first)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
stlhelper_inline static int compareelems(const void * a, const void * b)
|
||||
{
|
||||
internal * aPtr = *((internal **) a);
|
||||
internal * bPtr = *((internal **) b);
|
||||
if (aPtr->first < bPtr->first)
|
||||
return -1;
|
||||
if (aPtr->first == bPtr->first)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
stlhelper_inline int size()
|
||||
{
|
||||
return m.size();
|
||||
}
|
||||
|
||||
stlhelper_inline void clear()
|
||||
{
|
||||
for (int ii = 0, end = m.size(); ii != end; ++ii)
|
||||
{
|
||||
internal * Elem = m[ii];
|
||||
delete Elem;
|
||||
}
|
||||
m.clear();
|
||||
}
|
||||
|
||||
stlhelper_inline T & getElement(int idx)
|
||||
{
|
||||
return m.v[idx]->second;
|
||||
}
|
||||
|
||||
#define compareKeys (int (*)( const void *, const void * )) Unsafemap<U, T>::comparekeys
|
||||
#define compareElems (int (*)( const void *, const void * )) Unsafemap<U, T>::compareelems
|
||||
|
||||
stlhelper_inline internal * find(const U & keyIn)
|
||||
{
|
||||
int res = searchForIndex(&keyIn);
|
||||
if (res == -1)
|
||||
{
|
||||
return 0x0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m[res];
|
||||
}
|
||||
}
|
||||
|
||||
stlhelper_inline T & operator[](const U & keyIn)
|
||||
{
|
||||
int res = searchForIndex(&keyIn);
|
||||
if (res == -1)
|
||||
{
|
||||
internal * Elem = new internal(keyIn);
|
||||
m.addElement(Elem);
|
||||
qsort(m.v, m.size(), sizeof(internal *), compareElems);
|
||||
return Elem->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m[res]->second;
|
||||
}
|
||||
}
|
||||
|
||||
stlhelper_inline void remove(const U & keyIn)
|
||||
{
|
||||
int res = searchForIndex(&keyIn);
|
||||
if (res != -1)
|
||||
{
|
||||
m.removeElement(res);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
stlhelper_inline int searchForIndex(const U * keyIn)
|
||||
{
|
||||
size_t lowerIdx, upperIdx, currIdx;
|
||||
const void *currAddr;
|
||||
int comparResult;
|
||||
|
||||
lowerIdx = 0;
|
||||
upperIdx = m.size();
|
||||
while (lowerIdx < upperIdx)
|
||||
{
|
||||
currIdx = (lowerIdx + upperIdx) / 2;
|
||||
currAddr = (void *) (((const char *) m.v) + (currIdx * sizeof(internal *)));
|
||||
comparResult = (*compareKeys )(keyIn, currAddr);
|
||||
if (comparResult < 0)
|
||||
upperIdx = currIdx;
|
||||
else if (comparResult > 0)
|
||||
lowerIdx = currIdx + 1;
|
||||
else
|
||||
{
|
||||
return currIdx;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#undef compareKeys
|
||||
#undef compareElems
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* UNSAFEMAP_HH_ */
|
@ -1,516 +0,0 @@
|
||||
/*******************************************************************************
|
||||
|
||||
PURPOSE:
|
||||
(Definition of Unsafevector container class. Minimal protections and
|
||||
forced-inlining for this container to acheive maximum performance..)
|
||||
|
||||
PROGRAMMERS:
|
||||
(((Thomas Brain) (Metecs) (Apr 2014) (--)))
|
||||
|
||||
ICG:(No.)
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CHECKPOINTHELPER_UNSAFEVECTOR_HH_
|
||||
#define CHECKPOINTHELPER_UNSAFEVECTOR_HH_
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#ifndef DEBUG
|
||||
#define stlhelper_inline inline __attribute__((always_inline))
|
||||
#define stlhelper_force_optimize __attribute__((optimize("-O3")))
|
||||
#else
|
||||
#define stlhelper_inline
|
||||
#define stlhelper_force_optimize
|
||||
#endif
|
||||
|
||||
//#define stlhelper_inline inline
|
||||
//#define stlhelper_force_optimize
|
||||
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace CheckpointHelper
|
||||
{
|
||||
|
||||
static const int minSize = 16;
|
||||
|
||||
template<class T>
|
||||
class Unsafevector
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
stlhelper_inline Unsafevector() :
|
||||
v(new T[minSize]), numElems(0), capacity(minSize)
|
||||
{
|
||||
}
|
||||
|
||||
stlhelper_inline Unsafevector(int newNumElems) :
|
||||
numElems(0), capacity(minSize)
|
||||
{
|
||||
while (capacity <= newNumElems)
|
||||
{
|
||||
capacity *= 2;
|
||||
}
|
||||
v = new T[capacity];
|
||||
}
|
||||
|
||||
stlhelper_inline Unsafevector(const Unsafevector<T> & other) :
|
||||
numElems(other.numElems), capacity(other.numElems)
|
||||
{
|
||||
v = new T[other.numElems];
|
||||
for (int ii = 0; ii < other.numElems; ++ii)
|
||||
{
|
||||
v[ii] = other.v[ii];
|
||||
}
|
||||
}
|
||||
|
||||
stlhelper_inline Unsafevector<T> & operator=(const Unsafevector<T> & other)
|
||||
{
|
||||
reserve_nocopy(other.numElems);
|
||||
for (int ii = 0; ii < other.numElems; ++ii)
|
||||
{
|
||||
v[ii] = other.v[ii];
|
||||
}
|
||||
capacity = other.numElems;
|
||||
numElems = other.numElems;
|
||||
return *this;
|
||||
}
|
||||
|
||||
stlhelper_inline Unsafevector<T> & operator=(const std::vector<T> & other)
|
||||
{
|
||||
int vSize = other.size();
|
||||
reserve_nocopy(vSize);
|
||||
for (int ii = 0; ii < vSize; ++ii)
|
||||
{
|
||||
v[ii] = other[ii];
|
||||
}
|
||||
numElems = vSize;
|
||||
return *this;
|
||||
}
|
||||
|
||||
stlhelper_inline ~Unsafevector()
|
||||
{
|
||||
delete[] v;
|
||||
}
|
||||
|
||||
stlhelper_inline void reserve(int newSize)
|
||||
{
|
||||
if (newSize > capacity)
|
||||
{
|
||||
while (capacity <= newSize)
|
||||
{
|
||||
capacity *= 2;
|
||||
}
|
||||
T * newPtr = new T[capacity];
|
||||
for (int ii = 0; ii < numElems; ++ii)
|
||||
{
|
||||
newPtr[ii] = v[ii];
|
||||
}
|
||||
delete[] v;
|
||||
v = newPtr;
|
||||
}
|
||||
}
|
||||
|
||||
stlhelper_inline void addVectorNoCheck(std::vector<T> & vecIn)
|
||||
{
|
||||
int vecInSize = vecIn.size();
|
||||
for (int ii = numElems, jj = 0; jj < vecInSize; ++ii, ++jj)
|
||||
{
|
||||
v[ii] = vecIn[jj];
|
||||
}
|
||||
numElems += vecInSize;
|
||||
}
|
||||
|
||||
stlhelper_inline void addVector(std::vector<T> & vecIn)
|
||||
{
|
||||
int vecInSize = vecIn.size();
|
||||
reserve(numElems + vecInSize);
|
||||
for (int ii = numElems, jj = 0; jj < vecInSize; ++ii, ++jj)
|
||||
{
|
||||
v[ii] = vecIn[jj];
|
||||
}
|
||||
numElems += vecInSize;
|
||||
}
|
||||
|
||||
stlhelper_inline void addVectorNoCheck(Unsafevector<T> & vecIn)
|
||||
{
|
||||
int vecInSize = vecIn.size();
|
||||
for (int ii = numElems, jj = 0; jj < vecInSize; ++ii, ++jj)
|
||||
{
|
||||
v[ii] = vecIn[jj];
|
||||
}
|
||||
numElems += vecInSize;
|
||||
}
|
||||
|
||||
stlhelper_inline void addVector(Unsafevector<T> & vecIn)
|
||||
{
|
||||
int vecInSize = vecIn.size();
|
||||
reserve(numElems + vecInSize);
|
||||
for (int ii = numElems, jj = 0; jj < vecInSize; ++ii, ++jj)
|
||||
{
|
||||
v[ii] = vecIn[jj];
|
||||
}
|
||||
numElems += vecInSize;
|
||||
}
|
||||
|
||||
stlhelper_inline void addElementNoCheck(const T & elemIn)
|
||||
{
|
||||
v[numElems++] = elemIn;
|
||||
}
|
||||
|
||||
stlhelper_inline void addElement(const T & elemIn)
|
||||
{
|
||||
if (numElems >= capacity)
|
||||
{
|
||||
reserve(capacity * 2);
|
||||
}
|
||||
v[numElems++] = elemIn;
|
||||
}
|
||||
|
||||
stlhelper_inline void removeElement(int idx)
|
||||
{
|
||||
if ((numElems - 1) != idx)
|
||||
{
|
||||
for (int ii = idx, end = numElems; ii != end; ++ii)
|
||||
{
|
||||
v[ii] = v[ii + 1];
|
||||
}
|
||||
--numElems;
|
||||
}
|
||||
else
|
||||
{
|
||||
--numElems;
|
||||
}
|
||||
}
|
||||
|
||||
stlhelper_inline int find(const T & testElem)
|
||||
{
|
||||
for (int ii = 0, end = numElems; ii != end; ++ii)
|
||||
{
|
||||
if (v[ii] == testElem)
|
||||
{
|
||||
return ii;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
stlhelper_inline void clear()
|
||||
{
|
||||
numElems = 0;
|
||||
}
|
||||
|
||||
stlhelper_inline int size()
|
||||
{
|
||||
return numElems;
|
||||
}
|
||||
|
||||
stlhelper_inline bool isEmpty()
|
||||
{
|
||||
return (numElems == 0);
|
||||
}
|
||||
|
||||
stlhelper_inline T & operator[](int idx)
|
||||
{
|
||||
return v[idx];
|
||||
}
|
||||
stlhelper_inline T operator[](int idx) const
|
||||
{
|
||||
return v[idx];
|
||||
}
|
||||
|
||||
stlhelper_inline void swap(Unsafevector<T> & other)
|
||||
{
|
||||
std::swap(v, other.v);
|
||||
std::swap(numElems, other.numElems);
|
||||
std::swap(capacity, other.capacity);
|
||||
}
|
||||
|
||||
T * v;
|
||||
int numElems;
|
||||
int capacity;
|
||||
|
||||
protected:
|
||||
|
||||
stlhelper_inline void reserve_nocopy(int newSize)
|
||||
{
|
||||
if (newSize > capacity)
|
||||
{
|
||||
delete[] v;
|
||||
v = new T[newSize];
|
||||
capacity = newSize;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class Unsafevector<T *>
|
||||
{
|
||||
public:
|
||||
|
||||
stlhelper_inline Unsafevector() :
|
||||
v(new T *[minSize]), numElems(0), capacity(minSize)
|
||||
{
|
||||
}
|
||||
|
||||
stlhelper_inline Unsafevector(int newNumElems) :
|
||||
numElems(0), capacity(minSize)
|
||||
{
|
||||
while (capacity <= newNumElems)
|
||||
{
|
||||
capacity *= 2;
|
||||
}
|
||||
v = new T *[capacity];
|
||||
}
|
||||
|
||||
stlhelper_inline Unsafevector(const Unsafevector<T *> & other)
|
||||
{
|
||||
v = new T *[other.numElems];
|
||||
memcpy(v, other.v, sizeof(T *) * other.numElems);
|
||||
capacity = other.numElems;
|
||||
numElems = other.numElems;
|
||||
}
|
||||
|
||||
stlhelper_inline Unsafevector<T *> & operator=(const Unsafevector<T *> & other)
|
||||
{
|
||||
reserve_nocopy(other.numElems);
|
||||
memcpy(v, other.v, sizeof(T *) * other.numElems);
|
||||
capacity = other.numElems;
|
||||
numElems = other.numElems;
|
||||
return *this;
|
||||
}
|
||||
|
||||
stlhelper_inline Unsafevector<T *> & operator=(const std::vector<T *> & other)
|
||||
{
|
||||
int vSize = other.size();
|
||||
reserve_nocopy(vSize);
|
||||
memcpy(v, &other[0], sizeof(T *) * vSize);
|
||||
numElems = vSize;
|
||||
return *this;
|
||||
}
|
||||
|
||||
stlhelper_inline ~Unsafevector()
|
||||
{
|
||||
delete[] v;
|
||||
}
|
||||
|
||||
stlhelper_inline void reserve(int newSize)
|
||||
{
|
||||
if (newSize > capacity)
|
||||
{
|
||||
while (capacity <= newSize)
|
||||
{
|
||||
capacity *= 2;
|
||||
}
|
||||
T ** newPtr = new T *[capacity];
|
||||
memcpy(newPtr, v, sizeof(T *) * numElems);
|
||||
delete[] v;
|
||||
v = newPtr;
|
||||
}
|
||||
}
|
||||
|
||||
stlhelper_inline void addVectorNoCheck(std::vector<T *> & vecIn)
|
||||
{
|
||||
int vecInSize = vecIn.size();
|
||||
if (vecInSize)
|
||||
{
|
||||
memcpy(&v[numElems], &vecIn[0], sizeof(T *) * vecInSize);
|
||||
numElems += vecInSize;
|
||||
}
|
||||
}
|
||||
|
||||
stlhelper_inline void addVector(std::vector<T *> & vecIn)
|
||||
{
|
||||
int vecInSize = vecIn.size();
|
||||
if (vecInSize)
|
||||
{
|
||||
reserve(numElems + vecInSize);
|
||||
memcpy(&v[numElems], &vecIn[0], sizeof(T *) * vecInSize);
|
||||
numElems += vecInSize;
|
||||
}
|
||||
}
|
||||
|
||||
stlhelper_inline void addVectorNoCheck(Unsafevector<T *> & vecIn)
|
||||
{
|
||||
int vecInSize = vecIn.size();
|
||||
if (vecInSize)
|
||||
{
|
||||
memcpy(&v[numElems], vecIn.v, sizeof(T *) * vecInSize);
|
||||
numElems += vecInSize;
|
||||
}
|
||||
}
|
||||
|
||||
stlhelper_inline void addVector(Unsafevector<T *> & vecIn)
|
||||
{
|
||||
int vecInSize = vecIn.size();
|
||||
if (vecInSize)
|
||||
{
|
||||
reserve(numElems + vecInSize);
|
||||
memcpy(&v[numElems], vecIn.v, sizeof(T *) * vecInSize);
|
||||
numElems += vecInSize;
|
||||
}
|
||||
}
|
||||
|
||||
stlhelper_inline void addElementNoCheck(T * elemIn)
|
||||
{
|
||||
v[numElems++] = elemIn;
|
||||
}
|
||||
|
||||
stlhelper_inline void addElement(T * elemIn)
|
||||
{
|
||||
if (numElems >= capacity)
|
||||
{
|
||||
reserve(capacity * 2);
|
||||
}
|
||||
v[numElems++] = elemIn;
|
||||
}
|
||||
|
||||
void addElementSortedUnique(T * elemIn)
|
||||
{
|
||||
for (int ii = 0; ii < numElems; ++ii)
|
||||
{
|
||||
if (elemIn == v[ii])
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
addElement(elemIn);
|
||||
sortSelf();
|
||||
}
|
||||
|
||||
stlhelper_inline void removeElement(int idx)
|
||||
{
|
||||
memmove(&v[idx], &v[idx + 1], sizeof(T*) * (numElems - idx - 1));
|
||||
--numElems;
|
||||
}
|
||||
|
||||
stlhelper_inline int find(const T * testElem)
|
||||
{
|
||||
for (int ii = 0, end = numElems; ii != end; ++ii)
|
||||
{
|
||||
if (v[ii] == testElem)
|
||||
{
|
||||
return ii;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
stlhelper_inline void clear()
|
||||
{
|
||||
numElems = 0;
|
||||
}
|
||||
|
||||
stlhelper_inline int size()
|
||||
{
|
||||
return numElems;
|
||||
}
|
||||
|
||||
stlhelper_inline bool isEmpty()
|
||||
{
|
||||
return (numElems == 0);
|
||||
}
|
||||
|
||||
stlhelper_inline T * & operator[](int idx)
|
||||
{
|
||||
return v[idx];
|
||||
}
|
||||
stlhelper_inline T * operator[](int idx) const
|
||||
{
|
||||
return v[idx];
|
||||
}
|
||||
|
||||
stlhelper_inline void swap(Unsafevector<T *> & other)
|
||||
{
|
||||
std::swap(v, other.v);
|
||||
std::swap(numElems, other.numElems);
|
||||
std::swap(capacity, other.capacity);
|
||||
}
|
||||
|
||||
stlhelper_inline static int compareelems(const void * a, const void * b)
|
||||
{
|
||||
T * aPtr = *((T **) a);
|
||||
T * bPtr = *((T **) b);
|
||||
if (aPtr < bPtr)
|
||||
return -1;
|
||||
if (aPtr == bPtr)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
stlhelper_inline static int comparekey(const void * a, const void * b)
|
||||
{
|
||||
T * aPtr = (T *) a;
|
||||
T * bPtr = *((T **) b);
|
||||
if (aPtr < bPtr)
|
||||
return -1;
|
||||
if (aPtr == bPtr)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
stlhelper_inline bool contains(const T & keyIn)
|
||||
{
|
||||
return (search(&keyIn) != 0x0);
|
||||
}
|
||||
|
||||
#define compareElems (int (*)( const void *, const void * )) Unsafevector<T *>::compareelems
|
||||
#define compareKey (int (*)( const void *, const void * )) Unsafevector<T *>::comparekey
|
||||
|
||||
stlhelper_inline void sortSelf()
|
||||
{
|
||||
std::qsort(v, numElems, sizeof(T *), compareElems);
|
||||
}
|
||||
|
||||
stlhelper_inline void sortSelf(int (*compareIn)(const void *, const void *))
|
||||
{
|
||||
std::qsort(v, numElems, sizeof(T *), compareIn);
|
||||
}
|
||||
|
||||
T ** v;
|
||||
int numElems;
|
||||
int capacity;
|
||||
|
||||
protected:
|
||||
stlhelper_inline T ** search(const T * keyIn)
|
||||
{
|
||||
size_t lowerIdx, upperIdx, currIdx;
|
||||
const void *currAddr;
|
||||
int comparResult;
|
||||
|
||||
lowerIdx = 0;
|
||||
upperIdx = numElems;
|
||||
while (lowerIdx < upperIdx)
|
||||
{
|
||||
currIdx = (lowerIdx + upperIdx) / 2;
|
||||
currAddr = (void *) (((const char *) v) + (currIdx * sizeof(T *)));
|
||||
comparResult = (*compareKey )(keyIn, currAddr);
|
||||
if (comparResult < 0)
|
||||
upperIdx = currIdx;
|
||||
else if (comparResult > 0)
|
||||
lowerIdx = currIdx + 1;
|
||||
else
|
||||
return (T **) currAddr;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
stlhelper_inline void reserve_nocopy(int newSize)
|
||||
{
|
||||
if (newSize > capacity)
|
||||
{
|
||||
delete[] v;
|
||||
v = new T *[newSize];
|
||||
capacity = newSize;
|
||||
}
|
||||
}
|
||||
#undef compareElems
|
||||
#undef compareKey
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* UNSAFEVECTOR_HH_ */
|
@ -1,79 +0,0 @@
|
||||
/*******************************************************************************
|
||||
|
||||
PURPOSE:
|
||||
(Vector for checkpointable vector container.)
|
||||
|
||||
PROGRAMMERS:
|
||||
(((Thomas Brain) (Metecs) (May 2013) (--)))
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CHECKPOINTHELPER_VECTOR_HH_
|
||||
#define CHECKPOINTHELPER_VECTOR_HH_
|
||||
|
||||
#include "CheckpointItem.hh"
|
||||
#include "Unsafevector.hh"
|
||||
#include <vector>
|
||||
|
||||
namespace CheckpointHelper
|
||||
{
|
||||
|
||||
template<class T>
|
||||
class vector: public CheckpointItem, public std::vector<T>
|
||||
{
|
||||
public:
|
||||
T ** chkpt;
|
||||
std::string mmstr;
|
||||
|
||||
vector(T ** chkptIn, std::string mmstrIn) :
|
||||
chkpt(chkptIn), mmstr(mmstrIn)
|
||||
{
|
||||
*chkpt = 0x0;
|
||||
}
|
||||
|
||||
vector<T>& operator=(const std::vector<T>& pr)
|
||||
{
|
||||
std::vector<T>::operator=(pr);
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ~vector()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void checkpoint()
|
||||
{
|
||||
chkpt_seq<typename std::vector<T>::iterator, T>(*this);
|
||||
}
|
||||
virtual void restart()
|
||||
{
|
||||
restart_seq<typename std::vector<T>::iterator>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
#define STLVECTOR( type, varName ) \
|
||||
type* _##varName; \
|
||||
CheckpointHelper::vector<type> varName
|
||||
#else
|
||||
#define STLVECTOR( type, varName ) \
|
||||
type* _##varName
|
||||
#endif
|
||||
|
||||
#if (!defined(SWIG) && !defined(TRICK_ICG))
|
||||
#ifndef STL_CSTR1
|
||||
#define STL_CSTR1( varName, type ) \
|
||||
varName( &_##varName, #type )
|
||||
#endif
|
||||
#else
|
||||
#ifndef STL_CSTR1
|
||||
#define STL_CSTR1( varName, type ) \
|
||||
_##varName()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define STLVECTORCSTR STL_CSTR1
|
||||
|
||||
#endif /* STLHELPER_VECTOR_HH_ */
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +0,0 @@
|
||||
<!-- $Id$ -->
|
||||
|
||||
<head>
|
||||
<meta HTTP-EQUIV="REFRESH" content="0; url=html/index.html">
|
||||
</head>
|
||||
|
@ -1,94 +0,0 @@
|
||||
def create_new_sim_object( simObjName, typeName, ctrString = "" ):
|
||||
global externAllocs
|
||||
TRICK_DEFAULT_PHASE = 60000
|
||||
externAllocs.simObjectAllocs.append((simObjName, typeName, ctrString))
|
||||
|
||||
if not ctrString:
|
||||
ctrString = "trick." + typeName + "()"
|
||||
else:
|
||||
ctrString = "trick." + typeName + ctrString
|
||||
|
||||
cmdStr = simObjName + " = " + ctrString + "\n"
|
||||
cmdStr += "globals()[\'" + simObjName + "\'] = " + simObjName + "\n"
|
||||
|
||||
if "DRAscii" in typeName or "DRBinary" in typeName or "DRHDF5" in typeName:
|
||||
cmdStr += simObjName + ".declare_memory()\n"
|
||||
else:
|
||||
cmdStr += "trick.exec_add_sim_object(" + simObjName + ", \'" + simObjName + "\' )\n"
|
||||
cmdStr += "trick.TMM_declare_ext_var(" + simObjName + ", trick.TRICK_STRUCTURED, \'" + typeName + "\', 0, \'" + simObjName + "\', 0, None)\n"
|
||||
|
||||
cmdStr += "newSO = " + simObjName + "\n"
|
||||
exec(cmdStr)
|
||||
return newSO
|
||||
|
||||
def create_new_instance( objectName, typeName, ctrString = "", mmName = ""):
|
||||
global externAllocs
|
||||
externAllocs.objectAllocs.append((objectName, typeName, ctrString, mmName))
|
||||
|
||||
if not ctrString:
|
||||
ctrString = "trick." + typeName + "()"
|
||||
else:
|
||||
ctrString = "trick." + typeName + ctrString
|
||||
|
||||
cmdStr = objectName + " = " + ctrString + "\n"
|
||||
cmdStr += "globals()[\'" + objectName + "\'] = " + objectName + "\n"
|
||||
if not mmName:
|
||||
cmdStr += "trick.TMM_declare_ext_var(" + objectName + ", trick.TRICK_STRUCTURED, \'" + typeName + "\', 0, \'" + objectName + "\', 0, None)\n"
|
||||
else:
|
||||
cmdStr += "trick.TMM_declare_ext_var(" + objectName + ", trick.TRICK_STRUCTURED, \'" + mmName + "\', 0, \'" + objectName + "\', 0, None)\n"
|
||||
cmdStr += "newObj = " + objectName + "\n"
|
||||
exec(cmdStr)
|
||||
return newObj
|
||||
|
||||
class ExternAlloc():
|
||||
def __init__(self):
|
||||
self.simObjectAllocs = []
|
||||
self.objectAllocs = []
|
||||
|
||||
def printEntries(self):
|
||||
for alloc in self.simObjectAllocs:
|
||||
print "SimObject", alloc[0], "of type", alloc[1], "allocated in input file"
|
||||
for alloc in self.objectAllocs:
|
||||
print "Object", alloc[0], "of type", alloc[1], "allocated in input file"
|
||||
return
|
||||
|
||||
def writeChkptFile(self, chkpt_file):
|
||||
path = chkpt_file
|
||||
file = open(path, 'w')
|
||||
file.write("oldAllocs = ExternAlloc()\n")
|
||||
file.write("oldAllocs.simObjectAllocs = list(externAllocs.simObjectAllocs)\n")
|
||||
file.write("oldAllocs.objectAllocs = list(externAllocs.objectAllocs)\n")
|
||||
file.write("newAllocs = ExternAlloc()\n")
|
||||
for alloc in self.simObjectAllocs:
|
||||
file.write("newAllocs.simObjectAllocs.append((\"" + alloc[0] + "\",\"" + alloc[1] + "\",\"" + alloc[2] +"\"))\n")
|
||||
for alloc in self.objectAllocs:
|
||||
file.write("newAllocs.objectAllocs.append((\"" + alloc[0] + "\",\"" + alloc[1] + "\",\"" + alloc[2] +"\", \"" + alloc[3] + "\"))\n")
|
||||
file.write("for alloc in newAllocs.simObjectAllocs:\n")
|
||||
file.write(" if alloc not in oldAllocs.simObjectAllocs:\n")
|
||||
file.write(" create_new_sim_object( alloc[0], alloc[1], alloc[2])\n")
|
||||
file.write(" print \"Allocated \" + alloc[0]\n")
|
||||
file.write(" else:\n")
|
||||
file.write(" oldAllocs.simObjectAllocs.remove( alloc )\n")
|
||||
file.write("for alloc in newAllocs.objectAllocs:\n")
|
||||
file.write(" if alloc not in oldAllocs.objectAllocs:\n")
|
||||
file.write(" create_new_instance( alloc[0], alloc[1], alloc[2], alloc[3])\n")
|
||||
file.write(" print \"Allocated \" + alloc[0]\n")
|
||||
file.write(" else:\n")
|
||||
file.write(" oldAllocs.objectAllocs.remove( alloc )\n")
|
||||
file.write("for alloc in oldAllocs.simObjectAllocs:\n")
|
||||
file.write(" exec(\"ptr = \" + alloc[0])\n")
|
||||
file.write(" trick.exec_remove_sim_object( ptr ) \n")
|
||||
file.write(" trick.TMM_delete_extern_var_a( ptr )\n")
|
||||
file.write(" del globals()[alloc[0]]\n")
|
||||
file.write(" print \"Deleting \" + alloc[0]\n")
|
||||
file.write(" externAllocs.simObjectAllocs.remove( alloc )\n")
|
||||
file.write("for alloc in oldAllocs.objectAllocs:\n")
|
||||
file.write(" trick.TMM_delete_extern_var_n( alloc[0] )\n")
|
||||
file.write(" del globals()[alloc[0]]\n")
|
||||
file.write(" print \"Deleting \" + alloc[0]\n")
|
||||
file.write(" externAllocs.objectAllocs.remove( alloc )\n")
|
||||
return
|
||||
|
||||
if "externAllocs" not in globals():
|
||||
global externAllocs
|
||||
externAllocs = ExternAlloc()
|
Loading…
Reference in New Issue
Block a user