mirror of
https://github.com/NGSolve/netgen.git
synced 2025-01-26 21:00:34 +05:00
Fix casts
This commit is contained in:
parent
0ef2d0f7f9
commit
b0d15ee29e
@ -387,7 +387,7 @@ namespace ngcore
|
|||||||
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)
|
||||||
p = dynamic_cast<T*>(info.creator(typeid(T)));
|
p = static_cast<T*>(info.creator(typeid(T)));
|
||||||
// we store the downcasted pointer (to be able to find it again from
|
// we store the downcasted pointer (to be able to find it again from
|
||||||
// another class in a multiple inheritance tree)
|
// another class in a multiple inheritance tree)
|
||||||
nr2ptr.push_back(info.downcaster(typeid(T),p));
|
nr2ptr.push_back(info.downcaster(typeid(T),p));
|
||||||
@ -402,10 +402,10 @@ namespace ngcore
|
|||||||
{
|
{
|
||||||
// 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
|
||||||
auto info = GetArchiveRegister(name);
|
auto info = GetArchiveRegister(name);
|
||||||
p = dynamic_cast<T*>(info.upcaster(typeid(T), nr2ptr[nr]));
|
p = static_cast<T*>(info.upcaster(typeid(T), nr2ptr[nr]));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
p = dynamic_cast<T*>(nr2ptr[nr]);
|
p = static_cast<T*>(nr2ptr[nr]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@ -459,7 +459,7 @@ namespace ngcore
|
|||||||
static void* tryDowncast(const std::type_info& ti, void* p)
|
static void* tryDowncast(const std::type_info& ti, void* p)
|
||||||
{
|
{
|
||||||
if(typeid(B1) == ti)
|
if(typeid(B1) == ti)
|
||||||
return dynamic_cast<T*>(dynamic_cast<B1*>(p));
|
return dynamic_cast<T*>(static_cast<B1*>(p));
|
||||||
try
|
try
|
||||||
{ return GetArchiveRegister(demangle(typeid(B1).name())).downcaster(ti, static_cast<void*>(dynamic_cast<B1*>(p))); }
|
{ return GetArchiveRegister(demangle(typeid(B1).name())).downcaster(ti, static_cast<void*>(dynamic_cast<B1*>(p))); }
|
||||||
catch(std::exception)
|
catch(std::exception)
|
||||||
@ -481,7 +481,7 @@ namespace ngcore
|
|||||||
{ return typeid(T) == ti ? constructIfPossible<T>()
|
{ return typeid(T) == ti ? constructIfPossible<T>()
|
||||||
: Archive::Caster<T, Bases...>::tryUpcast(ti, constructIfPossible<T>()); };
|
: Archive::Caster<T, Bases...>::tryUpcast(ti, constructIfPossible<T>()); };
|
||||||
info.upcaster = [this](const std::type_info& ti, void* p) -> void*
|
info.upcaster = [this](const std::type_info& ti, void* p) -> void*
|
||||||
{ return typeid(T) == ti ? p : Archive::Caster<T, Bases...>::tryUpcast(ti, dynamic_cast<T*>(p)); };
|
{ return typeid(T) == ti ? p : Archive::Caster<T, Bases...>::tryUpcast(ti, static_cast<T*>(p)); };
|
||||||
info.downcaster = [this](const std::type_info& ti, void* p) -> void*
|
info.downcaster = [this](const std::type_info& ti, void* p) -> void*
|
||||||
{ return typeid(T) == ti ? p : Archive::Caster<T, Bases...>::tryDowncast(ti, p); };
|
{ return typeid(T) == ti ? p : Archive::Caster<T, Bases...>::tryDowncast(ti, p); };
|
||||||
Archive::SetArchiveRegister(std::string(demangle(typeid(T).name())),info);
|
Archive::SetArchiveRegister(std::string(demangle(typeid(T).name())),info);
|
||||||
@ -558,11 +558,11 @@ namespace ngcore
|
|||||||
if (unlikely(ptr > BUFFERSIZE-sizeof(T)))
|
if (unlikely(ptr > BUFFERSIZE-sizeof(T)))
|
||||||
{
|
{
|
||||||
fout->write(&buffer[0], ptr);
|
fout->write(&buffer[0], ptr);
|
||||||
*dynamic_cast<T*>(&buffer[0]) = x;
|
*static_cast<T*>(&buffer[0]) = x;
|
||||||
ptr = sizeof(T);
|
ptr = sizeof(T);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
*dynamic_cast<T*>(&buffer[ptr]) = x;
|
*static_cast<T*>(&buffer[ptr]) = x;
|
||||||
ptr += sizeof(T);
|
ptr += sizeof(T);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user