X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmSegmentedPalette.h;h=3c9c13877be6ab2e0e417e2bff84148ab350355c;hb=721d134c6e594b9a23bf1ce002ed87bfbc1576a7;hp=2a7d7119dbcc7c2acd9b9567e1662d9eee0a0d14;hpb=4249e0d6fb6942a1b221a74f42bff4acd773105d;p=gdcm.git diff --git a/src/gdcmSegmentedPalette.h b/src/gdcmSegmentedPalette.h index 2a7d7119..3c9c1387 100644 --- a/src/gdcmSegmentedPalette.h +++ b/src/gdcmSegmentedPalette.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSegmentedPalette.h,v $ Language: C++ - Date: $Date: 2007/10/24 07:15:32 $ - Version: $Revision: 1.11 $ + Date: $Date: 2007/10/30 09:14:42 $ + Version: $Revision: 1.15 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -36,7 +36,7 @@ // And both were coming from a ALOKA SSD-4000 station // // JPRx : -// It compiles fine under gcc 4.1.2 and msvc 7 +// It compiles fine under gcc 4.1.2, msvc 7 and DarwinG5-g++ // It doesn't compile on msvc 6, borland and SunOS // Any fix welcome ! @@ -54,8 +54,34 @@ #define GDCM_TYPENAME typename #endif +// Hack for Borland +#if defined(__BORLANDC__) +#define GDCM_TYPENAME2 +#else +#define GDCM_TYPENAME2 typename +#endif + + namespace GDCM_NAME_SPACE { +// Long stody short: Sun compiler only provide the second interface of std::distance, since the implemenation +// is so trivial, I'd rather redo it myself. +// Ref: +// http://www.sgi.com/tech/stl/distance.html#2 +// The second version of distance was the one defined in the original STL, and the first version is the one defined in the draft C++ standard; the definition was changed because the older interface was clumsy and error-prone. The older interface required the use of a temporary variable, and it has semantics that are somewhat nonintuitive: it increments n by the distance from first to last, rather than storing that distance in n + template + inline int32_t + mydistance(InputIterator first, InputIterator last) + { + int32_t n = 0; + while (first != last) + { + ++first; + ++n; + } + return n; + } + // abstract class for segment. template class Segment { @@ -64,12 +90,9 @@ namespace GDCM_NAME_SPACE virtual bool Expand(const SegmentMap& instances, std::vector& expanded) const = 0; const EntryType* First() const { return _first; } - const EntryType* Last() const { return _last; } + const EntryType* Last() const { return _last; } struct ToMap { - std::pair< - typename SegmentMap::key_type, - typename SegmentMap::mapped_type - > + typename SegmentMap::value_type operator()(const Segment* segment) const { return std::make_pair(segment->First(), segment); } }; @@ -153,7 +176,8 @@ namespace GDCM_NAME_SPACE } EntryType nNumCopies = *(this->_first + 1); GDCM_TYPENAME SegmentMap::const_iterator ppSeg = ppHeadSeg; - while ( std::distance(ppHeadSeg, ppSeg) < nNumCopies ) { + while ( mydistance(ppHeadSeg, ppSeg) < nNumCopies ) { + // assert( mydistance(ppHeadSeg, ppSeg) == std::distance(ppHeadSeg, ppSeg) ); assert( ppSeg != instances.end() ); ppSeg->second->Expand(instances, expanded); ++ppSeg; @@ -169,7 +193,8 @@ namespace GDCM_NAME_SPACE typedef std::deque*> SegmentList; SegmentList segments; const EntryType* raw_seg = raw_values; - while ( (std::distance(raw_values, raw_seg) * sizeof(EntryType)) * segment = NULL; if ( *raw_seg == 0 ) { segment = new DiscreteSegment(raw_seg); @@ -185,10 +210,11 @@ namespace GDCM_NAME_SPACE // invalid opcode break; } + } GDCM_TYPENAME Segment::SegmentMap instances; std::transform(segments.begin(), segments.end(), - std::inserter(instances, instances.end()), GDCM_TYPENAME Segment::ToMap()); + std::inserter(instances, instances.end()), GDCM_TYPENAME2 Segment::ToMap()); GDCM_TYPENAME SegmentList::iterator ppSeg = segments.begin(); GDCM_TYPENAME SegmentList::iterator endOfSegments = segments.end(); for ( ; ppSeg != endOfSegments; ++ppSeg ) {