X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=common%2FclitkCommon.txx;h=845e62fe520deb89def17b26d99c0e3fa7be1c98;hb=543b72e23ad001ac2a7743b9beacf48e2d0054ac;hp=dc7f1653c45d5d9e3538043297ca89408c64b80e;hpb=765020625fbc092d283e221e36c83e60a1844cb7;p=clitk.git diff --git a/common/clitkCommon.txx b/common/clitkCommon.txx index dc7f165..845e62f 100644 --- a/common/clitkCommon.txx +++ b/common/clitkCommon.txx @@ -195,6 +195,7 @@ std::string GetTypeAsString() } //-------------------------------------------------------------------- + //-------------------------------------------------------------------- template void CloneImage(const typename ImageType::Pointer & input, typename ImageType::Pointer & output) @@ -217,5 +218,39 @@ void CloneImage(const typename ImageType::Pointer & input, typename ImageType::P } //-------------------------------------------------------------------- + +//-------------------------------------------------------------------- +// http://stackoverflow.com/questions/771453/copy-map-values-to-vector-in-stl +template +void MapToVecFirst(const M & m, V & v) { + for( typename M::const_iterator it = m.begin(); it != m.end(); ++it ) { + v.push_back( it->first ); + } +} +template +void MapToVecSecond(const M & m, V & v) { + for( typename M::const_iterator it = m.begin(); it != m.end(); ++it ) { + v.push_back( it->second ); + } +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +//http://stackoverflow.com/questions/1494399/how-do-i-search-find-and-replace-in-a-standard-string +template +int inline findAndReplace(T& source, const T& find, const T& replace) +{ + int num=0; + int fLen = find.size(); + int rLen = replace.size(); + for (int pos=0; (pos=source.find(find, pos))!=T::npos; pos+=rLen) { + num++; + source.replace(pos, fLen, replace); + } + return num; +} +//-------------------------------------------------------------------- + #endif /* end #define CLITKCOMMON_TXX */