mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-26 05:50:32 +05:00
logging in archive not compile time based
This commit is contained in:
parent
9a20974418
commit
0a46569474
@ -211,6 +211,7 @@ namespace ngcore
|
|||||||
// don't use it that often anyway)
|
// don't use it that often anyway)
|
||||||
Archive& operator& (std::vector<bool>& v)
|
Archive& operator& (std::vector<bool>& v)
|
||||||
{
|
{
|
||||||
|
logger->debug("In special archive for std::vector<bool>");
|
||||||
size_t size;
|
size_t size;
|
||||||
if(Output())
|
if(Output())
|
||||||
size = v.size();
|
size = v.size();
|
||||||
@ -295,11 +296,11 @@ namespace ngcore
|
|||||||
{
|
{
|
||||||
if(Output())
|
if(Output())
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Store shared ptr of type " + Demangle(typeid(T).name()));
|
logger->debug("Store shared ptr of type {}", Demangle(typeid(T).name()));
|
||||||
// save -2 for nullptr
|
// save -2 for nullptr
|
||||||
if(!ptr)
|
if(!ptr)
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Storing nullptr");
|
logger->debug("Storing nullptr");
|
||||||
return (*this) << -2;
|
return (*this) << -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,7 +309,7 @@ namespace ngcore
|
|||||||
// Downcasting is only possible for our registered classes
|
// Downcasting is only possible for our registered classes
|
||||||
if(typeid(T) != typeid(*ptr))
|
if(typeid(T) != typeid(*ptr))
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Typids are different: " + Demangle(typeid(T).name()) + " vs. " +
|
logger->debug("Typids are different: " + Demangle(typeid(T).name()) + " vs. " +
|
||||||
Demangle(typeid(*ptr).name()));
|
Demangle(typeid(*ptr).name()));
|
||||||
if(!IsRegistered(Demangle(typeid(*ptr).name())))
|
if(!IsRegistered(Demangle(typeid(*ptr).name())))
|
||||||
throw Exception(std::string("Archive error: Polymorphic type ")
|
throw Exception(std::string("Archive error: Polymorphic type ")
|
||||||
@ -318,7 +319,7 @@ namespace ngcore
|
|||||||
// if there was a true downcast we have to store more information
|
// if there was a true downcast we have to store more information
|
||||||
if(reg_ptr != static_cast<void*>(ptr.get()))
|
if(reg_ptr != static_cast<void*>(ptr.get()))
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Multiple/Virtual inheritance involved, need to cast pointer");
|
logger->debug("Multiple/Virtual inheritance involved, need to cast pointer");
|
||||||
neededDowncast = true;
|
neededDowncast = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -326,8 +327,8 @@ namespace ngcore
|
|||||||
// if not found store -1 and the pointer
|
// if not found store -1 and the pointer
|
||||||
if(pos == shared_ptr2nr.end())
|
if(pos == shared_ptr2nr.end())
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Didn't find the shared_ptr, create new registry entry at " +
|
logger->debug("Didn't find the shared_ptr, create new registry entry at {}",
|
||||||
std::to_string(shared_ptr_count));
|
shared_ptr_count);
|
||||||
auto p = ptr.get();
|
auto p = ptr.get();
|
||||||
(*this) << -1;
|
(*this) << -1;
|
||||||
(*this) & neededDowncast & p;
|
(*this) & neededDowncast & p;
|
||||||
@ -338,27 +339,27 @@ namespace ngcore
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
// if found store the position and if it has to be downcasted and how
|
// if found store the position and if it has to be downcasted and how
|
||||||
NETGEN_DEBUG_LOG(logger, "Found shared_ptr at position " + std::to_string(pos->second));
|
logger->debug("Found shared_ptr at position {}", pos->second);
|
||||||
(*this) << pos->second << neededDowncast;
|
(*this) << pos->second << neededDowncast;
|
||||||
if(neededDowncast)
|
if(neededDowncast)
|
||||||
(*this) << Demangle(typeid(*ptr).name());
|
(*this) << Demangle(typeid(*ptr).name());
|
||||||
}
|
}
|
||||||
else // Input
|
else // Input
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Reading shared_ptr of type " + Demangle(typeid(T).name()));
|
logger->debug("Reading shared_ptr of type {}", Demangle(typeid(T).name()));
|
||||||
int nr;
|
int nr;
|
||||||
(*this) & nr;
|
(*this) & nr;
|
||||||
// -2 restores a nullptr
|
// -2 restores a nullptr
|
||||||
if(nr == -2)
|
if(nr == -2)
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Reading a nullptr");
|
logger->debug("Reading a nullptr");
|
||||||
ptr = nullptr;
|
ptr = nullptr;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
// -1 restores a new shared ptr by restoring the inner pointer and creating a shared_ptr to it
|
// -1 restores a new shared ptr by restoring the inner pointer and creating a shared_ptr to it
|
||||||
if (nr == -1)
|
if (nr == -1)
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Createing new shared_ptr");
|
logger->debug("Createing new shared_ptr");
|
||||||
T* p = nullptr;
|
T* p = nullptr;
|
||||||
bool neededDowncast;
|
bool neededDowncast;
|
||||||
(*this) & neededDowncast & p;
|
(*this) & neededDowncast & p;
|
||||||
@ -366,7 +367,7 @@ namespace ngcore
|
|||||||
// if we did downcast we need to store a shared_ptr<void> to the true object
|
// if we did downcast we need to store a shared_ptr<void> to the true object
|
||||||
if(neededDowncast)
|
if(neededDowncast)
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Shared pointer needed downcasting");
|
logger->debug("Shared pointer needed downcasting");
|
||||||
std::string name;
|
std::string name;
|
||||||
(*this) & name;
|
(*this) & name;
|
||||||
auto info = GetArchiveRegister(name);
|
auto info = GetArchiveRegister(name);
|
||||||
@ -378,19 +379,19 @@ namespace ngcore
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Shared pointer didn't need downcasting");
|
logger->debug("Shared pointer didn't need downcasting");
|
||||||
nr2shared_ptr.push_back(ptr);
|
nr2shared_ptr.push_back(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Reading already existing pointer at entry " + std::to_string(nr));
|
logger->debug("Reading already existing pointer at entry {}", nr);
|
||||||
auto other = nr2shared_ptr[nr];
|
auto other = nr2shared_ptr[nr];
|
||||||
bool neededDowncast;
|
bool neededDowncast;
|
||||||
(*this) & neededDowncast;
|
(*this) & neededDowncast;
|
||||||
if(neededDowncast)
|
if(neededDowncast)
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Shared pointer needed pointer downcast");
|
logger->debug("Shared pointer needed pointer downcast");
|
||||||
// if there was a downcast we can expect the class to be registered (since archiving
|
// if there was a downcast we can expect the class to be registered (since archiving
|
||||||
// wouldn't have worked else)
|
// wouldn't have worked else)
|
||||||
std::string name;
|
std::string name;
|
||||||
@ -404,7 +405,7 @@ namespace ngcore
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Shared pointer didn't need pointer casts");
|
logger->debug("Shared pointer didn't need pointer casts");
|
||||||
ptr = std::static_pointer_cast<T>(other);
|
ptr = std::static_pointer_cast<T>(other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -418,18 +419,19 @@ namespace ngcore
|
|||||||
{
|
{
|
||||||
if (Output())
|
if (Output())
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Store pointer of type " + Demangle(typeid(T).name()));
|
logger->debug("Store pointer of type {}",Demangle(typeid(T).name()));
|
||||||
// if the pointer is null store -2
|
// if the pointer is null store -2
|
||||||
if (!p)
|
if (!p)
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Storing nullptr");
|
logger->debug("Storing nullptr");
|
||||||
return (*this) << -2;
|
return (*this) << -2;
|
||||||
}
|
}
|
||||||
auto reg_ptr = static_cast<void*>(p);
|
auto reg_ptr = static_cast<void*>(p);
|
||||||
if(typeid(T) != typeid(*p))
|
if(typeid(T) != typeid(*p))
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Typeids are different: " + Demangle(typeid(T).name()) + " vs. " +
|
logger->debug("Typeids are different: {} vs {}",
|
||||||
Demangle(typeid(*p).name()));
|
Demangle(typeid(T).name()),
|
||||||
|
Demangle(typeid(*p).name()));
|
||||||
if(!IsRegistered(Demangle(typeid(*p).name())))
|
if(!IsRegistered(Demangle(typeid(*p).name())))
|
||||||
throw Exception(std::string("Archive error: Polymorphic type ")
|
throw Exception(std::string("Archive error: Polymorphic type ")
|
||||||
+ Demangle(typeid(*p).name())
|
+ Demangle(typeid(*p).name())
|
||||||
@ -437,20 +439,20 @@ namespace ngcore
|
|||||||
reg_ptr = GetArchiveRegister(Demangle(typeid(*p).name())).downcaster(typeid(T), static_cast<void*>(p));
|
reg_ptr = GetArchiveRegister(Demangle(typeid(*p).name())).downcaster(typeid(T), static_cast<void*>(p));
|
||||||
if(reg_ptr != static_cast<void*>(p))
|
if(reg_ptr != static_cast<void*>(p))
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Multiple/Virtual inheritance involved, need to cast pointer");
|
logger->debug("Multiple/Virtual inheritance involved, need to cast pointer");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto pos = ptr2nr.find(reg_ptr);
|
auto pos = ptr2nr.find(reg_ptr);
|
||||||
// if the pointer is not found in the map create a new entry
|
// if the pointer is not found in the map create a new entry
|
||||||
if (pos == ptr2nr.end())
|
if (pos == ptr2nr.end())
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Didn't find pointer, create new registry entry at " +
|
logger->debug("Didn't find pointer, create new registry entry at " +
|
||||||
std::to_string(ptr_count));
|
std::to_string(ptr_count));
|
||||||
ptr2nr[reg_ptr] = ptr_count++;
|
ptr2nr[reg_ptr] = ptr_count++;
|
||||||
if(typeid(*p) == typeid(T))
|
if(typeid(*p) == typeid(T))
|
||||||
if (std::is_constructible<T>::value)
|
if (std::is_constructible<T>::value)
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Store standard class pointer (no virt. inh,...)");
|
logger->debug("Store standard class pointer (no virt. inh,...)");
|
||||||
return (*this) << -1 & (*p);
|
return (*this) << -1 & (*p);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -466,7 +468,7 @@ namespace ngcore
|
|||||||
throw Exception(std::string("Archive error: Polymorphic type ")
|
throw Exception(std::string("Archive error: Polymorphic type ")
|
||||||
+ Demangle(typeid(*p).name())
|
+ Demangle(typeid(*p).name())
|
||||||
+ " not registered for archive");
|
+ " not registered for archive");
|
||||||
NETGEN_DEBUG_LOG(logger, "Store a possibly more complicated pointer");
|
logger->debug("Store a possibly more complicated pointer");
|
||||||
return (*this) << -3 << Demangle(typeid(*p).name()) & (*p);
|
return (*this) << -3 << Demangle(typeid(*p).name()) & (*p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -474,39 +476,37 @@ namespace ngcore
|
|||||||
{
|
{
|
||||||
(*this) & pos->second;
|
(*this) & pos->second;
|
||||||
bool downcasted = !(reg_ptr == static_cast<void*>(p) );
|
bool downcasted = !(reg_ptr == static_cast<void*>(p) );
|
||||||
NETGEN_DEBUG_LOG(logger, "Store a the existing position in registry at " +
|
logger->debug("Store a the existing position in registry at {}", pos->second);
|
||||||
std::to_string(pos->second));
|
logger->debug("Pointer {} downcasting", downcasted ? "needs" : "doesn't need");
|
||||||
NETGEN_DEBUG_LOG(logger, std::string("Pointer ") + (downcasted ? "needs " : "doesn't need ") +
|
|
||||||
"downcasting");
|
|
||||||
// store if the class has been downcasted and the name
|
// store if the class has been downcasted and the name
|
||||||
(*this) << downcasted << Demangle(typeid(*p).name());
|
(*this) << downcasted << Demangle(typeid(*p).name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Reading pointer of type " + Demangle(typeid(T).name()));
|
logger->debug("Reading pointer of type {}", Demangle(typeid(T).name()));
|
||||||
int nr;
|
int nr;
|
||||||
(*this) & nr;
|
(*this) & nr;
|
||||||
if (nr == -2) // restore a nullptr
|
if (nr == -2) // restore a nullptr
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Loading a nullptr");
|
logger->debug("Loading a nullptr");
|
||||||
p = nullptr;
|
p = nullptr;
|
||||||
}
|
}
|
||||||
else if (nr == -1) // create a new pointer of standard type (no virtual or multiple inheritance,...)
|
else if (nr == -1) // create a new pointer of standard type (no virtual or multiple inheritance,...)
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Load a new pointer to a simple class");
|
logger->debug("Load a new pointer to a simple class");
|
||||||
p = detail::constructIfPossible<T>();
|
p = detail::constructIfPossible<T>();
|
||||||
nr2ptr.push_back(p);
|
nr2ptr.push_back(p);
|
||||||
(*this) & *p;
|
(*this) & *p;
|
||||||
}
|
}
|
||||||
else if(nr == -3) // restore one of our registered classes that can have multiple inheritance,...
|
else if(nr == -3) // restore one of our registered classes that can have multiple inheritance,...
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Load a new pointer to a potentially more complicated class "
|
logger->debug("Load a new pointer to a potentially more complicated class "
|
||||||
"(allows for multiple/virtual inheritance,...)");
|
"(allows for multiple/virtual inheritance,...)");
|
||||||
// As stated above, we want this special behaviour only for our classes that implement DoArchive
|
// As stated above, we want this special behaviour only for our classes that implement DoArchive
|
||||||
std::string name;
|
std::string name;
|
||||||
(*this) & name;
|
(*this) & name;
|
||||||
NETGEN_DEBUG_LOG(logger, "Name = " + name);
|
logger->debug("Name = " + name);
|
||||||
auto info = GetArchiveRegister(name);
|
auto info = GetArchiveRegister(name);
|
||||||
// the creator creates a new object of type name, and returns a void* pointing
|
// the creator creates a new object of type name, and returns a void* pointing
|
||||||
// to T (which may have an offset)
|
// to T (which may have an offset)
|
||||||
@ -518,13 +518,11 @@ namespace ngcore
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NETGEN_DEBUG_LOG(logger, "Restoring pointer to already existing object at registry position " +
|
logger->debug("Restoring pointer to already existing object at registry position {}", nr);
|
||||||
std::to_string(nr));
|
|
||||||
bool downcasted;
|
bool downcasted;
|
||||||
std::string name;
|
std::string name;
|
||||||
(*this) & downcasted & name;
|
(*this) & downcasted & name;
|
||||||
NETGEN_DEBUG_LOG(logger, std::string(downcasted ? "Downcasted" : "Not downcasted") +
|
logger->debug("{} object of type {}", downcasted ? "Downcasted" : "Not downcasted", name);
|
||||||
" object of type " + name);
|
|
||||||
if(downcasted)
|
if(downcasted)
|
||||||
{
|
{
|
||||||
// if the class has been downcasted we can assume it is in the register
|
// if the class has been downcasted we can assume it is in the register
|
||||||
|
Loading…
Reference in New Issue
Block a user