// utils.h // // Author: J.A. de Jong // // Description: // Some generic utils. ////////////////////////////////////////////////////////////////////// #pragma once #ifndef UTILS_H #define UTILS_H #include #include #include "tracer.h" #include "vtypes.h" #include #include #include // Purge a vector of components template void purge(std::vector& vec){ TRACE(10,"purge(vector)"); for (T& it: vec){ delete it; it=nullptr; } vec.clear(); } // Purge a vector of components template void purge(std::map& map){ TRACE(10,"purge(map)"); for (auto& it: map){ delete it.second; it.second=nullptr; } map.clear(); } template const T& min(const T& x,const T& y) { return x<=y? x : y; } template const T& max(const T& x,const T& y) { return x<=y? y : x; } template SegType* copySeg(const SegType& t,const Sys& sys) { SegType* newt=new SegType(t); if(!newt){ WARN("Copying " << typeid(t).name() << "failed!"); } return newt; } // copySeg template void makeNormal(T& c) { for(auto& val: c) if(!std::isnormal(val)) val=0; } } // namespace utils //////////////////////////////////////////////////////////////////////