diff --git a/Code/Common/otbVariableLengthVectorConverter.h b/Code/Common/otbVariableLengthVectorConverter.h new file mode 100644 index 0000000000000000000000000000000000000000..f1a0c43f5146ceff922f35bf2fb6382a811e9b75 --- /dev/null +++ b/Code/Common/otbVariableLengthVectorConverter.h @@ -0,0 +1,259 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbVariableLengthVectorConverter_h +#define __otbVariableLengthVectorConverter_h + +#include "itkProcessObject.h" +#include "itkVariableLengthVector.h" +#include "itkNumericTraits.h" +#include "itkExceptionObject.h" +#include "itkFixedArray.h" +#include "itkHistogram.h" +#include "itkSmartPointer.h" + + +namespace otb +{ +/** + * \class VariableLengthVectorConverter + * \brief Convert any data container type into a VariableLengthVector. + * + * To be usable, the desired convertion must be implemented through + * partial specialisation mecanism. + * + */ + +//Base +template< class TInputType, class TPrecisionType = double > +class ITK_EXPORT VariableLengthVectorConverter : +public itk::ProcessObject +{ +public: + /** Standard class typedefs */ + typedef VariableLengthVectorConverter Self; + typedef itk::ProcessObject Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(VariableLengthVectorConverter, ProcessObject); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + typedef TPrecisionType OutputPrecisionType; + typedef typename itk::VariableLengthVector<OutputPrecisionType> OutputType; + typedef TInputType InputType; + + OutputType Convert (InputType input) + { + itkGenericExceptionMacro( << "Type Convertion Not Implemented." << std::endl ); + } + +protected: + VariableLengthVectorConverter(){} + virtual ~VariableLengthVectorConverter(){} + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os, indent); + os << "Attempt to use inexistant implementation of the converter!" + << std::endl; + } + +private: + VariableLengthVectorConverter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented +}; + + + +// Real Matrix +template< class TInternalInputType, class TPrecisionType > +class ITK_EXPORT VariableLengthVectorConverter<std::vector<std::vector<TInternalInputType> >, + TPrecisionType> : +public itk::ProcessObject +{ +public: + /** Standard class typedefs */ + typedef VariableLengthVectorConverter Self; + typedef itk::ProcessObject Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(VariableLengthVectorConverter, ProcessObject); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + typedef TPrecisionType OutputPrecisionType; + typedef typename itk::VariableLengthVector<OutputPrecisionType> OutputType; + typedef typename std::vector<std::vector<TInternalInputType> > InputType; + + OutputType Convert(InputType input); + +protected: + VariableLengthVectorConverter(){} + virtual ~VariableLengthVectorConverter(){} + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os, indent); + os << "Converter: std::vector<std::vector<RealType>> => VariableLengthVector<RealType>" + << std::endl; + } + +private: + VariableLengthVectorConverter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented +}; + + + +//Complex Matrix +template< class TInternalInputType, class TPrecisionType > +class ITK_EXPORT VariableLengthVectorConverter<std::vector<std::vector<std::complex<TInternalInputType> > >, + TPrecisionType> : +public itk::ProcessObject +{ +public: + /** Standard class typedefs */ + typedef VariableLengthVectorConverter Self; + typedef itk::ProcessObject Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(VariableLengthVectorConverter, ProcessObject); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + typedef TPrecisionType OutputPrecisionType; + typedef typename itk::VariableLengthVector<OutputPrecisionType> OutputType; + typedef typename std::vector<std::vector<std::complex<TInternalInputType> > > InputType; + + OutputType Convert(InputType input); + +protected: + VariableLengthVectorConverter(){} + virtual ~VariableLengthVectorConverter(){} + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os, indent); + os << "Converter: std::vector<std::vector<std::complex<RealType>>> => VariableLengthVector<RealType>" + << std::endl; + } + +private: + VariableLengthVectorConverter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented +}; + + + +//Fixed Array +template< class TInternalInputType, unsigned int VArrayDimension, class TPrecisionType > +class ITK_EXPORT VariableLengthVectorConverter<itk::FixedArray<TInternalInputType, VArrayDimension>, + TPrecisionType> : +public itk::ProcessObject +{ +public: + /** Standard class typedefs */ + typedef VariableLengthVectorConverter Self; + typedef itk::ProcessObject Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(VariableLengthVectorConverter, ProcessObject); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + typedef TPrecisionType OutputPrecisionType; + typedef typename itk::VariableLengthVector<OutputPrecisionType> OutputType; + typedef typename itk::FixedArray<TInternalInputType, VArrayDimension> InputType; + + OutputType Convert(InputType input); + +protected: + VariableLengthVectorConverter(){} + virtual ~VariableLengthVectorConverter(){} + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os, indent); + os << "Converter: itk::FixedArray<RealType, VArrayDimension> => VariableLengthVector<RealType>" + << std::endl; + } + +private: + VariableLengthVectorConverter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented +}; + +//Histogram +template< class TMeasurement, unsigned int VMeasurementVectorSize, class TFrequencyContainer, class TPrecisionType > +class ITK_EXPORT VariableLengthVectorConverter<typename itk::SmartPointer< const itk::Statistics::Histogram<TMeasurement, + VMeasurementVectorSize, + TFrequencyContainer> >, + TPrecisionType> : +public itk::ProcessObject +{ +public: + /** Standard class typedefs */ + typedef VariableLengthVectorConverter Self; + typedef itk::ProcessObject Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(VariableLengthVectorConverter, ProcessObject); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + typedef TPrecisionType OutputPrecisionType; + typedef typename itk::VariableLengthVector<OutputPrecisionType> OutputType; + typedef typename itk::SmartPointer< const itk::Statistics::Histogram<TMeasurement, + VMeasurementVectorSize, + TFrequencyContainer> > InputType; + + OutputType Convert(InputType input); + +protected: + VariableLengthVectorConverter(){} + virtual ~VariableLengthVectorConverter(){} + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os, indent); + os << "Converter: itk::Statistics::Histogram<RealType, VMeasurementVectorSize, TFrequencyContainer> => VariableLengthVector<RealType>" + << std::endl; + } + +private: + VariableLengthVectorConverter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented +}; + +}// namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbVariableLengthVectorConverter.txx" +#endif + +#endif diff --git a/Code/Common/otbVariableLengthVectorConverter.txx b/Code/Common/otbVariableLengthVectorConverter.txx new file mode 100644 index 0000000000000000000000000000000000000000..42931131a5789729f74a6344066f237bb336d95a --- /dev/null +++ b/Code/Common/otbVariableLengthVectorConverter.txx @@ -0,0 +1,140 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbVariableLengthVectorConverter_txx +#define __otbVariableLengthVectorConverter_txx + +#include "otbVariableLengthVectorConverter.h" +#include "itkNumericTraits.h" +#include <complex> + + +namespace otb +{ + +// Real Matrix +template< class TInternalInputType, class TPrecisionType > +typename VariableLengthVectorConverter< std::vector<std::vector<TInternalInputType> >, TPrecisionType> +::OutputType +VariableLengthVectorConverter< std::vector<std::vector<TInternalInputType> >, TPrecisionType> +::Convert(InputType input) +{ + unsigned int p, q, rsltIdx = 0; + OutputType result; + + p = input.size(); + q = input.at(0).size(); + + result.SetSize(p*q); + + for (unsigned int i=0; i<p; i++) + { + for (unsigned int j=0; j<q; j++) + { + result[rsltIdx] = static_cast<OutputPrecisionType>(input.at(i).at(j)); + rsltIdx ++; + } + } + + return result; +} + +// Complex Matrix +template< class TInternalInputType, class TPrecisionType > +typename VariableLengthVectorConverter< std::vector<std::vector<std::complex<TInternalInputType> > >, + TPrecisionType> +::OutputType +VariableLengthVectorConverter< std::vector<std::vector<std::complex<TInternalInputType> > >, + TPrecisionType> +::Convert(InputType input) +{ + unsigned int p, q, rsltIdx = 0; + OutputType result; + + p = input.size(); + q = input.at(0).size(); + + result.SetSize(p*q*2); + + for (unsigned int i=0; i<p; i++) + { + for (unsigned int j=0; j<q; j++) + { + result[rsltIdx] = static_cast<OutputPrecisionType>(input.at(i).at(j).real()); + rsltIdx ++; + result[rsltIdx] = static_cast<OutputPrecisionType>(input.at(i).at(j).imag()); + rsltIdx ++; + } + } + + return result; +} + +// Fixed Array +template< class TInternalInputType, unsigned int VArrayDimension, class TPrecisionType > +typename VariableLengthVectorConverter< itk::FixedArray<TInternalInputType, VArrayDimension>, TPrecisionType> +::OutputType +VariableLengthVectorConverter< itk::FixedArray<TInternalInputType, VArrayDimension>, TPrecisionType> +::Convert(InputType input) +{ + unsigned int p, q, rsltIdx = 0; + OutputType result; + + result.SetSize(VArrayDimension); + + for (unsigned int i=0; i<VArrayDimension; i++) + { + result[rsltIdx] = static_cast<OutputPrecisionType>(input[i]); + rsltIdx ++; + } + + return result; +} + +// Histogram +template< class TMeasurement, unsigned int VMeasurementVectorSize, class TFrequencyContainer, class TPrecisionType > +typename VariableLengthVectorConverter< itk::SmartPointer< const itk::Statistics::Histogram<TMeasurement, + VMeasurementVectorSize, + TFrequencyContainer> >, + TPrecisionType> +::OutputType +VariableLengthVectorConverter< itk::SmartPointer<const itk::Statistics::Histogram<TMeasurement, + VMeasurementVectorSize, + TFrequencyContainer> >, + TPrecisionType> +::Convert(InputType input) +{ + unsigned int rsltIdx = 0; + itk::Size<1> nbBins; + OutputType result; + + nbBins[0] = input->GetSize()[0]; + + result.SetSize(nbBins[0]); + + for (unsigned int i=0; i<nbBins[0]; i++) + { + result[rsltIdx] = static_cast<OutputPrecisionType>(input->GetFrequency(i)); + rsltIdx ++; + } + + return result; +} + +} // namespace otb + +#endif diff --git a/Code/FeatureExtraction/otbComplexMomentsImageFunction.h b/Code/FeatureExtraction/otbComplexMomentsImageFunction.h index 9a6314c07fb85f814379917d0f46cc6706dc046d..290c27a544d04cdbe166731c365721388d552acf 100644 --- a/Code/FeatureExtraction/otbComplexMomentsImageFunction.h +++ b/Code/FeatureExtraction/otbComplexMomentsImageFunction.h @@ -80,6 +80,8 @@ public: typedef double ScalarRealType; typedef typename std::complex<ScalarRealType> ScalarComplexType; + typedef TCoordRep CoordRepType; + /** Dimension of the underlying image. */ itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); diff --git a/Code/FeatureExtraction/otbFlusserMomentsImageFunction.h b/Code/FeatureExtraction/otbFlusserMomentsImageFunction.h index 422d83222ecb4cdd3abb832bab72949f71c8d1bd..80170e12224793fe2afce524fa7b4ac94bbaaa4b 100644 --- a/Code/FeatureExtraction/otbFlusserMomentsImageFunction.h +++ b/Code/FeatureExtraction/otbFlusserMomentsImageFunction.h @@ -93,6 +93,8 @@ public: typedef typename Superclass::OutputType OutputType; typedef typename OutputType::ValueType ScalarRealType; + typedef TCoordRep CoordRepType; + /** Dimension of the underlying image. */ itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); diff --git a/Code/FeatureExtraction/otbFourierMellinDescriptorsImageFunction.h b/Code/FeatureExtraction/otbFourierMellinDescriptorsImageFunction.h index f3600a3d84b0c0c703ba81dff23087f0827c4d4f..fc0c95a649cfa054af2ac82834358d373dff44f1 100644 --- a/Code/FeatureExtraction/otbFourierMellinDescriptorsImageFunction.h +++ b/Code/FeatureExtraction/otbFourierMellinDescriptorsImageFunction.h @@ -89,6 +89,8 @@ public: typedef typename std::complex<ScalarRealType> ScalarComplexType; typedef typename std::vector< std::vector< ScalarComplexType > > ComplexType; + typedef TCoordRep CoordRepType; + /** Dimension of the underlying image. */ itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); diff --git a/Code/FeatureExtraction/otbHaralickTexturesImageFunction.h b/Code/FeatureExtraction/otbHaralickTexturesImageFunction.h new file mode 100644 index 0000000000000000000000000000000000000000..e36b5847c1abcc2d6804c80e2e97086ef6391a33 --- /dev/null +++ b/Code/FeatureExtraction/otbHaralickTexturesImageFunction.h @@ -0,0 +1,215 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbHaralickTexturesImageFunction_h +#define __otbHaralickTexturesImageFunction_h + +#include "itkImageFunction.h" +#include "itkFixedArray.h" +#include "otbMaskedScalarImageToGreyLevelCoocurenceMatrixGenerator.h" +#include "itkGreyLevelCooccurrenceMatrixTextureCoefficientsCalculator.h" + +namespace otb +{ +/** + * \class HaralickTexturesImageFunction + * \brief Compute the 8 Haralick texture indices on the neighborhood of the point + * + * This class computes the 8 Haralick texture indices on the neighborhood of the point + * (where \f$ g(i, j) \f$ is the element in + * cell i, j of a normalized GLCM): + * + * "Energy" \f$ = f_1 = \sum_{i,j}g(i, j)^2 \f$ + * + * "Entropy" \f$ = f_2 = -\sum_{i,j}g(i, j) \log_2 g(i, j)\f$, or 0 if \f$g(i, j) = 0\f$ + * + * "Correlation" \f$ = f_3 = \sum_{i,j}\frac{(i - \mu)(j - \mu)g(i, j)}{\sigma^2} \f$ + * + * "Difference Moment" \f$= f_4 = \sum_{i,j}\frac{1}{1 + (i - j)^2}g(i, j) \f$ + * + * "Inertia" \f$ = f_5 = \sum_{i,j}(i - j)^2g(i, j) \f$ (sometimes called "contrast") + * + * "Cluster Shade" \f$ = f_6 = \sum_{i,j}((i - \mu) + (j - \mu))^3 g(i, j) \f$ + * + * "Cluster Prominence" \f$ = f_7 = \sum_{i,j}((i - \mu) + (j - \mu))^4 g(i, j) \f$ + * + * "Haralick's Correlation" \f$ = f_8 = \frac{\sum_{i,j}(i, j) g(i, j) -\mu_t^2}{\sigma_t^2} \f$ + * where \f$\mu_t\f$ and \f$\sigma_t\f$ are the mean and standard deviation of the row + * (or column, due to symmetry) sums. + * + * Above, \f$ \mu = \f$ (weighted pixel average) \f$ = \sum_{i,j}i \cdot g(i, j) = + * \sum_{i,j}j \cdot g(i, j) \f$ (due to matrix summetry), and + * + * \f$ \sigma = \f$ (weighted pixel variance) \f$ = \sum_{i,j}(i - \mu)^2 \cdot g(i, j) = + * \sum_{i,j}(j - \mu)^2 \cdot g(i, j) \f$ (due to matrix summetry) + * This class is templated over the input image type and the + * coordinate representation type (e.g. float or double). + * + * \sa otb::MaskedScalarImageToGreyLevelCooccurrenceMatrixGenerator + * \sa itk::GreyLevelCooccurrenceMatrixTextureCoefficientsCalculator + * + * \ingroup ImageFunctions + */ + +template <class TInputImage, class TCoordRep = double > +class ITK_EXPORT HaralickTexturesImageFunction : + public itk::ImageFunction< TInputImage, + itk::FixedArray< + ITK_TYPENAME itk::NumericTraits<typename TInputImage::PixelType>::RealType, + 8 >, + TCoordRep > +{ +public: + /** Standard class typedefs. */ + typedef HaralickTexturesImageFunction Self; + typedef itk::ImageFunction< TInputImage, + itk::FixedArray< + ITK_TYPENAME itk::NumericTraits< + typename TInputImage::PixelType>::RealType, + 8 >, + TCoordRep > Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(HaralickTexturesImageFunction, ImageFunction); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** InputImageType typedef support. */ + typedef TInputImage InputImageType; + typedef typename Superclass::IndexType IndexType; + typedef typename Superclass::ContinuousIndexType ContinuousIndexType; + typedef typename Superclass::PointType PointType; + typedef typename InputImageType::Pointer InputImagePointerType; + typedef typename InputImageType::PixelType InputPixelType; + typedef typename InputImageType::RegionType InputRegionType; + typedef typename InputRegionType::SizeType SizeType; + + // Textures tools + /** Co-occurence matrix and textures calculator */ + typedef otb::MaskedScalarImageToGreyLevelCooccurrenceMatrixGenerator + <InputImageType> CoocurrenceMatrixGeneratorType; + typedef typename CoocurrenceMatrixGeneratorType + ::Pointer CoocurrenceMatrixGeneratorPointerType; + typedef typename CoocurrenceMatrixGeneratorType + ::OffsetType OffsetType; + typedef typename CoocurrenceMatrixGeneratorType + ::HistogramType HistogramType; + typedef itk::Statistics::GreyLevelCooccurrenceMatrixTextureCoefficientsCalculator + <HistogramType> TextureCoefficientsCalculatorType; + typedef typename TextureCoefficientsCalculatorType + ::Pointer TextureCoefficientsCalculatorPointerType; + + // Output typedef support + typedef typename Superclass::OutputType OutputType; + typedef typename OutputType::ValueType ScalarRealType; + + // Coord rep + typedef TCoordRep CoordRepType; + + /** Dimension of the underlying image. */ + itkStaticConstMacro(ImageDimension, unsigned int, + InputImageType::ImageDimension); + + /** Evalulate the function at specified index */ + virtual OutputType EvaluateAtIndex(const IndexType& index) const; + + /** Evaluate the function at non-integer positions */ + virtual OutputType Evaluate(const PointType& point) const + { + IndexType index; + this->ConvertPointToNearestIndex(point, index); + return this->EvaluateAtIndex(index); + } + virtual OutputType EvaluateAtContinuousIndex( + const ContinuousIndexType& cindex) const + { + IndexType index; + this->ConvertContinuousIndexToNearestIndex(cindex, index); + return this->EvaluateAtIndex(index); + } + + /** + * Set the radius of the neighborhood over which the + * statistics are evaluated + */ + itkSetMacro( NeighborhoodRadius, unsigned int ); + /** + * Get the radius of the neighborhood over which the + * statistics are evaluated + */ + itkGetConstReferenceMacro( NeighborhoodRadius, unsigned int ); + + /** Set the offset for co-occurence computation */ + itkSetMacro(Offset, OffsetType); + + /** Get the offset for co-occurence computation */ + itkGetMacro(Offset, OffsetType); + + /** Set the number of bin per axis for histogram generation */ + itkSetMacro(NumberOfBinsPerAxis, unsigned int); + + /** Get the number of bin per axis for histogram generation */ + itkGetMacro(NumberOfBinsPerAxis, unsigned int); + + /** Set the input image minimum */ + itkSetMacro(InputImageMinimum, InputPixelType); + + /** Get the input image minimum */ + itkGetMacro(InputImageMinimum, InputPixelType); + + /** Set the input image maximum */ + itkSetMacro(InputImageMaximum, InputPixelType); + + /** Get the input image maximum */ + itkGetMacro(InputImageMaximum, InputPixelType); + +protected: + HaralickTexturesImageFunction(); + virtual ~HaralickTexturesImageFunction() {} + void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + HaralickTexturesImageFunction(const Self &); //purposely not implemented + void operator =(const Self&); //purposely not implemented + + /** Radius of the neighborhood over which to compute the textures */ + unsigned int m_NeighborhoodRadius; + + /** Offset for co-occurences generation */ + OffsetType m_Offset; + + /** Number of bins per axis for histogram generation */ + unsigned int m_NumberOfBinsPerAxis; + + /** Input image minimum */ + InputPixelType m_InputImageMinimum; + + /** Input image maximum */ + InputPixelType m_InputImageMaximum; +}; + +} // namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbHaralickTexturesImageFunction.txx" +#endif + +#endif + diff --git a/Code/FeatureExtraction/otbHaralickTexturesImageFunction.txx b/Code/FeatureExtraction/otbHaralickTexturesImageFunction.txx new file mode 100644 index 0000000000000000000000000000000000000000..54d5a05f3c3c3fa67d301da0febc2d85787ae792 --- /dev/null +++ b/Code/FeatureExtraction/otbHaralickTexturesImageFunction.txx @@ -0,0 +1,124 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbHaralickTexturesImageFunction_txx +#define __otbHaralickTexturesImageFunction_txx + +#include "otbHaralickTexturesImageFunction.h" +#include "itkConstNeighborhoodIterator.h" +#include "itkNumericTraits.h" +#include "itkMacro.h" +#include <complex> + +namespace otb +{ + +/** + * Constructor + */ +template <class TInputImage, class TCoordRep> +HaralickTexturesImageFunction<TInputImage, TCoordRep> +::HaralickTexturesImageFunction() : + m_NeighborhoodRadius(10), + m_Offset(), + m_NumberOfBinsPerAxis(8), + m_InputImageMinimum(0), + m_InputImageMaximum(256) +{} + +template <class TInputImage, class TCoordRep> +void +HaralickTexturesImageFunction<TInputImage, TCoordRep> +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + this->Superclass::PrintSelf(os, indent); + os << indent << " Neighborhood radius value : " << m_NeighborhoodRadius << std::endl; +} + +template <class TInputImage, class TCoordRep> +typename HaralickTexturesImageFunction<TInputImage,TCoordRep>::OutputType +HaralickTexturesImageFunction<TInputImage,TCoordRep> +::EvaluateAtIndex(const IndexType& index) const +{ + // Build textures vector + OutputType textures; + + // Initialize textures + textures.Fill( itk::NumericTraits< ScalarRealType >::Zero ); + + // Check for input image + if( !this->GetInputImage() ) + { + return textures; + } + + // Check for out of buffer + if ( !this->IsInsideBuffer( index ) ) + { + return textures; + } + + // Build the co-occurence matrix generator + CoocurrenceMatrixGeneratorPointerType coOccurenceMatrixGenerator = CoocurrenceMatrixGeneratorType::New(); + coOccurenceMatrixGenerator->SetInput(this->GetInputImage()); + coOccurenceMatrixGenerator->SetOffset(m_Offset); + coOccurenceMatrixGenerator->SetNumberOfBinsPerAxis(m_NumberOfBinsPerAxis); + coOccurenceMatrixGenerator->SetPixelValueMinMax(m_InputImageMinimum, m_InputImageMaximum); + + // Compute the region on which co-occurence will be estimated + typename InputRegionType::IndexType inputIndex = index; + for(unsigned int dim = 0; dim<InputImageType::ImageDimension;++dim) + { + inputIndex[dim]-= m_NeighborhoodRadius; + } + typename InputRegionType::SizeType inputSize; + inputSize.Fill(2*m_NeighborhoodRadius+1); + + // Build the input region + InputRegionType inputRegion; + inputRegion.SetIndex(inputIndex); + inputRegion.SetSize(inputSize); + + // Compute the co-occurence matrix + coOccurenceMatrixGenerator->SetRegion(inputRegion); + coOccurenceMatrixGenerator->SetNormalize(true); + coOccurenceMatrixGenerator->Compute(); + + // Build the texture calculator + TextureCoefficientsCalculatorPointerType texturesCalculator = TextureCoefficientsCalculatorType::New(); + + // Compute textures indices + texturesCalculator->SetHistogram(coOccurenceMatrixGenerator->GetOutput()); + texturesCalculator->Compute(); + + // Fill the output vector + textures[0]=texturesCalculator->GetEnergy(); + textures[1]=texturesCalculator->GetEntropy(); + textures[2]=texturesCalculator->GetCorrelation(); + textures[3]=texturesCalculator->GetInverseDifferenceMoment(); + textures[4]=texturesCalculator->GetInertia(); + textures[5]=texturesCalculator->GetClusterShade(); + textures[6]=texturesCalculator->GetClusterProminence(); + textures[7]=texturesCalculator->GetHaralickCorrelation(); + + // Return result + return textures; +} + +} // namespace otb + +#endif diff --git a/Code/FeatureExtraction/otbHuMomentsImageFunction.h b/Code/FeatureExtraction/otbHuMomentsImageFunction.h index 6428f41d356a3aa11dacb784d81261f106f1ca74..954f5437fb44cd0e8650973b1510549ca9a8eb0c 100644 --- a/Code/FeatureExtraction/otbHuMomentsImageFunction.h +++ b/Code/FeatureExtraction/otbHuMomentsImageFunction.h @@ -89,6 +89,8 @@ public: typedef typename Superclass::OutputType OutputType; typedef typename OutputType::ValueType ScalarRealType; + typedef TCoordRep CoordRepType; + /** Dimension of the underlying image. */ itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); diff --git a/Code/FeatureExtraction/otbImageFunctionAdapter.h b/Code/FeatureExtraction/otbImageFunctionAdapter.h deleted file mode 100644 index e66a57bda16d77b24d45b036b0ae6f954c7c5aa6..0000000000000000000000000000000000000000 --- a/Code/FeatureExtraction/otbImageFunctionAdapter.h +++ /dev/null @@ -1,493 +0,0 @@ -/*========================================================================= - - Program: ORFEO Toolbox - Language: C++ - Date: $Date$ - Version: $Revision$ - - - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. - See OTBCopyright.txt for details. - - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __otbImageFunctionAdapter_h -#define __otbImageFunctionAdapter_h - -#include "itkImageFunction.h" -#include "itkNumericTraits.h" - -#include "otbFourierMellinDescriptorsImageFunction.h" -#include "otbRealMomentsImageFunction.h" -#include "otbComplexMomentsImageFunction.h" -#include "otbFlusserMomentsImageFunction.h" -#include "otbHuMomentsImageFunction.h" -#include "otbRadiometricMomentsImageFunction.h" -#include "otbLocalHistogramImageFunction.h" - -#include <complex> - -namespace otb -{ - - -template< class TInputImage, class TInternalImageFunctionType, class TCoordRep = double > -class ITK_EXPORT ImageFunctionAdapterBase : - public itk::ImageFunction< TInputImage, - itk::VariableLengthVector< - ITK_TYPENAME itk::NumericTraits<typename TInputImage::PixelType> - ::RealType >, - TCoordRep > -{ - public: - // Standard class typedefs. // - typedef ImageFunctionAdapterBase Self; - typedef itk::ImageFunction< TInputImage, - itk::VariableLengthVector< - ITK_TYPENAME itk::NumericTraits<typename TInputImage::PixelType> - ::RealType >, - TCoordRep > Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - // Run-time type information (and related methods). // - itkTypeMacro(ImageFunctionAdapterBase, ImageFunction); - - // Method for creation through the object factory. // - itkNewMacro(Self); - - // InputImageType typedef support. // - typedef TInputImage InputImageType; - typedef typename Superclass::IndexType IndexType; - typedef typename Superclass::ContinuousIndexType ContinuousIndexType; - typedef typename Superclass::PointType PointType; - typedef typename Superclass::OutputType OutputType; - typedef typename OutputType::ValueType OutputValueType; - - // Template Partial Specialization Specific typedef // - typedef TInternalImageFunctionType InternalImageFunctionType; - typedef typename InternalImageFunctionType::Pointer InternalImageFunctionPointerType; - - // Dimension of the underlying image. // - itkStaticConstMacro(ImageDimension, unsigned int, - InputImageType::ImageDimension); - - // Evalulate the function at specified index // - virtual OutputType EvaluateAtIndex(const IndexType& index) const - { - OutputType result; - - result.SetSize(1); - - result[0] = 0.0; - - return result; - }; - - // Evaluate the function at non-integer positions // - virtual OutputType Evaluate(const PointType& point) const - { - IndexType index; - this->ConvertPointToNearestIndex(point, index); - return this->EvaluateAtIndex(index); - } - virtual OutputType EvaluateAtContinuousIndex( - const ContinuousIndexType& cindex) const - { - IndexType index; - this->ConvertContinuousIndexToNearestIndex(cindex, index); - return this->EvaluateAtIndex(index); - } - - // Get/Set the internal image function // - InternalImageFunctionPointerType GetImageFunction() const - { - return m_ImageFunction; - } - -protected: - ImageFunctionAdapterBase() - { - m_ImageFunction = InternalImageFunctionType::New(); - } - - virtual ~ImageFunctionAdapterBase() {} - void PrintSelf(std::ostream& os, itk::Indent indent) const - { - Superclass::PrintSelf(os, indent); - os << indent << "Internal Image Function: " << m_ImageFunction << std::endl; - } - -private: - ImageFunctionAdapterBase(const Self &); //purposely not implemented - void operator =(const Self&); //purposely not implemented - - // Internal Image Function // - InternalImageFunctionPointerType m_ImageFunction; -}; - - -// ----- Template Partial Specialization ----- // - -//Dummy -template< class TInputImage, class TInternalImageFunctionType, class TCoordRep = double > -class ITK_EXPORT ImageFunctionAdapter : - public otb::ImageFunctionAdapterBase< TInputImage, - TInternalImageFunctionType, - TCoordRep > -{ -public: - typedef ImageFunctionAdapter Self; - typedef ImageFunctionAdapterBase< TInputImage, - TInternalImageFunctionType, - TCoordRep > Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - itkTypeMacro(ImageFunctionAdapter, ImageFunction); - itkNewMacro(Self); - typedef typename Superclass::IndexType IndexType; - typedef typename Superclass::ContinuousIndexType ContinuousIndexType; - typedef typename Superclass::OutputType OutputType; - typedef typename Superclass::InternalImageFunctionType InternalImageFunctionType; - - virtual OutputType EvaluateAtIndex(const IndexType& index) const; - -protected: - ImageFunctionAdapter() {} - virtual ~ImageFunctionAdapter() {} - void PrintSelf(std::ostream& os, itk::Indent indent) const; - -private: - ImageFunctionAdapter(const Self &); //purposely not implemented - void operator =(const Self&); //purposely not implemented -}; - - -//FourierMellinDescriptors -template< class TInputImage, class TCoordRep > -class ITK_EXPORT ImageFunctionAdapter< TInputImage, - otb::FourierMellinDescriptorsImageFunction<TInputImage, TCoordRep>, - TCoordRep > : - public otb::ImageFunctionAdapterBase< TInputImage, - FourierMellinDescriptorsImageFunction< - TInputImage, - TCoordRep >, - TCoordRep > -{ -public: - // Standard class typedefs. // - typedef ImageFunctionAdapter Self; - typedef ImageFunctionAdapterBase< TInputImage, - FourierMellinDescriptorsImageFunction< - TInputImage, - TCoordRep >, - TCoordRep > Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - // Run-time type information (and related methods). // - itkTypeMacro(ImageFunctionAdapter, ImageFunction); - // Method for creation through the object factory. // - itkNewMacro(Self); - // Usefull typedefs // - typedef typename Superclass::IndexType IndexType; - typedef typename Superclass::ContinuousIndexType ContinuousIndexType; - typedef typename Superclass::OutputType OutputType; - // Template Partial Specialization Specific typedef // - typedef typename Superclass::InternalImageFunctionType InternalImageFunctionType; - - // Evalulate the function at specified index // - virtual OutputType EvaluateAtIndex(const IndexType& index) const; - -protected: - ImageFunctionAdapter() {} - virtual ~ImageFunctionAdapter() {} - void PrintSelf(std::ostream& os, itk::Indent indent) const; - -private: - ImageFunctionAdapter(const Self &); //purposely not implemented - void operator =(const Self&); //purposely not implemented -}; - -//RealMoments -template< class TInputImage, class TCoordRep > -class ITK_EXPORT ImageFunctionAdapter< TInputImage, - otb::RealMomentsImageFunction<TInputImage, TCoordRep>, - TCoordRep > : - public otb::ImageFunctionAdapterBase< TInputImage, - RealMomentsImageFunction< - TInputImage, - TCoordRep >, - TCoordRep > -{ -public: - // Standard class typedefs. // - typedef ImageFunctionAdapter Self; - typedef ImageFunctionAdapterBase< TInputImage, - RealMomentsImageFunction< - TInputImage, - TCoordRep >, - TCoordRep > Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - // Run-time type information (and related methods). // - itkTypeMacro(ImageFunctionAdapter, ImageFunction); - // Method for creation through the object factory. // - itkNewMacro(Self); - // Usefull typedefs // - typedef typename Superclass::IndexType IndexType; - typedef typename Superclass::ContinuousIndexType ContinuousIndexType; - typedef typename Superclass::OutputType OutputType; - // Template Partial Specialization Specific typedef // - typedef typename Superclass::InternalImageFunctionType InternalImageFunctionType; - - // Evalulate the function at specified index // - virtual OutputType EvaluateAtIndex(const IndexType& index) const; - -protected: - ImageFunctionAdapter() {} - virtual ~ImageFunctionAdapter() {} - void PrintSelf(std::ostream& os, itk::Indent indent) const; - -private: - ImageFunctionAdapter(const Self &); //purposely not implemented - void operator =(const Self&); //purposely not implemented -}; - -//ComplexMoments -template< class TInputImage, class TCoordRep > -class ITK_EXPORT ImageFunctionAdapter< TInputImage, - otb::ComplexMomentsImageFunction< TInputImage, TCoordRep>, - TCoordRep > : - public otb::ImageFunctionAdapterBase< TInputImage, - ComplexMomentsImageFunction< - TInputImage, - TCoordRep >, - TCoordRep > -{ -public: - // Standard class typedefs. // - typedef ImageFunctionAdapter Self; - typedef ImageFunctionAdapterBase< TInputImage, - ComplexMomentsImageFunction< - TInputImage, - TCoordRep >, - TCoordRep > Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - // Run-time type information (and related methods). // - itkTypeMacro(ImageFunctionAdapter, ImageFunction); - // Method for creation through the object factory. // - itkNewMacro(Self); - // Usefull typedefs // - typedef typename Superclass::IndexType IndexType; - typedef typename Superclass::ContinuousIndexType ContinuousIndexType; - typedef typename Superclass::OutputType OutputType; - // Template Partial Specialization Specific typedef // - typedef typename Superclass::InternalImageFunctionType InternalImageFunctionType; - - // Evalulate the function at specified index // - virtual OutputType EvaluateAtIndex(const IndexType& index) const; - -protected: - ImageFunctionAdapter() {} - virtual ~ImageFunctionAdapter() {} - void PrintSelf(std::ostream& os, itk::Indent indent) const; - -private: - ImageFunctionAdapter(const Self &); //purposely not implemented - void operator =(const Self&); //purposely not implemented -}; - -//FlusserMoments -template< class TInputImage, class TCoordRep > -class ITK_EXPORT ImageFunctionAdapter< TInputImage, - otb::FlusserMomentsImageFunction< TInputImage, TCoordRep>, - TCoordRep > : - public otb::ImageFunctionAdapterBase< TInputImage, - FlusserMomentsImageFunction< - TInputImage, - TCoordRep >, - TCoordRep > -{ -public: - // Standard class typedefs. // - typedef ImageFunctionAdapter Self; - typedef ImageFunctionAdapterBase< TInputImage, - FlusserMomentsImageFunction< - TInputImage, - TCoordRep >, - TCoordRep > Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - // Run-time type information (and related methods). // - itkTypeMacro(ImageFunctionAdapter, ImageFunction); - // Method for creation through the object factory. // - itkNewMacro(Self); - // Usefull typedefs // - typedef typename Superclass::IndexType IndexType; - typedef typename Superclass::ContinuousIndexType ContinuousIndexType; - typedef typename Superclass::OutputType OutputType; - // Template Partial Specialization Specific typedef // - typedef typename Superclass::InternalImageFunctionType InternalImageFunctionType; - - // Evalulate the function at specified index // - virtual OutputType EvaluateAtIndex(const IndexType& index) const; - -protected: - ImageFunctionAdapter() {}; - virtual ~ImageFunctionAdapter() {}; - void PrintSelf(std::ostream& os, itk::Indent indent) const; - -private: - ImageFunctionAdapter(const Self &); //purposely not implemented - void operator =(const Self&); //purposely not implemented -}; - -//HuMoments -template< class TInputImage, class TCoordRep > -class ITK_EXPORT ImageFunctionAdapter< TInputImage, - otb::HuMomentsImageFunction< TInputImage, TCoordRep>, - TCoordRep > : - public otb::ImageFunctionAdapterBase< TInputImage, - HuMomentsImageFunction< - TInputImage, - TCoordRep >, - TCoordRep > -{ -public: - // Standard class typedefs. // - typedef ImageFunctionAdapter Self; - typedef ImageFunctionAdapterBase< TInputImage, - HuMomentsImageFunction< - TInputImage, - TCoordRep >, - TCoordRep > Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - // Run-time type information (and related methods). // - itkTypeMacro(ImageFunctionAdapter, ImageFunction); - // Method for creation through the object factory. // - itkNewMacro(Self); - // Usefull typedefs // - typedef typename Superclass::IndexType IndexType; - typedef typename Superclass::ContinuousIndexType ContinuousIndexType; - typedef typename Superclass::OutputType OutputType; - // Template Partial Specialization Specific typedef // - typedef typename Superclass::InternalImageFunctionType InternalImageFunctionType; - - // Evalulate the function at specified index // - virtual OutputType EvaluateAtIndex(const IndexType& index) const; - -protected: - ImageFunctionAdapter() {} - virtual ~ImageFunctionAdapter() {} - void PrintSelf(std::ostream& os, itk::Indent indent) const; - -private: - ImageFunctionAdapter(const Self &); //purposely not implemented - void operator =(const Self&); //purposely not implemented -}; - -//RadiometricMoments -template< class TInputImage, class TCoordRep > -class ITK_EXPORT ImageFunctionAdapter< TInputImage, - otb::RadiometricMomentsImageFunction< TInputImage, TCoordRep>, - TCoordRep > : - public otb::ImageFunctionAdapterBase< TInputImage, - RadiometricMomentsImageFunction< - TInputImage, - TCoordRep >, - TCoordRep > -{ -public: - // Standard class typedefs. // - typedef ImageFunctionAdapter Self; - typedef ImageFunctionAdapterBase< TInputImage, - RadiometricMomentsImageFunction< - TInputImage, - TCoordRep >, - TCoordRep > Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - // Run-time type information (and related methods). // - itkTypeMacro(ImageFunctionAdapter, ImageFunction); - // Method for creation through the object factory. // - itkNewMacro(Self); - // Usefull typedefs // - typedef typename Superclass::IndexType IndexType; - typedef typename Superclass::ContinuousIndexType ContinuousIndexType; - typedef typename Superclass::OutputType OutputType; - // Template Partial Specialization Specific typedef // - typedef typename Superclass::InternalImageFunctionType InternalImageFunctionType; - - // Evalulate the function at specified index // - virtual OutputType EvaluateAtIndex(const IndexType& index) const; - -protected: - ImageFunctionAdapter() {} - virtual ~ImageFunctionAdapter() {} - void PrintSelf(std::ostream& os, itk::Indent indent) const; - -private: - ImageFunctionAdapter(const Self &); //purposely not implemented - void operator =(const Self&); //purposely not implemented -}; - - -//LocalHistogram -template< class TInputImage, class TCoordRep > -class ITK_EXPORT ImageFunctionAdapter< TInputImage, - otb::LocalHistogramImageFunction< TInputImage, TCoordRep>, - TCoordRep > : - public otb::ImageFunctionAdapterBase< TInputImage, - LocalHistogramImageFunction< - TInputImage, - TCoordRep >, - TCoordRep > -{ -public: - // Standard class typedefs. // - typedef ImageFunctionAdapter Self; - typedef ImageFunctionAdapterBase< TInputImage, - LocalHistogramImageFunction< - TInputImage, - TCoordRep >, - TCoordRep > Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - // Run-time type information (and related methods). - itkTypeMacro(ImageFunctionAdapter, ImageFunction); - // Method for creation through the object factory. - itkNewMacro(Self); - // Usefull typedefs // - typedef typename Superclass::IndexType IndexType; - typedef typename Superclass::ContinuousIndexType ContinuousIndexType; - typedef typename Superclass::OutputType OutputType; - // Template Partial Specialization Specific typedef - typedef typename Superclass::InternalImageFunctionType InternalImageFunctionType; - - // Evalulate the function at specified index // - virtual OutputType EvaluateAtIndex(const IndexType& index) const; - -protected: - ImageFunctionAdapter() {} - virtual ~ImageFunctionAdapter() {} - void PrintSelf(std::ostream& os, itk::Indent indent) const; - -private: - ImageFunctionAdapter(const Self &); //purposely not implemented - void operator =(const Self&); //purposely not implemented -}; - - -} // end namespace otb - -#ifndef OTB_MANUAL_INSTANTIATION -#include "otbImageFunctionAdapter.txx" -#endif - -#endif diff --git a/Code/FeatureExtraction/otbImageFunctionAdapter.txx b/Code/FeatureExtraction/otbImageFunctionAdapter.txx deleted file mode 100644 index 1b55cd7edae2bcd4648d89ef836bf314b1f00181..0000000000000000000000000000000000000000 --- a/Code/FeatureExtraction/otbImageFunctionAdapter.txx +++ /dev/null @@ -1,342 +0,0 @@ -/*========================================================================= - - Program: ORFEO Toolbox - Language: C++ - Date: $Date$ - Version: $Revision$ - - - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. - See OTBCopyright.txt for details. - - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __otbImageFunctionAdapter_txx -#define __otbImageFunctionAdapter_txx - -#include "otbImageFunctionAdapter.h" - -namespace otb -{ -/** ----- Template Partial Specialization ----- **/ -// Dummy -template <class TInputImage, class TInternalImageFunctionType, class TCoordRep> -typename ImageFunctionAdapter<TInputImage, TInternalImageFunctionType, TCoordRep >::OutputType -ImageFunctionAdapter <TInputImage, TInternalImageFunctionType, TCoordRep > -::EvaluateAtIndex(const IndexType& index) const -{ - OutputType result; - result.SetSize(1); - result[0] = 0.0; - return result; -} -template <class TInputImage, class TInternalImageFunctionType, class TCoordRep > -void -ImageFunctionAdapter <TInputImage, TInternalImageFunctionType, TCoordRep > -::PrintSelf(std::ostream& os, itk::Indent indent) const -{ - Superclass::PrintSelf(os, indent); -} - - -// Fourier-Mellin Descriptors -template <class TInputImage, class TCoordRep> -typename ImageFunctionAdapter<TInputImage, - FourierMellinDescriptorsImageFunction< TInputImage, TCoordRep >, - TCoordRep >::OutputType -ImageFunctionAdapter<TInputImage, - FourierMellinDescriptorsImageFunction< TInputImage, TCoordRep >, - TCoordRep > -::EvaluateAtIndex(const IndexType& index) const -{ - unsigned int p, q, rsltIdx = 0; - OutputType result; - - p = this->GetImageFunction()->GetPmax(); - q = this->GetImageFunction()->GetQmax(); - - result.SetSize((p+1)*(q+1)); - - typename InternalImageFunctionType::OutputType tmpResult; - this->GetImageFunction()->SetInputImage(this->GetInputImage()); - tmpResult = this->GetImageFunction()->EvaluateAtIndex(index); - - for (unsigned int i=0; i<=p; i++) - { - for (unsigned int j=0; j<=q; j++) - { - result[rsltIdx] = tmpResult.at(i).at(j); - rsltIdx ++; - } - } - - return result; -} - -template <class TInputImage, class TCoordRep> -void -ImageFunctionAdapter<TInputImage, - FourierMellinDescriptorsImageFunction< TInputImage, TCoordRep >, - TCoordRep > -::PrintSelf(std::ostream& os, itk::Indent indent) const -{ - Superclass::PrintSelf(os, indent); -} - - -// Real Moments -template <class TInputImage, class TCoordRep> -typename ImageFunctionAdapter<TInputImage, - RealMomentsImageFunction< TInputImage, TCoordRep >, - TCoordRep >::OutputType -ImageFunctionAdapter<TInputImage, - RealMomentsImageFunction< TInputImage, TCoordRep >, - TCoordRep > -::EvaluateAtIndex(const IndexType& index) const -{ - unsigned int p, q, rsltIdx = 0; - OutputType result; - - p = this->GetImageFunction()->GetPmax(); - q = this->GetImageFunction()->GetQmax(); - - result.SetSize((p+1)*(q+1)); - - typename InternalImageFunctionType::OutputType tmpResult; - this->GetImageFunction()->SetInputImage(this->GetInputImage()); - tmpResult = this->GetImageFunction()->EvaluateAtIndex(index); - - for (unsigned int i=0; i<=p; i++) - { - for (unsigned int j=0; j<=q; j++) - { - result[rsltIdx] = tmpResult.at(i).at(j); - rsltIdx ++; - } - } - - return result; -} - -template <class TInputImage, class TCoordRep> -void -ImageFunctionAdapter<TInputImage, - RealMomentsImageFunction< TInputImage, TCoordRep >, - TCoordRep > -::PrintSelf(std::ostream& os, itk::Indent indent) const -{ - Superclass::PrintSelf(os, indent); -} - - -//Complex Moments -template <class TInputImage, class TCoordRep> -typename ImageFunctionAdapter<TInputImage, - ComplexMomentsImageFunction< TInputImage, TCoordRep >, - TCoordRep >::OutputType -ImageFunctionAdapter<TInputImage, - ComplexMomentsImageFunction< TInputImage, TCoordRep >, - TCoordRep > -::EvaluateAtIndex(const IndexType& index) const -{ - unsigned int p, q, rsltIdx = 0; - OutputType result; - - p = this->GetImageFunction()->GetPmax(); - q = this->GetImageFunction()->GetQmax(); - - result.SetSize((p+1)*(q+1)*2); - - typename InternalImageFunctionType::OutputType tmpResult; - this->GetImageFunction()->SetInputImage(this->GetInputImage()); - tmpResult = this->GetImageFunction()->EvaluateAtIndex(index); - - for (unsigned int i=0; i<=p; i++) - { - for (unsigned int j=0; j<=q; j++) - { - result[rsltIdx] = tmpResult.at(i).at(j).real(); - rsltIdx ++; - result[rsltIdx] = tmpResult.at(i).at(j).imag(); - rsltIdx ++; - } - } - - return result; -} - -template <class TInputImage, class TCoordRep> -void -ImageFunctionAdapter<TInputImage, - ComplexMomentsImageFunction< TInputImage, TCoordRep >, - TCoordRep > -::PrintSelf(std::ostream& os, itk::Indent indent) const -{ - Superclass::PrintSelf(os, indent); -} - - -//Flusser Moments -template <class TInputImage, class TCoordRep> -typename ImageFunctionAdapter<TInputImage, - FlusserMomentsImageFunction< TInputImage, TCoordRep >, - TCoordRep >::OutputType -ImageFunctionAdapter<TInputImage, - FlusserMomentsImageFunction< TInputImage, TCoordRep >, - TCoordRep > -::EvaluateAtIndex(const IndexType& index) const -{ - unsigned int rsltIdx = 0; - OutputType result; - - result.SetSize(11); - - typename InternalImageFunctionType::OutputType tmpResult; - this->GetImageFunction()->SetInputImage(this->GetInputImage()); - tmpResult = this->GetImageFunction()->EvaluateAtIndex(index); - - for (unsigned int i=0; i<11; i++) - { - result[rsltIdx] = tmpResult[i]; - rsltIdx ++; - } - - return result; -} - -template <class TInputImage, class TCoordRep> -void -ImageFunctionAdapter<TInputImage, - FlusserMomentsImageFunction<TInputImage, TCoordRep >, - TCoordRep > -::PrintSelf(std::ostream& os, itk::Indent indent) const -{ - Superclass::PrintSelf(os, indent); -} - - -//Hu Moments -template <class TInputImage, class TCoordRep> -typename ImageFunctionAdapter<TInputImage, - HuMomentsImageFunction< TInputImage, TCoordRep >, - TCoordRep >::OutputType -ImageFunctionAdapter<TInputImage, - HuMomentsImageFunction< TInputImage, TCoordRep >, - TCoordRep > -::EvaluateAtIndex(const IndexType& index) const -{ - unsigned int rsltIdx = 0; - OutputType result; - - result.SetSize(7); - - typename InternalImageFunctionType::OutputType tmpResult; - this->GetImageFunction()->SetInputImage(this->GetInputImage()); - tmpResult = this->GetImageFunction()->EvaluateAtIndex(index); - - for (unsigned int i=0; i<7; i++) - { - result[rsltIdx] = tmpResult[i]; - rsltIdx ++; - } - - return result; -} - -template <class TInputImage, class TCoordRep> -void -ImageFunctionAdapter<TInputImage, - HuMomentsImageFunction< TInputImage, TCoordRep >, - TCoordRep > -::PrintSelf(std::ostream& os, itk::Indent indent) const -{ - Superclass::PrintSelf(os, indent); -} - - -//Radiometric Moments -template <class TInputImage, class TCoordRep> -typename ImageFunctionAdapter<TInputImage, - RadiometricMomentsImageFunction< TInputImage, TCoordRep >, - TCoordRep >::OutputType -ImageFunctionAdapter<TInputImage, - RadiometricMomentsImageFunction< TInputImage, TCoordRep >, - TCoordRep > -::EvaluateAtIndex(const IndexType& index) const -{ - unsigned int rsltIdx = 0; - OutputType result; - - result.SetSize(4); - - typename InternalImageFunctionType::OutputType tmpResult; - this->GetImageFunction()->SetInputImage(this->GetInputImage()); - tmpResult = this->GetImageFunction()->EvaluateAtIndex(index); - - for (unsigned int i=0; i<4; i++) - { - result[rsltIdx] = tmpResult[i]; - rsltIdx ++; - } - - return result; -} - -template <class TInputImage, class TCoordRep> -void -ImageFunctionAdapter<TInputImage, - RadiometricMomentsImageFunction< TInputImage, TCoordRep >, - TCoordRep > -::PrintSelf(std::ostream& os, itk::Indent indent) const -{ - Superclass::PrintSelf(os, indent); -} - - -//Local Histogramm -template <class TInputImage, class TCoordRep> -typename ImageFunctionAdapter<TInputImage, - LocalHistogramImageFunction< TInputImage, TCoordRep >, - TCoordRep >::OutputType -ImageFunctionAdapter<TInputImage, - LocalHistogramImageFunction< TInputImage, TCoordRep >, - TCoordRep > -::EvaluateAtIndex(const IndexType& index) const -{ - unsigned int nbBins, rsltIdx = 0; - OutputType result; - - nbBins = this->GetImageFunction()->GetNumberOfHistogramBins(); - - result.SetSize(nbBins); - - typename InternalImageFunctionType::OutputType tmpResult; - this->GetImageFunction()->SetInputImage(this->GetInputImage()); - tmpResult = this->GetImageFunction()->EvaluateAtIndex(index); - - for (unsigned int i=0; i<nbBins; i++) - { - result[rsltIdx] = tmpResult->GetFrequency(i); - rsltIdx ++; - } - - return result; -} - -template <class TInputImage, class TCoordRep> -void -ImageFunctionAdapter<TInputImage, - LocalHistogramImageFunction< TInputImage, TCoordRep >, - TCoordRep > -::PrintSelf(std::ostream& os, itk::Indent indent) const -{ - Superclass::PrintSelf(os, indent); -} - -} // end namespace otb - -#endif diff --git a/Code/FeatureExtraction/otbImageFunctionAdaptor.h b/Code/FeatureExtraction/otbImageFunctionAdaptor.h new file mode 100644 index 0000000000000000000000000000000000000000..bf392fddfc0a78416ab371fecffbe7685544a6ff --- /dev/null +++ b/Code/FeatureExtraction/otbImageFunctionAdaptor.h @@ -0,0 +1,122 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbImageFunctionAdaptor_h +#define __otbImageFunctionAdaptor_h + +#include "itkImageFunction.h" +#include "itkNumericTraits.h" + +#include "otbVariableLengthVectorConverter.h" + + +#include <complex> + +namespace otb +{ + + +template< class TInternalImageFunctionType > +class ITK_EXPORT ImageFunctionAdaptor : + public itk::ImageFunction< typename TInternalImageFunctionType::InputImageType, + itk::VariableLengthVector< + ITK_TYPENAME itk::NumericTraits<typename TInternalImageFunctionType::InputImageType::PixelType> + ::RealType >, + typename TInternalImageFunctionType::CoordRepType > +{ + public: + // Standard class typedefs. // + typedef ImageFunctionAdaptor Self; + typedef itk::ImageFunction< typename TInternalImageFunctionType::InputImageType, + itk::VariableLengthVector< + ITK_TYPENAME itk::NumericTraits<typename TInternalImageFunctionType::InputImageType::PixelType> + ::RealType >, + typename TInternalImageFunctionType::CoordRepType > + Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + // Run-time type information (and related methods). // + itkTypeMacro(ImageFunctionAdaptor, ImageFunction); + + // Method for creation through the object factory. // + itkNewMacro(Self); + + // InputImageType typedef support. // + typedef typename TInternalImageFunctionType::InputImageType InputImageType; + typedef typename TInternalImageFunctionType::CoordRepType CoordRepType; + typedef typename Superclass::IndexType IndexType; + typedef typename Superclass::ContinuousIndexType ContinuousIndexType; + typedef typename Superclass::PointType PointType; + typedef typename Superclass::OutputType OutputType; + typedef typename OutputType::ValueType OutputValueType; + + // InternalImageFunction related typedefs // + typedef TInternalImageFunctionType InternalImageFunctionType; + typedef typename InternalImageFunctionType::OutputType InternalImageFunctionOutputType; + + // Converter related typedefs // + typedef VariableLengthVectorConverter<InternalImageFunctionOutputType, double> ConverterType; + + + // Dimension of the underlying image. // + itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); + + // Evalulate the function at specified index // + virtual OutputType EvaluateAtIndex(const IndexType& index) const; + + // Evaluate the function at non-integer positions // + virtual OutputType Evaluate(const PointType& point) const + { + IndexType index; + this->ConvertPointToNearestIndex(point, index); + return this->EvaluateAtIndex(index); + } + virtual OutputType EvaluateAtContinuousIndex( + const ContinuousIndexType& cindex) const + { + IndexType index; + this->ConvertContinuousIndexToNearestIndex(cindex, index); + return this->EvaluateAtIndex(index); + } + + // Accessors // + itkGetConstMacro(InternalImageFunction, typename InternalImageFunctionType::Pointer); + itkSetMacro(InternalImageFunction, typename InternalImageFunctionType::Pointer); + +protected: + ImageFunctionAdaptor(); + virtual ~ImageFunctionAdaptor() {} + void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + ImageFunctionAdaptor(const Self &); //purposely not implemented + void operator =(const Self&); //purposely not implemented + + // Internal Image Function // + typename InternalImageFunctionType::Pointer m_InternalImageFunction; + // Converter // + typename ConverterType::Pointer m_Converter; +}; + +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbImageFunctionAdaptor.txx" +#endif + +#endif diff --git a/Code/FeatureExtraction/otbImageFunctionAdaptor.txx b/Code/FeatureExtraction/otbImageFunctionAdaptor.txx new file mode 100644 index 0000000000000000000000000000000000000000..62a1437d1419ee56559017189bba046b0e1feb1b --- /dev/null +++ b/Code/FeatureExtraction/otbImageFunctionAdaptor.txx @@ -0,0 +1,58 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbImageFunctionAdaptor_txx +#define __otbImageFunctionAdaptor_txx + +#include "otbImageFunctionAdaptor.h" + +namespace otb +{ +template< class TInternalImageFunctionType > +ImageFunctionAdaptor< TInternalImageFunctionType > +::ImageFunctionAdaptor() +{ + m_InternalImageFunction = InternalImageFunctionType::New(); + m_Converter = ConverterType::New(); +} + +template< class TInternalImageFunctionType > +void +ImageFunctionAdaptor< TInternalImageFunctionType > +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + Superclass::PrintSelf(os, indent); + os << indent << "Internal Image Function: " << m_InternalImageFunction << std::endl; +} + +template< class TInternalImageFunctionType > +typename ImageFunctionAdaptor< TInternalImageFunctionType >::OutputType +ImageFunctionAdaptor< TInternalImageFunctionType > +::EvaluateAtIndex(const IndexType& index) const +{ + OutputType result; + this->GetInternalImageFunction()->SetInputImage(this->GetInputImage()); + InternalImageFunctionOutputType tmpResult = this->GetInternalImageFunction()->EvaluateAtIndex(index); + result = m_Converter->Convert(tmpResult); + + return result; +} + + +} // end namespace otb + +#endif diff --git a/Code/FeatureExtraction/otbLocalHistogramImageFunction.h b/Code/FeatureExtraction/otbLocalHistogramImageFunction.h index 3989b474c32ed27906d96cea3922baa5ef82fccc..821cdab3d1674088e4ddcdeb83d6c00c9fafe1bc 100644 --- a/Code/FeatureExtraction/otbLocalHistogramImageFunction.h +++ b/Code/FeatureExtraction/otbLocalHistogramImageFunction.h @@ -68,6 +68,8 @@ public: typedef itk::Statistics::Histogram<typename TInputImage::PixelType> HistogramType; typedef typename HistogramType::Pointer HistogramPointer; + typedef TCoordRep CoordRepType; + /** Dimension of the underlying image. */ itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); diff --git a/Code/FeatureExtraction/otbMetaImageFunction.txx b/Code/FeatureExtraction/otbMetaImageFunction.txx index 94239e2ba64cb89374e04f27b979c9bb0bd048ff..197c08faba0ad2597994febd79468023035b69db 100644 --- a/Code/FeatureExtraction/otbMetaImageFunction.txx +++ b/Code/FeatureExtraction/otbMetaImageFunction.txx @@ -19,7 +19,7 @@ #define __otbMetaImageFunction_txx #include "otbMetaImageFunction.h" -#include "otbImageFunctionAdapter.h" +#include "otbImageFunctionAdaptor.h" #include <algorithm> diff --git a/Code/FeatureExtraction/otbRadiometricMomentsImageFunction.h b/Code/FeatureExtraction/otbRadiometricMomentsImageFunction.h index 4bb775f9f94e06d2df52f68eb0164ffd334b7a9c..f7cc6d5454ae12ab416c905a559f3ccf5bc5ea12 100644 --- a/Code/FeatureExtraction/otbRadiometricMomentsImageFunction.h +++ b/Code/FeatureExtraction/otbRadiometricMomentsImageFunction.h @@ -72,6 +72,8 @@ public: typedef typename Superclass::OutputType OutputType; typedef typename OutputType::ValueType ScalarRealType; + typedef TCoordRep CoordRepType; + /** Dimension of the underlying image. */ itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); diff --git a/Code/FeatureExtraction/otbRealMomentsImageFunction.h b/Code/FeatureExtraction/otbRealMomentsImageFunction.h index 39d297cec9a6b04b3938f92da7dae5fb8578c143..1534dc35ec9d906398a63d2d0d4e32157d81548d 100644 --- a/Code/FeatureExtraction/otbRealMomentsImageFunction.h +++ b/Code/FeatureExtraction/otbRealMomentsImageFunction.h @@ -67,6 +67,8 @@ public: typedef typename Superclass::OutputType OutputType; typedef float ScalarRealType; + typedef TCoordRep CoordRepType; + /** Dimension of the underlying image. */ itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); diff --git a/Code/Learning/otbListSampleToBalancedListSampleFilter.h b/Code/Learning/otbListSampleToBalancedListSampleFilter.h index 38da0e2e6477dba219bd2c3cc0be65a9945514e6..185a68a43a147af2f0eca0760d01f9437a3e0b92 100644 --- a/Code/Learning/otbListSampleToBalancedListSampleFilter.h +++ b/Code/Learning/otbListSampleToBalancedListSampleFilter.h @@ -81,10 +81,13 @@ public: typedef typename OutputSampleListType::MeasurementVectorType OutputMeasurementVectorType; typedef typename OutputMeasurementVectorType::ValueType OutputValueType; + /** DataObject typedef*/ + typedef typename Superclass::DataObjectPointer DataObjectPointer; + /** Input & Output sample list as data object */ typedef typename Superclass::InputSampleListObjectType InputSampleListObjectType; typedef typename Superclass::OutputSampleListObjectType OutputSampleListObjectType; - + /** Filter adding noise to a ListSample */ typedef otb::Statistics::GaussianAdditiveNoiseSampleListFilter <InputSampleListType,OutputSampleListType> GaussianAdditiveNoiseType; @@ -99,6 +102,12 @@ public: /** Returns the label sample list as a data object */ const LabelSampleListObjectType * GetInputLabel() const; + + /** Returns the output label samplelist */ + LabelSampleListType * GetOutputLabelSampleList(); + + /** Returns the label sample list as a data object */ + LabelSampleListObjectType * GetOutputLabel(); /** Set/Get the mean for the white gaussian noise to generate */ otbSetObjectMemberMacro(AddGaussianNoiseFilter,Mean,double); @@ -124,6 +133,9 @@ protected: * have the higher number of sample. */ void ComputeMaxSampleFrequency(); + + /** Make Output */ + DataObjectPointer MakeOutput(unsigned int idx); ListSampleToBalancedListSampleFilter(); virtual ~ListSampleToBalancedListSampleFilter() {} diff --git a/Code/Learning/otbListSampleToBalancedListSampleFilter.txx b/Code/Learning/otbListSampleToBalancedListSampleFilter.txx index 45610b7ce9d85cc8ecb654043be22e5c08af9a6e..115af1c4830ba0f77ed36f07bc757db7b7a2bebc 100644 --- a/Code/Learning/otbListSampleToBalancedListSampleFilter.txx +++ b/Code/Learning/otbListSampleToBalancedListSampleFilter.txx @@ -32,11 +32,42 @@ ListSampleToBalancedListSampleFilter<TInputSampleList,TLabelSampleList,TOutputSa ::ListSampleToBalancedListSampleFilter() { this->SetNumberOfRequiredInputs(2); + this->SetNumberOfRequiredOutputs(2); + + // Create the second output + //this->itk::ProcessObject::SetNthOutput(0, this->MakeOutput(0).GetPointer()); + this->itk::ProcessObject::SetNthOutput(1, this->MakeOutput(1).GetPointer()); m_AddGaussianNoiseFilter = GaussianAdditiveNoiseType::New(); m_BalancingFactor = 5; } +template < class TInputSampleList, class TLabelSampleList, class TOutputSampleList > +typename ListSampleToBalancedListSampleFilter<TInputSampleList,TLabelSampleList,TOutputSampleList> +::DataObjectPointer +ListSampleToBalancedListSampleFilter<TInputSampleList,TLabelSampleList,TOutputSampleList> +::MakeOutput(unsigned int idx) +{ + DataObjectPointer output; + switch (idx) + { + case 0: + Superclass::MakeOutput(0); + break; + case 1: + { + typename LabelSampleListObjectType::Pointer labelListSample = LabelSampleListObjectType::New(); + labelListSample->Set(LabelSampleListType::New()); + output = static_cast<itk::DataObject*>(labelListSample.GetPointer()); + break; + } + default: + output = static_cast<itk::DataObject*>(InputSampleListObjectType::New().GetPointer()); + break; + } + return output; +} + // Method to set the SampleList template < class TInputSampleList, class TLabelSampleList, class TOutputSampleList > void @@ -92,6 +123,27 @@ ListSampleToBalancedListSampleFilter<TInputSampleList,TLabelSampleList,TOutputSa return dataObjectPointer->Get(); } +// Get the output label SampleList +template < class TInputSampleList, class TLabelSampleList, class TOutputSampleList > +typename ListSampleToBalancedListSampleFilter<TInputSampleList,TLabelSampleList,TOutputSampleList> +::LabelSampleListType * +ListSampleToBalancedListSampleFilter<TInputSampleList,TLabelSampleList,TOutputSampleList> +::GetOutputLabelSampleList() +{ + return const_cast<LabelSampleListType*>(this->GetOutputLabel()->Get()); +} + +// Get the output label SampleList as DataObject +template < class TInputSampleList, class TLabelSampleList, class TOutputSampleList > +typename ListSampleToBalancedListSampleFilter<TInputSampleList,TLabelSampleList,TOutputSampleList> +::LabelSampleListObjectType * +ListSampleToBalancedListSampleFilter<TInputSampleList,TLabelSampleList,TOutputSampleList> +::GetOutputLabel() +{ + return dynamic_cast<LabelSampleListObjectType*>(this->itk::ProcessObject::GetOutput(1)); +} + + // Get the max sample number having the same label template < class TInputSampleList, class TLabelSampleList, class TOutputSampleList > void @@ -174,6 +226,10 @@ ListSampleToBalancedListSampleFilter<TInputSampleList,TLabelSampleList,TOutputSa typename LabelSampleListObjectType::ConstPointer labelPtr = this->GetInputLabel(); typename OutputSampleListObjectType::Pointer outputPtr = this->GetOutput(); + typename LabelSampleListObjectType::Pointer outputLabelPtr = this->GetOutputLabel(); + typename LabelSampleListType::Pointer outputLabel = const_cast<LabelSampleListType*>(outputLabelPtr->Get()); + + // Retrieve the ListSample InputSampleListConstPointer inputSampleListPtr = inputPtr->Get(); LabelSampleListConstPointer labelSampleListPtr = labelPtr->Get(); @@ -222,6 +278,9 @@ ListSampleToBalancedListSampleFilter<TInputSampleList,TLabelSampleList,TOutputSa // Add the current input casted sample to the output SampleList outputSampleListPtr->PushBack(currentOutputMeasurement); + // Add the currentsample list label + outputLabel->PushBack(currentLabelMeasurement); + // Add the noised versions of the current sample to OutputSampleList typename OutputSampleListType::ConstIterator tempIt = noisingFilter->GetOutput()->Get()->Begin(); @@ -231,6 +290,10 @@ ListSampleToBalancedListSampleFilter<TInputSampleList,TLabelSampleList,TOutputSa OutputMeasurementVectorType currentTempMeasurement = tempIt.GetMeasurementVector(); // Add to output SampleList outputSampleListPtr->PushBack(currentTempMeasurement); + + // Add a label in the output ListSample + outputLabel->PushBack(currentLabelMeasurement); + ++tempIt; } diff --git a/Code/Projections/otbImageToEnvelopeVectorDataFilter.h b/Code/Projections/otbImageToEnvelopeVectorDataFilter.h new file mode 100644 index 0000000000000000000000000000000000000000..7df28b1d0e64b6ea722d9ea54b4a8cd6432b5c43 --- /dev/null +++ b/Code/Projections/otbImageToEnvelopeVectorDataFilter.h @@ -0,0 +1,120 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbImageToEnvelopeVectorDataFilter_h +#define __otbImageToEnvelopeVectorDataFilter_h + +#include "otbVectorDataSource.h" +#include "otbGenericRSTransform.h" + +namespace otb +{ + +/** \class ImageToEnvelopeVectorDataFilter + * \brief Build a vector data containing the polygon of the image envelope + * + * This filter uses the GenericRSTransform to project the four corners of the image into ground position. + * In case of raw image geometry, a DEM directory or average elevation can be set for better accuracy. + * + * This filter supports user-specified output projection. If no projection is defined, the standard WGS84 + * projection will be used. + * + * \ingroup VectorDataFilter + * \ingroup Projection + * + */ +template <class TInputImage, class TOutputVectorData> +class ITK_EXPORT ImageToEnvelopeVectorDataFilter : + public otb::VectorDataSource<TOutputVectorData> +{ + +public: + /** Standard class typedefs. */ + typedef ImageToEnvelopeVectorDataFilter Self; + typedef otb::VectorDataSource<TOutputVectorData> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + typedef TInputImage InputImageType; + typedef TOutputVectorData OutputVectorDataType; + typedef typename TInputImage::ConstPointer InputImagePointer; + typedef typename TOutputVectorData::Pointer OutputVectorDataPointer; + + /** Some typedefs. */ + typedef otb::GenericRSTransform<double, 2, 2> InternalTransformType; + typedef typename InternalTransformType::Pointer InternalTransformPointerType; + typedef typename OutputVectorDataType + ::DataNodeType OutputDataNodeType; + typedef typename OutputVectorDataType + ::DataNodePointerType OutputDataNodePointerType; + typedef typename OutputVectorDataType + ::DataTreePointerType OutputDataTreePointerType; + typedef typename OutputVectorDataType + ::DataTreeType::TreeNodeType OutputInternalTreeNodeType; + typedef typename OutputDataNodeType::PolygonType PolygonType; + + /** Set input image */ + void SetInput(const InputImageType *input); + + /** Get input image */ + const InputImageType * GetInput(); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(ImageToEnvelopeVectorDataFilter, VectorDataSource); + + /** Set/Get output projection (default is WGS84) */ + itkSetStringMacro(OutputProjectionRef); + itkGetStringMacro(OutputProjectionRef); + + itkSetStringMacro(DEMDirectory); + itkGetStringMacro(DEMDirectory); + + itkSetMacro(AverageElevation, double); + itkGetMacro(AverageElevation, double); + +protected: + ImageToEnvelopeVectorDataFilter(); + virtual ~ImageToEnvelopeVectorDataFilter() {} + + void GenerateOutputInformation(void); + + void GenerateInputRequestedRegion(); + + void GenerateData(void); + + void InstantiateTransform(); + +private: + ImageToEnvelopeVectorDataFilter(const Self &); //purposely not implemented + void operator =(const Self&); //purposely not implemented + + InternalTransformPointerType m_Transform; + std::string m_OutputProjectionRef; + std::string m_DEMDirectory; + double m_AverageElevation; +}; + +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbImageToEnvelopeVectorDataFilter.txx" +#endif + +#endif diff --git a/Code/Projections/otbImageToEnvelopeVectorDataFilter.txx b/Code/Projections/otbImageToEnvelopeVectorDataFilter.txx new file mode 100644 index 0000000000000000000000000000000000000000..6e9e2794ef92cef8280e7d2a87383d37cc70e484 --- /dev/null +++ b/Code/Projections/otbImageToEnvelopeVectorDataFilter.txx @@ -0,0 +1,188 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbImageToEnvelopeVectorDataFilter_txx +#define __otbImageToEnvelopeVectorDataFilter_txx + +#include "otbImageToEnvelopeVectorDataFilter.h" +#include "otbDataNode.h" + +namespace otb +{ +/** + * Constructor + */ +template <class TInputImage, class TOutputVectorData> +ImageToEnvelopeVectorDataFilter<TInputImage, TOutputVectorData> +::ImageToEnvelopeVectorDataFilter() : m_DEMDirectory(""), m_AverageElevation(-32768.0) +{ + this->SetNumberOfInputs(1); + this->SetNumberOfOutputs(1); + m_OutputProjectionRef.clear(); + + // Build output + this->SetNthOutput(0,OutputVectorDataType::New()); +} + +template <class TInputImage, class TOutputVectorData> +void +ImageToEnvelopeVectorDataFilter<TInputImage, TOutputVectorData> +::SetInput(const InputImageType *input) +{ + // process object is not const-correct, the const_cast + // is required here. + this->itk::ProcessObject::SetNthInput(0, + const_cast<InputImageType *>(input)); +} + +template <class TInputImage, class TOutputVectorData> +const TInputImage * +ImageToEnvelopeVectorDataFilter<TInputImage, TOutputVectorData> +::GetInput(void) +{ + if (this->GetNumberOfInputs() < 1) return 0; + + return dynamic_cast<const InputImageType*> + (this->itk::ProcessObject::GetInput(0)); +} + +template <class TInputImage, class TOutputVectorData> +void +ImageToEnvelopeVectorDataFilter<TInputImage, TOutputVectorData> +::GenerateOutputInformation(void) +{ + // Call superclass implementation + Superclass::GenerateOutputInformation(); + + // Ensure transform instantiation + this->InstantiateTransform(); + + // Add projection info to output + OutputVectorDataPointer output = this->GetOutput(); + itk::MetaDataDictionary& dict = output->GetMetaDataDictionary(); + itk::EncapsulateMetaData<std::string>(dict, MetaDataKey::ProjectionRefKey, m_Transform->GetOutputProjectionRef()); +} + +template <class TInputImage, class TOutputVectorData> +void +ImageToEnvelopeVectorDataFilter<TInputImage, TOutputVectorData> +::GenerateInputRequestedRegion(void) +{ + // Call superclass implementation + Superclass::GenerateInputRequestedRegion(); + + // Retrieve input image pointer + typename InputImageType::Pointer inputPtr = const_cast<TInputImage *>(this->GetInput()); + + typename InputImageType::RegionType requestedRegion = inputPtr->GetRequestedRegion(); + typename InputImageType::SizeType size = requestedRegion.GetSize(); + size.Fill(0); + requestedRegion.SetSize(size); + + typename InputImageType::IndexType index = requestedRegion.GetIndex(); + index.Fill(0); + requestedRegion.SetIndex(index); + + inputPtr->SetRequestedRegion(requestedRegion); +} + +template <class TInputImage, class TOutputVectorData> +void +ImageToEnvelopeVectorDataFilter<TInputImage, TOutputVectorData> +::InstantiateTransform(void) +{ + // Project into output projection + typename InputImageType::ConstPointer inputPtr = this->GetInput(); + m_Transform = InternalTransformType::New(); + m_Transform->SetOutputProjectionRef(m_OutputProjectionRef); + m_Transform->SetInputProjectionRef(inputPtr->GetProjectionRef()); + m_Transform->SetInputKeywordList(inputPtr->GetImageKeywordlist()); + m_Transform->SetDEMDirectory(m_DEMDirectory); + m_Transform->SetAverageElevation(m_AverageElevation); + m_Transform->InstanciateTransform(); +} + + +template <class TInputImage, class TOutputVectorData> +void +ImageToEnvelopeVectorDataFilter<TInputImage, TOutputVectorData> +::GenerateData(void) +{ + // Retrieve input and output pointers + typename InputImageType::ConstPointer inputPtr = this->GetInput(); + OutputVectorDataPointer outputPtr = this->GetOutput(); + + // Compute corners as index + typename InputImageType::IndexType ul, ur,lr,ll; + ul = inputPtr->GetLargestPossibleRegion().GetIndex(); + ur = ul; + ll=ul; + lr=ul; + typename InputImageType::SizeType size = inputPtr->GetLargestPossibleRegion().GetSize(); + ur[0]+=size[0]; + ll[1]+=size[1]; + lr[0]+=size[0]; + lr[1]+=size[1]; + + // Get corners as physical points + typename InputImageType::PointType ulp,urp,lrp,llp,current; + inputPtr->TransformIndexToPhysicalPoint(ul,ulp); + inputPtr->TransformIndexToPhysicalPoint(ur,urp); + inputPtr->TransformIndexToPhysicalPoint(lr,lrp); + inputPtr->TransformIndexToPhysicalPoint(ll,llp); + + this->InstantiateTransform(); + + // Build envelope polygon + typename PolygonType::Pointer envelope = PolygonType::New(); + typename PolygonType::VertexType vertex; + current = m_Transform->TransformPoint(ulp); + vertex[0] = current[0]; + vertex[1] = current[1]; + envelope->AddVertex(vertex); + current = m_Transform->TransformPoint(urp); + vertex[0] = current[0]; + vertex[1] = current[1]; + envelope->AddVertex(vertex); + current = m_Transform->TransformPoint(lrp); + vertex[0] = current[0]; + vertex[1] = current[1]; + envelope->AddVertex(vertex); + current = m_Transform->TransformPoint(llp); + vertex[0] = current[0]; + vertex[1] = current[1]; + envelope->AddVertex(vertex); + + // Add polygon to the VectorData tree + OutputDataTreePointerType tree = outputPtr->GetDataTree(); + + // Create the output tree root + OutputDataNodePointerType root = tree->GetRoot()->Get(); + + OutputDataNodePointerType document = OutputDataNodeType::New(); + document->SetNodeType(DOCUMENT); + tree->Add(document, root); + + OutputDataNodePointerType newDataNode = OutputDataNodeType::New(); + newDataNode->SetPolygonExteriorRing(envelope); + + tree->Add(newDataNode,document); +} + +} // end namespace otb + +#endif diff --git a/Testing/Code/Common/CMakeLists.txt b/Testing/Code/Common/CMakeLists.txt index f5ba7d62e4afc98478ed0ea00a33e1f1c5fdb3b3..9630fc3714d515ffa323c91e629e4a349469e294 100644 --- a/Testing/Code/Common/CMakeLists.txt +++ b/Testing/Code/Common/CMakeLists.txt @@ -919,7 +919,7 @@ otbUnaryFunctorWithIndexImageFilter # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbCommonTests12 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# ---------------- otbParser ---------------------# +# ---------------- otbParser --------------------- # ADD_TEST(coTuParser ${COMMON_TESTS12} otbParserTestNew ) @@ -928,6 +928,14 @@ otbUnaryFunctorWithIndexImageFilter otbParserTest ) +# ---------------- otbVariableLengthVectorConverter --------------------- # +ADD_TEST(coTuVariableLengthVectorConverter ${COMMON_TESTS12} + otbVariableLengthVectorConverterNew + ) + +#ADD_TEST(coTvVariableLengthVectorConverter ${COMMON_TESTS12} +# otbVariableLengthVectorConverter +# ) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbCommonTests13 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1087,6 +1095,7 @@ otbUnaryFunctorWithIndexImageFilter.cxx SET(BasicCommon_SRCS12 otbCommonTests12.cxx otbParserTest.cxx +otbVariableLengthVectorConverter.cxx ) diff --git a/Testing/Code/Common/otbCommonTests12.cxx b/Testing/Code/Common/otbCommonTests12.cxx index f11a9e0d157059ec6a313038d2676948567b9706..28e89d576352973d8852aa9f44ef765e42109a30 100644 --- a/Testing/Code/Common/otbCommonTests12.cxx +++ b/Testing/Code/Common/otbCommonTests12.cxx @@ -28,4 +28,6 @@ void RegisterTests() { REGISTER_TEST(otbParserTestNew); REGISTER_TEST(otbParserTest); + REGISTER_TEST(otbVariableLengthVectorConverterNew); + //REGISTER_TEST(otbVariableLengthVectorConverter); } diff --git a/Testing/Code/Common/otbVariableLengthVectorConverter.cxx b/Testing/Code/Common/otbVariableLengthVectorConverter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d3e9a32ce1a0610f70ef9199274d91cc0bace2a1 --- /dev/null +++ b/Testing/Code/Common/otbVariableLengthVectorConverter.cxx @@ -0,0 +1,54 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "itkExceptionObject.h" +#include <cstdlib> +#include <cmath> + +#include "otbVariableLengthVectorConverter.h" + +int otbVariableLengthVectorConverterNew(int argc, char * argv[]) +{ + typedef itk::VariableLengthVector<double> InputType0; + typedef std::vector< std::vector< double > > InputType1; + typedef std::vector< std::vector< std::complex< double > > > InputType2; + typedef itk::FixedArray<double> InputType3; + + typedef float PrecisionType; + + typedef otb::VariableLengthVectorConverter<InputType0, PrecisionType> + ConverterType0; + typedef otb::VariableLengthVectorConverter<InputType1, PrecisionType> + ConverterType1; + typedef otb::VariableLengthVectorConverter<InputType2, PrecisionType> + ConverterType2; + typedef otb::VariableLengthVectorConverter<InputType3, PrecisionType> + ConverterType3; + + // Instantiating object + ConverterType0::Pointer converter0 = ConverterType0::New(); + ConverterType1::Pointer converter1 = ConverterType1::New(); + ConverterType2::Pointer converter2 = ConverterType2::New(); + ConverterType3::Pointer converter3 = ConverterType3::New(); + + std::cout << converter0 << std::endl; + std::cout << converter1 << std::endl; + std::cout << converter2 << std::endl; + std::cout << converter3 << std::endl; + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/FeatureExtraction/CMakeLists.txt b/Testing/Code/FeatureExtraction/CMakeLists.txt index 25d5f4fe048322ffbe5bf21e4bef29847b0aa860..64fe991fef73a160e9301a7bc4c68aa1382da80d 100644 --- a/Testing/Code/FeatureExtraction/CMakeLists.txt +++ b/Testing/Code/FeatureExtraction/CMakeLists.txt @@ -1507,12 +1507,12 @@ ADD_TEST(feTvLocalHistogramImageFunctionTest ${FEATUREEXTRACTION_TESTS16} # ------- otb::ImageFunctionAdapter ------------- -ADD_TEST(feTuImageFunctionAdapterNew ${FEATUREEXTRACTION_TESTS16} - otbImageFunctionAdapterNew +ADD_TEST(feTuImageFunctionAdaptorNew ${FEATUREEXTRACTION_TESTS16} + otbImageFunctionAdaptorNew ) -ADD_TEST(feTvImageFunctionAdapter ${FEATUREEXTRACTION_TESTS16} - otbImageFunctionAdapter +ADD_TEST(feTvImageFunctionAdaptor ${FEATUREEXTRACTION_TESTS16} + otbImageFunctionAdaptor ${INPUTDATA}/poupees.png ) @@ -1531,6 +1531,23 @@ ADD_TEST(feTvMetaImageFunction ${FEATUREEXTRACTION_TESTS16} 451846.014047961 5412466.57452216 ) +# ------- otb::HaralickTexturesImageFunction ------------- +ADD_TEST(feTuHaralickTexturesImageFunctionNew ${FEATUREEXTRACTION_TESTS16} + otbHaralickTexturesImageFunctionNew +) + +ADD_TEST(feTvHaralickTexturesImageFunction ${FEATUREEXTRACTION_TESTS16} +--compare-ascii ${EPSILON_8} + ${BASELINE_FILES}/feTvHaralickTexturesImageFunction.txt + ${TEMP}/feTvHaralickTexturesImageFunction.txt + otbHaralickTexturesImageFunction + ${INPUTDATA}/ROI_IKO_PAN_LesHalles.tif + ${TEMP}/feTvHaralickTexturesImageFunction.txt + 451846.014047961 5412466.57452216 +) + + + # A enrichir SET(BasicFeatureExtraction_SRCS1 otbFeatureExtractionTests1.cxx @@ -1725,8 +1742,9 @@ otbFeatureExtractionTests16.cxx otbFourierMellinDescriptors.cxx otbLocalHistogramImageFunctionNew.cxx otbLocalHistogramImageFunctionTest.cxx -otbImageFunctionAdapter.cxx +otbImageFunctionAdaptor.cxx otbMetaImageFunction.cxx +otbHaralickTexturesImageFunction.cxx ) diff --git a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests16.cxx b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests16.cxx index 0b1ddb8e18db845756e4f2828bbf52142cf9ec51..2dc89f67426caeaf521b69ec651e11a9a504f657 100644 --- a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests16.cxx +++ b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests16.cxx @@ -32,8 +32,10 @@ void RegisterTests() REGISTER_TEST(otbFourierMellinDescriptorsRotationInvariant); REGISTER_TEST(otbLocalHistogramImageFunctionNew); REGISTER_TEST(otbLocalHistogramImageFunctionTest); - REGISTER_TEST(otbImageFunctionAdapterNew); - REGISTER_TEST(otbImageFunctionAdapter); + REGISTER_TEST(otbImageFunctionAdaptorNew); + REGISTER_TEST(otbImageFunctionAdaptor); REGISTER_TEST(otbMetaImageFunctionNew); REGISTER_TEST(otbMetaImageFunction); + REGISTER_TEST(otbHaralickTexturesImageFunctionNew); + REGISTER_TEST(otbHaralickTexturesImageFunction); } diff --git a/Testing/Code/FeatureExtraction/otbHaralickTexturesImageFunction.cxx b/Testing/Code/FeatureExtraction/otbHaralickTexturesImageFunction.cxx new file mode 100644 index 0000000000000000000000000000000000000000..b2cbc51e7f3f24fd73c0c4f35e108ac1e7e2c58c --- /dev/null +++ b/Testing/Code/FeatureExtraction/otbHaralickTexturesImageFunction.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "otbHaralickTexturesImageFunction.h" +#include "otbImage.h" +#include "otbImageFileReader.h" + +typedef unsigned short InputPixelType; +const unsigned int Dimension = 2; + +typedef otb::Image<InputPixelType, Dimension> InputImageType; +typedef otb::ImageFileReader<InputImageType> ReaderType; + +typedef otb::HaralickTexturesImageFunction< + InputImageType,double> HaralickTexturesImageFunctionType; +typedef HaralickTexturesImageFunctionType::PointType PointType; +typedef HaralickTexturesImageFunctionType::OutputType OutputType; + +int otbHaralickTexturesImageFunctionNew(int argc, char * argv[]) +{ + HaralickTexturesImageFunctionType::Pointer function = HaralickTexturesImageFunctionType::New(); + + return EXIT_SUCCESS; +} + +int otbHaralickTexturesImageFunction(int argc, char * argv[]) +{ + // Read the input image + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(argv[1]); + reader->Update(); + + std::ofstream outputStream(argv[2]); + + HaralickTexturesImageFunctionType::Pointer haralick = HaralickTexturesImageFunctionType::New(); + haralick->SetInputImage(reader->GetOutput()); + haralick->SetNeighborhoodRadius(10); + + HaralickTexturesImageFunctionType::OffsetType offset; + offset.Fill(1); + haralick->SetOffset(offset); + + PointType p; + p[0] = atof(argv[3]); + p[1] = atof(argv[4]); + + OutputType output = haralick->Evaluate(p); + + outputStream<<"Evaluate("<<p<<") = "<<output<<std::endl; + + outputStream.close(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/FeatureExtraction/otbImageFunctionAdaptor.cxx b/Testing/Code/FeatureExtraction/otbImageFunctionAdaptor.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2f7fc61774aaa657d4f2f5a7d969a92d3ffb8d3d --- /dev/null +++ b/Testing/Code/FeatureExtraction/otbImageFunctionAdaptor.cxx @@ -0,0 +1,332 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "otbImage.h" +#include "otbImageFileReader.h" +#include "otbStreamingMinMaxImageFilter.h" + +#include "otbImageFunctionAdaptor.h" + +#include "otbFourierMellinDescriptorsImageFunction.h" +#include "otbRealMomentsImageFunction.h" +#include "otbComplexMomentsImageFunction.h" +#include "otbFlusserMomentsImageFunction.h" +#include "otbHuMomentsImageFunction.h" +#include "otbRadiometricMomentsImageFunction.h" +#include "otbLocalHistogramImageFunction.h" + + +int otbImageFunctionAdaptorNew(int argc, char * argv[]) +{ + typedef double InputPixelType; + const unsigned int Dimension = 2; + + typedef otb::Image<InputPixelType, Dimension> InputImageType; + + typedef otb::FourierMellinDescriptorsImageFunction<InputImageType> FMDFunctionType; + typedef otb::RealMomentsImageFunction<InputImageType> RMFunctionType; + typedef otb::ComplexMomentsImageFunction<InputImageType> CMFunctionType; + typedef otb::FlusserMomentsImageFunction<InputImageType> FMFunctionType; + typedef otb::HuMomentsImageFunction<InputImageType> HMFunctionType; + typedef otb::RadiometricMomentsImageFunction<InputImageType> RaMFunctionType; + typedef otb::LocalHistogramImageFunction<InputImageType> LHFunctionType; + + typedef otb::ImageFunctionAdaptor<FMDFunctionType> FMDImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<RMFunctionType> RMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<CMFunctionType> CMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<FMFunctionType> FMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<HMFunctionType> HMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<RaMFunctionType> RaMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<LHFunctionType> LHImageFunctionAdaptorType; + + // Instantiating objects + FMDImageFunctionAdaptorType::Pointer FMDadaptedFunction = FMDImageFunctionAdaptorType::New(); + std::cout << FMDadaptedFunction << std::endl; + RMImageFunctionAdaptorType::Pointer RMadaptedFunction = RMImageFunctionAdaptorType::New(); + std::cout << RMadaptedFunction << std::endl; + CMImageFunctionAdaptorType::Pointer CMadaptedFunction = CMImageFunctionAdaptorType::New(); + std::cout << CMadaptedFunction << std::endl; + FMImageFunctionAdaptorType::Pointer FMadaptedFunction = FMImageFunctionAdaptorType::New(); + std::cout << FMadaptedFunction << std::endl; + HMImageFunctionAdaptorType::Pointer HMadaptedFunction = HMImageFunctionAdaptorType::New(); + std::cout << HMadaptedFunction << std::endl; + RaMImageFunctionAdaptorType::Pointer RaMadaptedFunction = RaMImageFunctionAdaptorType::New(); + std::cout << RaMadaptedFunction << std::endl; + LHImageFunctionAdaptorType::Pointer LHadaptedFunction = LHImageFunctionAdaptorType::New(); + std::cout << LHadaptedFunction << std::endl; + + return EXIT_SUCCESS; +} + +int otbImageFunctionAdaptor(int argc, char * argv[]) +{ + const char * inputFilename = argv[1]; + + typedef double InputPixelType; + const unsigned int Dimension = 2; + unsigned int rsltIdx = 0; + + typedef otb::Image<InputPixelType, Dimension> InputImageType; + typedef otb::ImageFileReader<InputImageType> ReaderType; + typedef otb::StreamingMinMaxImageFilter<InputImageType> MinMaxFilterType; + + typedef otb::FourierMellinDescriptorsImageFunction<InputImageType> FMDFunctionType; + typedef otb::RealMomentsImageFunction<InputImageType> RMFunctionType; + typedef otb::ComplexMomentsImageFunction<InputImageType> CMFunctionType; + typedef otb::FlusserMomentsImageFunction<InputImageType> FMFunctionType; + typedef otb::HuMomentsImageFunction<InputImageType> HMFunctionType; + typedef otb::RadiometricMomentsImageFunction<InputImageType> RaMFunctionType; + typedef otb::LocalHistogramImageFunction<InputImageType> LHFunctionType; + + typedef otb::ImageFunctionAdaptor<FMDFunctionType> FMDImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<RMFunctionType> RMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<CMFunctionType> CMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<FMFunctionType> FMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<HMFunctionType> HMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<RaMFunctionType> RaMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<LHFunctionType> LHImageFunctionAdaptorType; + + // Instantiating objects + ReaderType::Pointer reader = ReaderType::New(); + MinMaxFilterType::Pointer filter = MinMaxFilterType::New(); + + FMDFunctionType::Pointer FMDFunction = FMDFunctionType::New(); + RMFunctionType::Pointer RMFunction = RMFunctionType::New(); + CMFunctionType::Pointer CMFunction = CMFunctionType::New(); + FMFunctionType::Pointer FMFunction = FMFunctionType::New(); + HMFunctionType::Pointer HMFunction = HMFunctionType::New(); + RaMFunctionType::Pointer RaMFunction = RaMFunctionType::New(); + LHFunctionType::Pointer LHFunction = LHFunctionType::New(); + + FMDImageFunctionAdaptorType::Pointer FMDadaptedFunction = FMDImageFunctionAdaptorType::New(); + RMImageFunctionAdaptorType::Pointer RMadaptedFunction = RMImageFunctionAdaptorType::New(); + CMImageFunctionAdaptorType::Pointer CMadaptedFunction = CMImageFunctionAdaptorType::New(); + FMImageFunctionAdaptorType::Pointer FMadaptedFunction = FMImageFunctionAdaptorType::New(); + HMImageFunctionAdaptorType::Pointer HMadaptedFunction = HMImageFunctionAdaptorType::New(); + RaMImageFunctionAdaptorType::Pointer RaMadaptedFunction = RaMImageFunctionAdaptorType::New(); + LHImageFunctionAdaptorType::Pointer LHadaptedFunction = LHImageFunctionAdaptorType::New(); + + reader->SetFileName(inputFilename); + filter->SetInput(reader->GetOutput()); + filter->Update(); + + InputImageType::IndexType index; + index[0] = 100; + index[1] = 100; + + // Content testing + double error = 0.0; + + FMDFunction->SetInputImage(reader->GetOutput()); + FMDFunction->SetNeighborhoodRadius(5); + FMDFunction->SetPmax(5); + FMDFunction->SetQmax(5); + FMDFunctionType::OutputType resultFMD = FMDFunction->EvaluateAtIndex(index); + + FMDadaptedFunction->SetInputImage(reader->GetOutput()); + FMDadaptedFunction->GetInternalImageFunction()->SetNeighborhoodRadius(5); + FMDadaptedFunction->GetInternalImageFunction()->SetPmax(5); + FMDadaptedFunction->GetInternalImageFunction()->SetQmax(5); + FMDImageFunctionAdaptorType::OutputType resultAdaptedFMD = FMDadaptedFunction->EvaluateAtIndex(index); + + rsltIdx = 0; + for (unsigned int i=0; i<=5; i++) + { + for (unsigned int j=0; j<=5; j++) + { + error += vcl_pow(vcl_abs(resultAdaptedFMD[rsltIdx] - resultFMD.at(i).at(j)), 2); + + std::cout << "resultAdaptedFMD : " << resultAdaptedFMD[rsltIdx] + << "\t - resultFMD : " << resultFMD.at(i).at(j) << std::endl; + rsltIdx ++; + } + } + + RMFunction->SetInputImage(reader->GetOutput()); + RMFunction->SetNeighborhoodRadius(5); + RMFunction->SetPmax(5); + RMFunction->SetQmax(5); + RMFunctionType::OutputType resultRM = RMFunction->EvaluateAtIndex(index); + + RMadaptedFunction->SetInputImage(reader->GetOutput()); + RMadaptedFunction->GetInternalImageFunction()->SetNeighborhoodRadius(5); + RMadaptedFunction->GetInternalImageFunction()->SetPmax(5); + RMadaptedFunction->GetInternalImageFunction()->SetQmax(5); + RMImageFunctionAdaptorType::OutputType resultAdaptedRM = RMadaptedFunction->EvaluateAtIndex(index); + + rsltIdx = 0; + for (unsigned int i=0; i<=5; i++) + { + for (unsigned int j=0; j<=5; j++) + { + error += vcl_pow(vcl_abs(resultAdaptedRM[rsltIdx] - resultRM.at(i).at(j)), 2); + + std::cout << "resultAdaptedRM : " << resultAdaptedRM[rsltIdx] + << "\t - resultRM : " << resultRM.at(i).at(j) << std::endl; + rsltIdx ++; + } + } + + CMFunction->SetInputImage(reader->GetOutput()); + CMFunction->SetNeighborhoodRadius(5); + CMFunction->SetPmax(5); + CMFunction->SetQmax(5); + CMFunctionType::OutputType resultCM = CMFunction->EvaluateAtIndex(index); + + CMadaptedFunction->SetInputImage(reader->GetOutput()); + CMadaptedFunction->GetInternalImageFunction()->SetNeighborhoodRadius(5); + CMadaptedFunction->GetInternalImageFunction()->SetPmax(5); + CMadaptedFunction->GetInternalImageFunction()->SetQmax(5); + CMImageFunctionAdaptorType::OutputType resultAdaptedCM = CMadaptedFunction->EvaluateAtIndex(index); + + rsltIdx = 0; + for (unsigned int i=0; i<=5; i++) + { + for (unsigned int j=0; j<=5; j++) + { + error += vcl_pow(vcl_abs(resultAdaptedCM[rsltIdx] - resultCM.at(i).at(j).real()), 2); + std::cout << "resultAdaptedCM : (" << resultAdaptedCM[rsltIdx] + << "," << resultAdaptedCM[rsltIdx+1] << ")" + << "\t - resultCM : " << resultCM.at(i).at(j) << std::endl; + rsltIdx ++; + error += vcl_pow(vcl_abs(resultAdaptedCM[rsltIdx] - resultCM.at(i).at(j).imag()), 2); + rsltIdx ++; + } + } + + FMFunction->SetInputImage(reader->GetOutput()); + FMFunction->SetNeighborhoodRadius(5); + FMFunctionType::OutputType resultFM = FMFunction->EvaluateAtIndex(index); + + FMadaptedFunction->SetInputImage(reader->GetOutput()); + FMadaptedFunction->GetInternalImageFunction()->SetNeighborhoodRadius(5); + FMImageFunctionAdaptorType::OutputType resultAdaptedFM = FMadaptedFunction->EvaluateAtIndex(index); + + rsltIdx = 0; + for (unsigned int i=0; i<11; i++) + { + error += vcl_pow(vcl_abs(resultAdaptedFM[rsltIdx] - resultFM[i]), 2); + + std::cout << "resultAdaptedFM : " << resultAdaptedFM[rsltIdx] + << "\t - resultFM : " << resultFM[i] << std::endl; + rsltIdx ++; + } + + HMFunction->SetInputImage(reader->GetOutput()); + HMFunction->SetNeighborhoodRadius(5); + HMFunctionType::OutputType resultHM = HMFunction->EvaluateAtIndex(index); + + HMadaptedFunction->SetInputImage(reader->GetOutput()); + HMadaptedFunction->GetInternalImageFunction()->SetNeighborhoodRadius(5); + HMImageFunctionAdaptorType::OutputType resultAdaptedHM = HMadaptedFunction->EvaluateAtIndex(index); + + rsltIdx = 0; + for (unsigned int i=0; i<7; i++) + { + error += vcl_pow(vcl_abs(resultAdaptedHM[rsltIdx] - resultHM[i]), 2); + + std::cout << "resultAdaptedHM : " << resultAdaptedHM[rsltIdx] + << "\t - resultHM : " << resultHM[i] << std::endl; + rsltIdx ++; + } + + RaMFunction->SetInputImage(reader->GetOutput()); + RaMFunction->SetNeighborhoodRadius(5); + RaMFunctionType::OutputType resultRaM = RaMFunction->EvaluateAtIndex(index); + + RaMadaptedFunction->SetInputImage(reader->GetOutput()); + RaMadaptedFunction->GetInternalImageFunction()->SetNeighborhoodRadius(5); + RaMImageFunctionAdaptorType::OutputType resultAdaptedRaM = RaMadaptedFunction->EvaluateAtIndex(index); + + rsltIdx = 0; + for (unsigned int i=0; i<4; i++) + { + error += vcl_pow(vcl_abs(resultAdaptedRaM[rsltIdx] - resultRaM[i]), 2); + + std::cout << "resultAdaptedRaM : " << resultAdaptedRaM[rsltIdx] + << "\t - resultRaM : " << resultRaM[i] << std::endl; + rsltIdx ++; + } + + LHFunction->SetInputImage(reader->GetOutput()); + LHFunction->SetNeighborhoodRadius(5); + LHFunction->SetNumberOfHistogramBins(64); + LHFunction->SetHistogramMin(filter->GetMinimum()); + LHFunction->SetHistogramMax(filter->GetMaximum()); + LHFunctionType::OutputType resultLH = LHFunction->EvaluateAtIndex(index); + + LHadaptedFunction->SetInputImage(reader->GetOutput()); + LHadaptedFunction->GetInternalImageFunction()->SetNeighborhoodRadius(5); + LHadaptedFunction->GetInternalImageFunction()->SetNumberOfHistogramBins(64); + LHadaptedFunction->GetInternalImageFunction()->SetHistogramMin(filter->GetMinimum()); + LHadaptedFunction->GetInternalImageFunction()->SetHistogramMax(filter->GetMaximum()); + LHImageFunctionAdaptorType::OutputType resultAdaptedLH = LHadaptedFunction->EvaluateAtIndex(index); + + rsltIdx = 0; + for (unsigned int i=0; i<64; i++) + { + error += vcl_pow(vcl_abs( resultAdaptedLH[rsltIdx] - resultLH->GetFrequency(i)), 2); + + std::cout << "resultAdaptedLH : " << resultAdaptedLH[rsltIdx] + << "\t - resultLH : " << resultLH->GetFrequency(i) << std::endl; + rsltIdx ++; + } + + error = vcl_sqrt(error); + std::cout << std::endl << "Error : " << error << std::endl + << std::endl; + + if (error > 1E-3) + { + itkGenericExceptionMacro( << "Error = " << error + << " > 1E-9 -> TEST FAILLED" << std::endl ); + } + + // Testing the use of a user defined InternalImageFunction instead + // of the build-in InternalImageFunction + FMDFunctionType::Pointer myFunction = FMDFunctionType::New(); + FMDImageFunctionAdaptorType::Pointer myAdaptedFunction = FMDImageFunctionAdaptorType::New(); + + myFunction->SetNeighborhoodRadius(8); + myFunction->SetPmax(2); + myFunction->SetQmax(2); + + myAdaptedFunction->SetInputImage(reader->GetOutput()); + myAdaptedFunction->SetInternalImageFunction(myFunction); + FMDImageFunctionAdaptorType::OutputType myResult = myAdaptedFunction->EvaluateAtIndex(index); + + rsltIdx = 0; + for (unsigned int i=0; i<=2; i++) + { + for (unsigned int j=0; j<=2; j++) + { + std::cout << "myResult: " << myResult[rsltIdx] << std::endl; + rsltIdx ++; + } + } + std::cout << myAdaptedFunction << std::endl; + + + + return EXIT_SUCCESS; +} + diff --git a/Testing/Code/FeatureExtraction/otbMetaImageFunction.cxx b/Testing/Code/FeatureExtraction/otbMetaImageFunction.cxx index fb5441ee64dcf4bc8085443f7e35c3dc8a9e2d12..633b4882b7d3ae2c319b78367d111a32586cf6fe 100644 --- a/Testing/Code/FeatureExtraction/otbMetaImageFunction.cxx +++ b/Testing/Code/FeatureExtraction/otbMetaImageFunction.cxx @@ -23,7 +23,7 @@ #include "otbImage.h" #include "otbImageFileReader.h" #include "otbFlusserMomentsImageFunction.h" -#include "otbImageFunctionAdapter.h" +#include "otbImageFunctionAdaptor.h" typedef unsigned short InputPixelType; const unsigned int Dimension = 2; @@ -31,7 +31,7 @@ const unsigned int Dimension = 2; typedef otb::Image<InputPixelType, Dimension> InputImageType; typedef otb::ImageFileReader<InputImageType> ReaderType; typedef otb::FlusserMomentsImageFunction<InputImageType> FlusserFunctionType; -typedef otb::ImageFunctionAdapter<InputImageType,FlusserFunctionType> FunctionType; +typedef otb::ImageFunctionAdaptor<FlusserFunctionType> FunctionType; typedef otb::MetaImageFunction< itk::NumericTraits<InputPixelType>::RealType,double> MetaImageFunctionType; @@ -61,9 +61,9 @@ int otbMetaImageFunction(int argc, char * argv[]) function2->SetInputImage(reader->GetOutput()); function3->SetInputImage(reader->GetOutput()); - function1->GetImageFunction()->SetNeighborhoodRadius(3); - function2->GetImageFunction()->SetNeighborhoodRadius(5); - function3->GetImageFunction()->SetNeighborhoodRadius(7); + function1->GetInternalImageFunction()->SetNeighborhoodRadius(3); + function2->GetInternalImageFunction()->SetNeighborhoodRadius(5); + function3->GetInternalImageFunction()->SetNeighborhoodRadius(7); std::ofstream outputStream(argv[2]); diff --git a/Testing/Code/Learning/otbListSampleToBalancedListSampleFilter.cxx b/Testing/Code/Learning/otbListSampleToBalancedListSampleFilter.cxx index 22e221f683780f52943f1aae177026c3ee790a9b..2a6650817ddabcc206575391ba5c123044d8c58d 100644 --- a/Testing/Code/Learning/otbListSampleToBalancedListSampleFilter.cxx +++ b/Testing/Code/Learning/otbListSampleToBalancedListSampleFilter.cxx @@ -101,7 +101,18 @@ int otbListSampleToBalancedListSampleFilter(int argc, char * argv[]) ++outIt; } + IntegerSampleListType::ConstIterator labelIt = filter->GetOutputLabelSampleList()->Begin(); + ofs<<"Output Label samples: "<<std::endl; + + while(labelIt != filter->GetOutputLabelSampleList()->End()) + { + ofs<<labelIt.GetMeasurementVector()<<std::endl; + ++labelIt; + } ofs.close(); + + std::cout <<"Output balanced SampleList Size : "<< filter->GetOutputSampleList()->Size() << std::endl; + std::cout <<"Output balanced Labeled SampleList Size : "<< filter->GetOutputLabelSampleList()->Size() << std::endl; return EXIT_SUCCESS; } diff --git a/Testing/Code/Projections/CMakeLists.txt b/Testing/Code/Projections/CMakeLists.txt index 4f78712016b4541ac33ba424be6b67dfbeb4fa21..dd8ed1c1217d6fd9e5f13fd17ce6e436c069f147 100644 --- a/Testing/Code/Projections/CMakeLists.txt +++ b/Testing/Code/Projections/CMakeLists.txt @@ -975,6 +975,20 @@ ADD_TEST(prTuElevDatabaseHeightAboveMSLFunction ${PROJECTIONS_TESTS4} otbElevDatabaseHeightAboveMSLFunction ) +#------ otb::ImageToEnvelopeVectorDataFilter --------------------- +ADD_TEST(prTuImageToEnvelopeVectorDataFilterNew ${PROJECTIONS_TESTS4} +otbImageToEnvelopeVectorDataFilterNew) + +IF(OTB_DATA_USE_LARGEINPUT) +ADD_TEST(prTvImageToEnvelopeVectorDataFilter ${PROJECTIONS_TESTS4} +--compare-ascii ${NOTOL} + ${BASELINE_FILES}/prTvImageToEnvelopeVectorDataFilterOutput.kml + ${TEMP}/prTvImageToEnvelopeVectorDataFilterOutput.kml + otbImageToEnvelopeVectorDataFilter + ${LARGEINPUT}/QUICKBIRD/TOULOUSE/000000128955_01_P001_PAN/02APR01105228-P1BS-000000128955_01_P001.TIF + ${TEMP}/prTvImageToEnvelopeVectorDataFilterOutput.kml +) +ENDIF(OTB_DATA_USE_LARGEINPUT) #======================================================================================= SET(Projections_SRCS1 @@ -1032,6 +1046,7 @@ otbProjectionsTests4.cxx otbPhysicalToRPCSensorModelImageFilter.cxx otbGenericRSResampleImageFilter.cxx otbElevDatabaseHeightAboveMSLFunction.cxx +otbImageToEnvelopeVectorDataFilter.cxx ) OTB_ADD_EXECUTABLE(otbProjectionsTests1 "${Projections_SRCS1}" "OTBProjections;OTBIO;OTBTesting") diff --git a/Testing/Code/Projections/otbImageToEnvelopeVectorDataFilter.cxx b/Testing/Code/Projections/otbImageToEnvelopeVectorDataFilter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..9baaf07374bcfad3e93736520fda7bdf49fb4d93 --- /dev/null +++ b/Testing/Code/Projections/otbImageToEnvelopeVectorDataFilter.cxx @@ -0,0 +1,53 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include "otbImage.h" +#include "otbImageToEnvelopeVectorDataFilter.h" +#include "otbVectorData.h" +#include "otbImageFileReader.h" +#include "otbVectorDataFileWriter.h" + +typedef unsigned short PixelType; +typedef otb::Image<PixelType,2> ImageType; +typedef otb::ImageFileReader<ImageType> ReaderType; +typedef otb::VectorData<> VectorDataType; +typedef otb::VectorDataFileWriter<VectorDataType> WriterType; +typedef otb::ImageToEnvelopeVectorDataFilter + <ImageType,VectorDataType> FilterType; + +int otbImageToEnvelopeVectorDataFilterNew(int argc,char* argv[]) +{ + // Instantiation + FilterType::Pointer filter = FilterType::New(); + + return EXIT_SUCCESS; +} + +int otbImageToEnvelopeVectorDataFilter(int argc,char* argv[]) +{ + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(argv[1]); + FilterType::Pointer filter = FilterType::New(); + filter->SetInput(reader->GetOutput()); + WriterType::Pointer writer = WriterType::New(); + writer->SetInput(filter->GetOutput()); + writer->SetFileName(argv[2]); + writer->Update(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/Projections/otbProjectionsTests4.cxx b/Testing/Code/Projections/otbProjectionsTests4.cxx index c47c2365da4746c38b7d965b933990a6f4b8b24e..338fd3ba159bca97dee12852de900eea7d2fa6cc 100644 --- a/Testing/Code/Projections/otbProjectionsTests4.cxx +++ b/Testing/Code/Projections/otbProjectionsTests4.cxx @@ -31,4 +31,6 @@ void RegisterTests() REGISTER_TEST(otbGenericRSResampleImageFilter); REGISTER_TEST(otbGenericRSResampleImageFilterFromMap); REGISTER_TEST(otbElevDatabaseHeightAboveMSLFunction); + REGISTER_TEST(otbImageToEnvelopeVectorDataFilterNew); + REGISTER_TEST(otbImageToEnvelopeVectorDataFilter); } diff --git a/Utilities/BGL/boost/algorithm/minmax.hpp b/Utilities/BGL/boost/algorithm/minmax.hpp new file mode 100755 index 0000000000000000000000000000000000000000..014a7d21ad90e02562bde551b9d384b846112b27 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/minmax.hpp @@ -0,0 +1,47 @@ +// (C) Copyright Herve Bronnimann 2004. +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +/* + Revision history: + 1 July 2004 + Split the code into two headers to lessen dependence on + Boost.tuple. (Herve) + 26 June 2004 + Added the code for the boost minmax library. (Herve) +*/ + +#ifndef BOOST_ALGORITHM_MINMAX_HPP +#define BOOST_ALGORITHM_MINMAX_HPP + +/* PROPOSED STANDARD EXTENSIONS: + * + * minmax(a, b) + * Effect: (b<a) ? std::make_pair(b,a) : std::make_pair(a,b); + * + * minmax(a, b, comp) + * Effect: comp(b,a) ? std::make_pair(b,a) : std::make_pair(a,b); + * + */ + +#include <boost/tuple/tuple.hpp> // for using pairs with boost::cref +#include <boost/ref.hpp> + +namespace boost { + + template <typename T> + tuple< T const&, T const& > + minmax(T const& a, T const& b) { + return (b<a) ? make_tuple(cref(b),cref(a)) : make_tuple(cref(a),cref(b)); + } + + template <typename T, class BinaryPredicate> + tuple< T const&, T const& > + minmax(T const& a, T const& b, BinaryPredicate comp) { + return comp(b,a) ? make_tuple(cref(b),cref(a)) : make_tuple(cref(a),cref(b)); + } + +} // namespace boost + +#endif // BOOST_ALGORITHM_MINMAX_HPP diff --git a/Utilities/BGL/boost/algorithm/minmax_element.hpp b/Utilities/BGL/boost/algorithm/minmax_element.hpp new file mode 100755 index 0000000000000000000000000000000000000000..996ede036d3c1d3c75f69513d7fdd3cdcb70858a --- /dev/null +++ b/Utilities/BGL/boost/algorithm/minmax_element.hpp @@ -0,0 +1,551 @@ +// (C) Copyright Herve Bronnimann 2004. +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +/* + Revision history: + 1 July 2004 + Split the code into two headers to lessen dependence on + Boost.tuple. (Herve) + 26 June 2004 + Added the code for the boost minmax library. (Herve) +*/ + +#ifndef BOOST_ALGORITHM_MINMAX_ELEMENT_HPP +#define BOOST_ALGORITHM_MINMAX_ELEMENT_HPP + +/* PROPOSED STANDARD EXTENSIONS: + * + * minmax_element(first, last) + * Effect: std::make_pair( std::min_element(first, last), + * std::max_element(first, last) ); + * + * minmax_element(first, last, comp) + * Effect: std::make_pair( std::min_element(first, last, comp), + * std::max_element(first, last, comp) ); + */ + +#include <utility> // for std::pair and std::make_pair + +namespace boost { + + namespace detail { // for obtaining a uniform version of minmax_element + // that compiles with VC++ 6.0 -- avoid the iterator_traits by + // having comparison object over iterator, not over dereferenced value + + template <typename Iterator> + struct less_over_iter { + bool operator()(Iterator const& it1, + Iterator const& it2) const { return *it1 < *it2; } + }; + + template <typename Iterator, class BinaryPredicate> + struct binary_pred_over_iter { + explicit binary_pred_over_iter(BinaryPredicate const& p ) : m_p( p ) {} + bool operator()(Iterator const& it1, + Iterator const& it2) const { return m_p(*it1, *it2); } + private: + BinaryPredicate m_p; + }; + + // common base for the two minmax_element overloads + + template <typename ForwardIter, class Compare > + std::pair<ForwardIter,ForwardIter> + basic_minmax_element(ForwardIter first, ForwardIter last, Compare comp) + { + if (first == last) + return std::make_pair(last,last); + + ForwardIter min_result = first; + ForwardIter max_result = first; + + // if only one element + ForwardIter second = first; ++second; + if (second == last) + return std::make_pair(min_result, max_result); + + // treat first pair separately (only one comparison for first two elements) + ForwardIter potential_min_result = last; + if (comp(first, second)) + max_result = second; + else { + min_result = second; + potential_min_result = first; + } + + // then each element by pairs, with at most 3 comparisons per pair + first = ++second; if (first != last) ++second; + while (second != last) { + if (comp(first, second)) { + if (comp(first, min_result)) { + min_result = first; + potential_min_result = last; + } + if (comp(max_result, second)) + max_result = second; + } else { + if (comp(second, min_result)) { + min_result = second; + potential_min_result = first; + } + if (comp(max_result, first)) + max_result = first; + } + first = ++second; + if (first != last) ++second; + } + + // if odd number of elements, treat last element + if (first != last) { // odd number of elements + if (comp(first, min_result)) + min_result = first, potential_min_result = last; + else if (comp(max_result, first)) + max_result = first; + } + + // resolve min_result being incorrect with one extra comparison + // (in which case potential_min_result is necessarily the correct result) + if (potential_min_result != last + && !comp(min_result, potential_min_result)) + min_result = potential_min_result; + + return std::make_pair(min_result,max_result); + } + + } // namespace detail + + template <typename ForwardIter> + std::pair<ForwardIter,ForwardIter> + minmax_element(ForwardIter first, ForwardIter last) + { + return detail::basic_minmax_element(first, last, + detail::less_over_iter<ForwardIter>() ); + } + + template <typename ForwardIter, class BinaryPredicate> + std::pair<ForwardIter,ForwardIter> + minmax_element(ForwardIter first, ForwardIter last, BinaryPredicate comp) + { + return detail::basic_minmax_element(first, last, + detail::binary_pred_over_iter<ForwardIter,BinaryPredicate>(comp) ); + } + +} + +/* PROPOSED BOOST EXTENSIONS + * In the description below, [rfirst,rlast) denotes the reversed range + * of [first,last). Even though the iterator type of first and last may + * be only a Forward Iterator, it is possible to explain the semantics + * by assuming that it is a Bidirectional Iterator. In the sequel, + * reverse(ForwardIterator&) returns the reverse_iterator adaptor. + * This is not how the functions would be implemented! + * + * first_min_element(first, last) + * Effect: std::min_element(first, last); + * + * first_min_element(first, last, comp) + * Effect: std::min_element(first, last, comp); + * + * last_min_element(first, last) + * Effect: reverse( std::min_element(reverse(last), reverse(first)) ); + * + * last_min_element(first, last, comp) + * Effect: reverse( std::min_element(reverse(last), reverse(first), comp) ); + * + * first_max_element(first, last) + * Effect: std::max_element(first, last); + * + * first_max_element(first, last, comp) + * Effect: max_element(first, last); + * + * last_max_element(first, last) + * Effect: reverse( std::max_element(reverse(last), reverse(first)) ); + * + * last_max_element(first, last, comp) + * Effect: reverse( std::max_element(reverse(last), reverse(first), comp) ); + * + * first_min_first_max_element(first, last) + * Effect: std::make_pair( first_min_element(first, last), + * first_max_element(first, last) ); + * + * first_min_first_max_element(first, last, comp) + * Effect: std::make_pair( first_min_element(first, last, comp), + * first_max_element(first, last, comp) ); + * + * first_min_last_max_element(first, last) + * Effect: std::make_pair( first_min_element(first, last), + * last_max_element(first, last) ); + * + * first_min_last_max_element(first, last, comp) + * Effect: std::make_pair( first_min_element(first, last, comp), + * last_max_element(first, last, comp) ); + * + * last_min_first_max_element(first, last) + * Effect: std::make_pair( last_min_element(first, last), + * first_max_element(first, last) ); + * + * last_min_first_max_element(first, last, comp) + * Effect: std::make_pair( last_min_element(first, last, comp), + * first_max_element(first, last, comp) ); + * + * last_min_last_max_element(first, last) + * Effect: std::make_pair( last_min_element(first, last), + * last_max_element(first, last) ); + * + * last_min_last_max_element(first, last, comp) + * Effect: std::make_pair( last_min_element(first, last, comp), + * last_max_element(first, last, comp) ); + */ + +namespace boost { + + // Min_element and max_element variants + + namespace detail { // common base for the overloads + + template <typename ForwardIter, class BinaryPredicate> + ForwardIter + basic_first_min_element(ForwardIter first, ForwardIter last, + BinaryPredicate comp) + { + if (first == last) return last; + ForwardIter min_result = first; + while (++first != last) + if (comp(first, min_result)) + min_result = first; + return min_result; + } + + template <typename ForwardIter, class BinaryPredicate> + ForwardIter + basic_last_min_element(ForwardIter first, ForwardIter last, + BinaryPredicate comp) + { + if (first == last) return last; + ForwardIter min_result = first; + while (++first != last) + if (!comp(min_result, first)) + min_result = first; + return min_result; + } + + template <typename ForwardIter, class BinaryPredicate> + ForwardIter + basic_first_max_element(ForwardIter first, ForwardIter last, + BinaryPredicate comp) + { + if (first == last) return last; + ForwardIter max_result = first; + while (++first != last) + if (comp(max_result, first)) + max_result = first; + return max_result; + } + + template <typename ForwardIter, class BinaryPredicate> + ForwardIter + basic_last_max_element(ForwardIter first, ForwardIter last, + BinaryPredicate comp) + { + if (first == last) return last; + ForwardIter max_result = first; + while (++first != last) + if (!comp(first, max_result)) + max_result = first; + return max_result; + } + + } // namespace detail + + template <typename ForwardIter> + ForwardIter + first_min_element(ForwardIter first, ForwardIter last) + { + return detail::basic_first_min_element(first, last, + detail::less_over_iter<ForwardIter>() ); + } + + template <typename ForwardIter, class BinaryPredicate> + ForwardIter + first_min_element(ForwardIter first, ForwardIter last, BinaryPredicate comp) + { + return detail::basic_first_min_element(first, last, + detail::binary_pred_over_iter<ForwardIter,BinaryPredicate>(comp) ); + } + + template <typename ForwardIter> + ForwardIter + last_min_element(ForwardIter first, ForwardIter last) + { + return detail::basic_last_min_element(first, last, + detail::less_over_iter<ForwardIter>() ); + } + + template <typename ForwardIter, class BinaryPredicate> + ForwardIter + last_min_element(ForwardIter first, ForwardIter last, BinaryPredicate comp) + { + return detail::basic_last_min_element(first, last, + detail::binary_pred_over_iter<ForwardIter,BinaryPredicate>(comp) ); + } + + template <typename ForwardIter> + ForwardIter + first_max_element(ForwardIter first, ForwardIter last) + { + return detail::basic_first_max_element(first, last, + detail::less_over_iter<ForwardIter>() ); + } + + template <typename ForwardIter, class BinaryPredicate> + ForwardIter + first_max_element(ForwardIter first, ForwardIter last, BinaryPredicate comp) + { + return detail::basic_first_max_element(first, last, + detail::binary_pred_over_iter<ForwardIter,BinaryPredicate>(comp) ); + } + + template <typename ForwardIter> + ForwardIter + last_max_element(ForwardIter first, ForwardIter last) + { + return detail::basic_last_max_element(first, last, + detail::less_over_iter<ForwardIter>() ); + } + + template <typename ForwardIter, class BinaryPredicate> + ForwardIter + last_max_element(ForwardIter first, ForwardIter last, BinaryPredicate comp) + { + return detail::basic_last_max_element(first, last, + detail::binary_pred_over_iter<ForwardIter,BinaryPredicate>(comp) ); + } + + + // Minmax_element variants -- comments removed + + namespace detail { + + template <typename ForwardIter, class BinaryPredicate> + std::pair<ForwardIter,ForwardIter> + basic_first_min_last_max_element(ForwardIter first, ForwardIter last, + BinaryPredicate comp) + { + if (first == last) + return std::make_pair(last,last); + + ForwardIter min_result = first; + ForwardIter max_result = first; + + ForwardIter second = ++first; + if (second == last) + return std::make_pair(min_result, max_result); + + if (comp(second, min_result)) + min_result = second; + else + max_result = second; + + first = ++second; if (first != last) ++second; + while (second != last) { + if (!comp(second, first)) { + if (comp(first, min_result)) + min_result = first; + if (!comp(second, max_result)) + max_result = second; + } else { + if (comp(second, min_result)) + min_result = second; + if (!comp(first, max_result)) + max_result = first; + } + first = ++second; if (first != last) ++second; + } + + if (first != last) { + if (comp(first, min_result)) + min_result = first; + else if (!comp(first, max_result)) + max_result = first; + } + + return std::make_pair(min_result, max_result); + } + + template <typename ForwardIter, class BinaryPredicate> + std::pair<ForwardIter,ForwardIter> + basic_last_min_first_max_element(ForwardIter first, ForwardIter last, + BinaryPredicate comp) + { + if (first == last) return std::make_pair(last,last); + + ForwardIter min_result = first; + ForwardIter max_result = first; + + ForwardIter second = ++first; + if (second == last) + return std::make_pair(min_result, max_result); + + if (comp(max_result, second)) + max_result = second; + else + min_result = second; + + first = ++second; if (first != last) ++second; + while (second != last) { + if (comp(first, second)) { + if (!comp(min_result, first)) + min_result = first; + if (comp(max_result, second)) + max_result = second; + } else { + if (!comp(min_result, second)) + min_result = second; + if (comp(max_result, first)) + max_result = first; + } + first = ++second; if (first != last) ++second; + } + + if (first != last) { + if (!comp(min_result, first)) + min_result = first; + else if (comp(max_result, first)) + max_result = first; + } + + return std::make_pair(min_result, max_result); + } + + template <typename ForwardIter, class BinaryPredicate> + std::pair<ForwardIter,ForwardIter> + basic_last_min_last_max_element(ForwardIter first, ForwardIter last, + BinaryPredicate comp) + { + if (first == last) return std::make_pair(last,last); + + ForwardIter min_result = first; + ForwardIter max_result = first; + + ForwardIter second = first; ++second; + if (second == last) + return std::make_pair(min_result,max_result); + + ForwardIter potential_max_result = last; + if (comp(first, second)) + max_result = second; + else { + min_result = second; + potential_max_result = second; + } + + first = ++second; if (first != last) ++second; + while (second != last) { + if (comp(first, second)) { + if (!comp(min_result, first)) + min_result = first; + if (!comp(second, max_result)) { + max_result = second; + potential_max_result = last; + } + } else { + if (!comp(min_result, second)) + min_result = second; + if (!comp(first, max_result)) { + max_result = first; + potential_max_result = second; + } + } + first = ++second; + if (first != last) ++second; + } + + if (first != last) { + if (!comp(min_result, first)) + min_result = first; + if (!comp(first, max_result)) { + max_result = first; + potential_max_result = last; + } + } + + if (potential_max_result != last + && !comp(potential_max_result, max_result)) + max_result = potential_max_result; + + return std::make_pair(min_result,max_result); + } + + } // namespace detail + + template <typename ForwardIter> + inline std::pair<ForwardIter,ForwardIter> + first_min_first_max_element(ForwardIter first, ForwardIter last) + { + return minmax_element(first, last); + } + + template <typename ForwardIter, class BinaryPredicate> + inline std::pair<ForwardIter,ForwardIter> + first_min_first_max_element(ForwardIter first, ForwardIter last, + BinaryPredicate comp) + { + return minmax_element(first, last, comp); + } + + template <typename ForwardIter> + std::pair<ForwardIter,ForwardIter> + first_min_last_max_element(ForwardIter first, ForwardIter last) + { + return detail::basic_first_min_last_max_element(first, last, + detail::less_over_iter<ForwardIter>() ); + } + + template <typename ForwardIter, class BinaryPredicate> + inline std::pair<ForwardIter,ForwardIter> + first_min_last_max_element(ForwardIter first, ForwardIter last, + BinaryPredicate comp) + { + return detail::basic_first_min_last_max_element(first, last, + detail::binary_pred_over_iter<ForwardIter,BinaryPredicate>(comp) ); + } + + template <typename ForwardIter> + std::pair<ForwardIter,ForwardIter> + last_min_first_max_element(ForwardIter first, ForwardIter last) + { + return detail::basic_last_min_first_max_element(first, last, + detail::less_over_iter<ForwardIter>() ); + } + + template <typename ForwardIter, class BinaryPredicate> + inline std::pair<ForwardIter,ForwardIter> + last_min_first_max_element(ForwardIter first, ForwardIter last, + BinaryPredicate comp) + { + return detail::basic_last_min_first_max_element(first, last, + detail::binary_pred_over_iter<ForwardIter,BinaryPredicate>(comp) ); + } + + template <typename ForwardIter> + std::pair<ForwardIter,ForwardIter> + last_min_last_max_element(ForwardIter first, ForwardIter last) + { + return detail::basic_last_min_last_max_element(first, last, + detail::less_over_iter<ForwardIter>() ); + } + + template <typename ForwardIter, class BinaryPredicate> + inline std::pair<ForwardIter,ForwardIter> + last_min_last_max_element(ForwardIter first, ForwardIter last, + BinaryPredicate comp) + { + return detail::basic_last_min_last_max_element(first, last, + detail::binary_pred_over_iter<ForwardIter,BinaryPredicate>(comp) ); + } + +} // namespace boost + +#endif // BOOST_ALGORITHM_MINMAX_ELEMENT_HPP diff --git a/Utilities/BGL/boost/algorithm/string.hpp b/Utilities/BGL/boost/algorithm/string.hpp new file mode 100755 index 0000000000000000000000000000000000000000..496400dbfd45c32e39a865b322099c1547fa5b14 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string.hpp @@ -0,0 +1,31 @@ +// Boost string_algo library string_algo.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2004. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_ALGO_HPP +#define BOOST_STRING_ALGO_HPP + +/*! \file + Cumulative include for string_algo library +*/ + +#include <boost/algorithm/string/std_containers_traits.hpp> +#include <boost/algorithm/string/trim.hpp> +#include <boost/algorithm/string/case_conv.hpp> +#include <boost/algorithm/string/predicate.hpp> +#include <boost/algorithm/string/find.hpp> +#include <boost/algorithm/string/split.hpp> +#include <boost/algorithm/string/join.hpp> +#include <boost/algorithm/string/replace.hpp> +#include <boost/algorithm/string/erase.hpp> +#include <boost/algorithm/string/classification.hpp> +#include <boost/algorithm/string/find_iterator.hpp> + + +#endif // BOOST_STRING_ALGO_HPP diff --git a/Utilities/BGL/boost/algorithm/string/case_conv.hpp b/Utilities/BGL/boost/algorithm/string/case_conv.hpp new file mode 100755 index 0000000000000000000000000000000000000000..40543d04f1984d683141cbb6380c25cbe274fcab --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/case_conv.hpp @@ -0,0 +1,176 @@ +// Boost string_algo library case_conv.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_CASE_CONV_HPP +#define BOOST_STRING_CASE_CONV_HPP + +#include <boost/algorithm/string/config.hpp> +#include <algorithm> +#include <locale> +#include <boost/iterator/transform_iterator.hpp> + +#include <boost/range/as_literal.hpp> +#include <boost/range/begin.hpp> +#include <boost/range/end.hpp> +#include <boost/range/value_type.hpp> + +#include <boost/algorithm/string/detail/case_conv.hpp> + +/*! \file + Defines sequence case-conversion algorithms. + Algorithms convert each element in the input sequence to the + desired case using provided locales. +*/ + +namespace boost { + namespace algorithm { + +// to_lower -----------------------------------------------// + + //! Convert to lower case + /*! + Each element of the input sequence is converted to lower + case. The result is a copy of the input converted to lower case. + It is returned as a sequence or copied to the output iterator. + + \param Output An output iterator to which the result will be copied + \param Input An input range + \param Loc A locale used for conversion + \return + An output iterator pointing just after the last inserted character or + a copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + + */ + template<typename OutputIteratorT, typename RangeT> + inline OutputIteratorT + to_lower_copy( + OutputIteratorT Output, + const RangeT& Input, + const std::locale& Loc=std::locale()) + { + return ::boost::algorithm::detail::transform_range_copy( + Output, + ::boost::as_literal(Input), + ::boost::algorithm::detail::to_lowerF< + typename range_value<RangeT>::type >(Loc)); + } + + //! Convert to lower case + /*! + \overload + */ + template<typename SequenceT> + inline SequenceT to_lower_copy( + const SequenceT& Input, + const std::locale& Loc=std::locale()) + { + return ::boost::algorithm::detail::transform_range_copy<SequenceT>( + Input, + ::boost::algorithm::detail::to_lowerF< + typename range_value<SequenceT>::type >(Loc)); + } + + //! Convert to lower case + /*! + Each element of the input sequence is converted to lower + case. The input sequence is modified in-place. + + \param Input A range + \param Loc a locale used for conversion + */ + template<typename WritableRangeT> + inline void to_lower( + WritableRangeT& Input, + const std::locale& Loc=std::locale()) + { + ::boost::algorithm::detail::transform_range( + ::boost::as_literal(Input), + ::boost::algorithm::detail::to_lowerF< + typename range_value<WritableRangeT>::type >(Loc)); + } + +// to_upper -----------------------------------------------// + + //! Convert to upper case + /*! + Each element of the input sequence is converted to upper + case. The result is a copy of the input converted to upper case. + It is returned as a sequence or copied to the output iterator + + \param Output An output iterator to which the result will be copied + \param Input An input range + \param Loc A locale used for conversion + \return + An output iterator pointing just after the last inserted character or + a copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template<typename OutputIteratorT, typename RangeT> + inline OutputIteratorT + to_upper_copy( + OutputIteratorT Output, + const RangeT& Input, + const std::locale& Loc=std::locale()) + { + return ::boost::algorithm::detail::transform_range_copy( + Output, + ::boost::as_literal(Input), + ::boost::algorithm::detail::to_upperF< + typename range_value<RangeT>::type >(Loc)); + } + + //! Convert to upper case + /*! + \overload + */ + template<typename SequenceT> + inline SequenceT to_upper_copy( + const SequenceT& Input, + const std::locale& Loc=std::locale()) + { + return ::boost::algorithm::detail::transform_range_copy<SequenceT>( + Input, + ::boost::algorithm::detail::to_upperF< + typename range_value<SequenceT>::type >(Loc)); + } + + //! Convert to upper case + /*! + Each element of the input sequence is converted to upper + case. The input sequence is modified in-place. + + \param Input An input range + \param Loc a locale used for conversion + */ + template<typename WritableRangeT> + inline void to_upper( + WritableRangeT& Input, + const std::locale& Loc=std::locale()) + { + ::boost::algorithm::detail::transform_range( + ::boost::as_literal(Input), + ::boost::algorithm::detail::to_upperF< + typename range_value<WritableRangeT>::type >(Loc)); + } + + } // namespace algorithm + + // pull names to the boost namespace + using algorithm::to_lower; + using algorithm::to_lower_copy; + using algorithm::to_upper; + using algorithm::to_upper_copy; + +} // namespace boost + +#endif // BOOST_STRING_CASE_CONV_HPP diff --git a/Utilities/BGL/boost/algorithm/string/classification.hpp b/Utilities/BGL/boost/algorithm/string/classification.hpp new file mode 100755 index 0000000000000000000000000000000000000000..e868b88b85d80204e0b5b350a8cfb184d747cd52 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/classification.hpp @@ -0,0 +1,312 @@ +// Boost string_algo library classification.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_CLASSIFICATION_HPP +#define BOOST_STRING_CLASSIFICATION_HPP + +#include <algorithm> +#include <locale> +#include <boost/range/value_type.hpp> +#include <boost/range/as_literal.hpp> +#include <boost/algorithm/string/detail/classification.hpp> +#include <boost/algorithm/string/predicate_facade.hpp> + + +/*! \file + Classification predicates are included in the library to give + some more convenience when using algorithms like \c trim() and \c all(). + They wrap functionality of STL classification functions ( e.g. \c std::isspace() ) + into generic functors. +*/ + +namespace boost { + namespace algorithm { + +// classification functor generator -------------------------------------// + + //! is_classified predicate + /*! + Construct the \c is_classified predicate. This predicate holds if the input is + of specified \c std::ctype category. + + \param Type A \c std::ctype category + \param Loc A locale used for classification + \return An instance of the \c is_classified predicate + */ + inline detail::is_classifiedF + is_classified(std::ctype_base::mask Type, const std::locale& Loc=std::locale()) + { + return detail::is_classifiedF(Type, Loc); + } + + //! is_space predicate + /*! + Construct the \c is_classified predicate for the \c ctype_base::space category. + + \param Loc A locale used for classification + \return An instance of the \c is_classified predicate + */ + inline detail::is_classifiedF + is_space(const std::locale& Loc=std::locale()) + { + return detail::is_classifiedF(std::ctype_base::space, Loc); + } + + //! is_alnum predicate + /*! + Construct the \c is_classified predicate for the \c ctype_base::alnum category. + + \param Loc A locale used for classification + \return An instance of the \c is_classified predicate + */ + inline detail::is_classifiedF + is_alnum(const std::locale& Loc=std::locale()) + { + return detail::is_classifiedF(std::ctype_base::alnum, Loc); + } + + //! is_alpha predicate + /*! + Construct the \c is_classified predicate for the \c ctype_base::alpha category. + + \param Loc A locale used for classification + \return An instance of the \c is_classified predicate + */ + inline detail::is_classifiedF + is_alpha(const std::locale& Loc=std::locale()) + { + return detail::is_classifiedF(std::ctype_base::alpha, Loc); + } + + //! is_cntrl predicate + /*! + Construct the \c is_classified predicate for the \c ctype_base::cntrl category. + + \param Loc A locale used for classification + \return An instance of the \c is_classified predicate + */ + inline detail::is_classifiedF + is_cntrl(const std::locale& Loc=std::locale()) + { + return detail::is_classifiedF(std::ctype_base::cntrl, Loc); + } + + //! is_digit predicate + /*! + Construct the \c is_classified predicate for the \c ctype_base::digit category. + + \param Loc A locale used for classification + \return An instance of the \c is_classified predicate + */ + inline detail::is_classifiedF + is_digit(const std::locale& Loc=std::locale()) + { + return detail::is_classifiedF(std::ctype_base::digit, Loc); + } + + //! is_graph predicate + /*! + Construct the \c is_classified predicate for the \c ctype_base::graph category. + + \param Loc A locale used for classification + \return An instance of the \c is_classified predicate + */ + inline detail::is_classifiedF + is_graph(const std::locale& Loc=std::locale()) + { + return detail::is_classifiedF(std::ctype_base::graph, Loc); + } + + //! is_lower predicate + /*! + Construct the \c is_classified predicate for the \c ctype_base::lower category. + + \param Loc A locale used for classification + \return An instance of \c is_classified predicate + */ + inline detail::is_classifiedF + is_lower(const std::locale& Loc=std::locale()) + { + return detail::is_classifiedF(std::ctype_base::lower, Loc); + } + + //! is_print predicate + /*! + Construct the \c is_classified predicate for the \c ctype_base::print category. + + \param Loc A locale used for classification + \return An instance of the \c is_classified predicate + */ + inline detail::is_classifiedF + is_print(const std::locale& Loc=std::locale()) + { + return detail::is_classifiedF(std::ctype_base::print, Loc); + } + + //! is_punct predicate + /*! + Construct the \c is_classified predicate for the \c ctype_base::punct category. + + \param Loc A locale used for classification + \return An instance of the \c is_classified predicate + */ + inline detail::is_classifiedF + is_punct(const std::locale& Loc=std::locale()) + { + return detail::is_classifiedF(std::ctype_base::punct, Loc); + } + + //! is_upper predicate + /*! + Construct the \c is_classified predicate for the \c ctype_base::upper category. + + \param Loc A locale used for classification + \return An instance of the \c is_classified predicate + */ + inline detail::is_classifiedF + is_upper(const std::locale& Loc=std::locale()) + { + return detail::is_classifiedF(std::ctype_base::upper, Loc); + } + + //! is_xdigit predicate + /*! + Construct the \c is_classified predicate for the \c ctype_base::xdigit category. + + \param Loc A locale used for classification + \return An instance of the \c is_classified predicate + */ + inline detail::is_classifiedF + is_xdigit(const std::locale& Loc=std::locale()) + { + return detail::is_classifiedF(std::ctype_base::xdigit, Loc); + } + + //! is_any_of predicate + /*! + Construct the \c is_any_of predicate. The predicate holds if the input + is included in the specified set of characters. + + \param Set A set of characters to be recognized + \return An instance of the \c is_any_of predicate + */ + template<typename RangeT> + inline detail::is_any_ofF< + BOOST_STRING_TYPENAME range_value<RangeT>::type> + is_any_of( const RangeT& Set ) + { + iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_set(boost::as_literal(Set)); + return detail::is_any_ofF<BOOST_STRING_TYPENAME range_value<RangeT>::type>(lit_set); + } + + //! is_from_range predicate + /*! + Construct the \c is_from_range predicate. The predicate holds if the input + is included in the specified range. (i.e. From <= Ch <= To ) + + \param From The start of the range + \param To The end of the range + \return An instance of the \c is_from_range predicate + */ + template<typename CharT> + inline detail::is_from_rangeF<CharT> is_from_range(CharT From, CharT To) + { + return detail::is_from_rangeF<CharT>(From,To); + } + + // predicate combinators ---------------------------------------------------// + + //! predicate 'and' composition predicate + /*! + Construct the \c class_and predicate. This predicate can be used + to logically combine two classification predicates. \c class_and holds, + if both predicates return true. + + \param Pred1 The first predicate + \param Pred2 The second predicate + \return An instance of the \c class_and predicate + */ + template<typename Pred1T, typename Pred2T> + inline detail::pred_andF<Pred1T, Pred2T> + operator&&( + const predicate_facade<Pred1T>& Pred1, + const predicate_facade<Pred2T>& Pred2 ) + { + // Doing the static_cast with the pointer instead of the reference + // is a workaround for some compilers which have problems with + // static_cast's of template references, i.e. CW8. /grafik/ + return detail::pred_andF<Pred1T,Pred2T>( + *static_cast<const Pred1T*>(&Pred1), + *static_cast<const Pred2T*>(&Pred2) ); + } + + //! predicate 'or' composition predicate + /*! + Construct the \c class_or predicate. This predicate can be used + to logically combine two classification predicates. \c class_or holds, + if one of the predicates return true. + + \param Pred1 The first predicate + \param Pred2 The second predicate + \return An instance of the \c class_or predicate + */ + template<typename Pred1T, typename Pred2T> + inline detail::pred_orF<Pred1T, Pred2T> + operator||( + const predicate_facade<Pred1T>& Pred1, + const predicate_facade<Pred2T>& Pred2 ) + { + // Doing the static_cast with the pointer instead of the reference + // is a workaround for some compilers which have problems with + // static_cast's of template references, i.e. CW8. /grafik/ + return detail::pred_orF<Pred1T,Pred2T>( + *static_cast<const Pred1T*>(&Pred1), + *static_cast<const Pred2T*>(&Pred2)); + } + + //! predicate negation operator + /*! + Construct the \c class_not predicate. This predicate represents a negation. + \c class_or holds if of the predicates return false. + + \param Pred The predicate to be negated + \return An instance of the \c class_not predicate + */ + template<typename PredT> + inline detail::pred_notF<PredT> + operator!( const predicate_facade<PredT>& Pred ) + { + // Doing the static_cast with the pointer instead of the reference + // is a workaround for some compilers which have problems with + // static_cast's of template references, i.e. CW8. /grafik/ + return detail::pred_notF<PredT>(*static_cast<const PredT*>(&Pred)); + } + + } // namespace algorithm + + // pull names to the boost namespace + using algorithm::is_classified; + using algorithm::is_space; + using algorithm::is_alnum; + using algorithm::is_alpha; + using algorithm::is_cntrl; + using algorithm::is_digit; + using algorithm::is_graph; + using algorithm::is_lower; + using algorithm::is_upper; + using algorithm::is_print; + using algorithm::is_punct; + using algorithm::is_xdigit; + using algorithm::is_any_of; + using algorithm::is_from_range; + +} // namespace boost + +#endif // BOOST_STRING_PREDICATE_HPP diff --git a/Utilities/BGL/boost/algorithm/string/compare.hpp b/Utilities/BGL/boost/algorithm/string/compare.hpp new file mode 100755 index 0000000000000000000000000000000000000000..f610b36431337430f9440d163791b0a3e3930e09 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/compare.hpp @@ -0,0 +1,199 @@ +// Boost string_algo library compare.hpp header file -------------------------// + +// Copyright Pavol Droba 2002-2006. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_COMPARE_HPP +#define BOOST_STRING_COMPARE_HPP + +#include <boost/algorithm/string/config.hpp> +#include <locale> + +/*! \file + Defines element comparison predicates. Many algorithms in this library can + take an additional argument with a predicate used to compare elements. + This makes it possible, for instance, to have case insensitive versions + of the algorithms. +*/ + +namespace boost { + namespace algorithm { + + // is_equal functor -----------------------------------------------// + + //! is_equal functor + /*! + Standard STL equal_to only handle comparison between arguments + of the same type. This is a less restrictive version which wraps operator ==. + */ + struct is_equal + { + //! Function operator + /*! + Compare two operands for equality + */ + template< typename T1, typename T2 > + bool operator()( const T1& Arg1, const T2& Arg2 ) const + { + return Arg1==Arg2; + } + }; + + //! case insensitive version of is_equal + /*! + Case insensitive comparison predicate. Comparison is done using + specified locales. + */ + struct is_iequal + { + //! Constructor + /*! + \param Loc locales used for comparison + */ + is_iequal( const std::locale& Loc=std::locale() ) : + m_Loc( Loc ) {} + + //! Function operator + /*! + Compare two operands. Case is ignored. + */ + template< typename T1, typename T2 > + bool operator()( const T1& Arg1, const T2& Arg2 ) const + { + #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL) + return std::toupper(Arg1)==std::toupper(Arg2); + #else + return std::toupper<T1>(Arg1,m_Loc)==std::toupper<T2>(Arg2,m_Loc); + #endif + } + + private: + std::locale m_Loc; + }; + + // is_less functor -----------------------------------------------// + + //! is_less functor + /*! + Convenient version of standard std::less. Operation is templated, therefore it is + not required to specify the exact types upon the construction + */ + struct is_less + { + //! Functor operation + /*! + Compare two operands using > operator + */ + template< typename T1, typename T2 > + bool operator()( const T1& Arg1, const T2& Arg2 ) const + { + return Arg1<Arg2; + } + }; + + + //! case insensitive version of is_less + /*! + Case insensitive comparison predicate. Comparison is done using + specified locales. + */ + struct is_iless + { + //! Constructor + /*! + \param Loc locales used for comparison + */ + is_iless( const std::locale& Loc=std::locale() ) : + m_Loc( Loc ) {} + + //! Function operator + /*! + Compare two operands. Case is ignored. + */ + template< typename T1, typename T2 > + bool operator()( const T1& Arg1, const T2& Arg2 ) const + { + #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL) + return std::toupper(Arg1)<std::toupper(Arg2); + #else + return std::toupper<T1>(Arg1,m_Loc)<std::toupper<T2>(Arg2,m_Loc); + #endif + } + + private: + std::locale m_Loc; + }; + + // is_not_greater functor -----------------------------------------------// + + //! is_not_greater functor + /*! + Convenient version of standard std::not_greater_to. Operation is templated, therefore it is + not required to specify the exact types upon the construction + */ + struct is_not_greater + { + //! Functor operation + /*! + Compare two operands using > operator + */ + template< typename T1, typename T2 > + bool operator()( const T1& Arg1, const T2& Arg2 ) const + { + return Arg1<=Arg2; + } + }; + + + //! case insensitive version of is_not_greater + /*! + Case insensitive comparison predicate. Comparison is done using + specified locales. + */ + struct is_not_igreater + { + //! Constructor + /*! + \param Loc locales used for comparison + */ + is_not_igreater( const std::locale& Loc=std::locale() ) : + m_Loc( Loc ) {} + + //! Function operator + /*! + Compare two operands. Case is ignored. + */ + template< typename T1, typename T2 > + bool operator()( const T1& Arg1, const T2& Arg2 ) const + { + #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL) + return std::toupper(Arg1)<=std::toupper(Arg2); + #else + return std::toupper<T1>(Arg1,m_Loc)<=std::toupper<T2>(Arg2,m_Loc); + #endif + } + + private: + std::locale m_Loc; + }; + + + } // namespace algorithm + + // pull names to the boost namespace + using algorithm::is_equal; + using algorithm::is_iequal; + using algorithm::is_less; + using algorithm::is_iless; + using algorithm::is_not_greater; + using algorithm::is_not_igreater; + +} // namespace boost + + +#endif // BOOST_STRING_COMPARE_HPP diff --git a/Utilities/BGL/boost/algorithm/string/concept.hpp b/Utilities/BGL/boost/algorithm/string/concept.hpp new file mode 100755 index 0000000000000000000000000000000000000000..2ef4ca731679795750e45a9d2429d5a348f1deda --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/concept.hpp @@ -0,0 +1,83 @@ +// Boost string_algo library concept.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_CONCEPT_HPP +#define BOOST_STRING_CONCEPT_HPP + +#include <boost/concept_check.hpp> +#include <boost/range/iterator_range.hpp> +#include <boost/range/begin.hpp> +#include <boost/range/end.hpp> + +/*! \file + Defines concepts used in string_algo library +*/ + +namespace boost { + namespace algorithm { + + //! Finder concept + /*! + Defines the Finder concept. Finder is a functor which selects + an arbitrary part of a string. Search is performed on + the range specified by starting and ending iterators. + + Result of the find operation must be convertible to iterator_range. + */ + template<typename FinderT, typename IteratorT> + struct FinderConcept + { + private: + typedef iterator_range<IteratorT> range; + public: + void constraints() + { + // Operation + r=(*pF)(i,i); + } + private: + range r; + IteratorT i; + FinderT* pF; + }; // Finder_concept + + + //! Formatter concept + /*! + Defines the Formatter concept. Formatter is a functor, which + takes a result from a finder operation and transforms it + in a specific way. + + Result must be a container supported by container_traits, + or a reference to it. + */ + template<typename FormatterT, typename FinderT, typename IteratorT> + struct FormatterConcept + { + public: + void constraints() + { + // Operation + ::boost::begin((*pFo)( (*pF)(i,i) )); + ::boost::end((*pFo)( (*pF)(i,i) )); + } + private: + IteratorT i; + FinderT* pF; + FormatterT *pFo; + }; // FormatterConcept; + + } // namespace algorithm +} // namespace boost + + + + +#endif // BOOST_STRING_CONCEPT_HPP diff --git a/Utilities/BGL/boost/algorithm/string/config.hpp b/Utilities/BGL/boost/algorithm/string/config.hpp new file mode 100755 index 0000000000000000000000000000000000000000..d10c6f5d8afaae6afab4236b249446d56ba60eaa --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/config.hpp @@ -0,0 +1,28 @@ +// Boost string_algo library config.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_CONFIG_HPP +#define BOOST_STRING_CONFIG_HPP + +#include <boost/config.hpp> +#include <boost/detail/workaround.hpp> + +#ifdef BOOST_STRING_DEDUCED_TYPENAME +# error "macro already defined!" +#endif + +#define BOOST_STRING_TYPENAME BOOST_DEDUCED_TYPENAME + +// Metrowerks workaround +#if BOOST_WORKAROUND(__MWERKS__, <= 0x3003) // 8.x +#pragma parse_func_templ off +#endif + +#endif // BOOST_STRING_CONFIG_HPP diff --git a/Utilities/BGL/boost/algorithm/string/constants.hpp b/Utilities/BGL/boost/algorithm/string/constants.hpp new file mode 100755 index 0000000000000000000000000000000000000000..9022d43589ba6033b7e64b4bfa5be26a3869e3de --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/constants.hpp @@ -0,0 +1,36 @@ +// Boost string_algo library constants.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_CONSTANTS_HPP +#define BOOST_STRING_CONSTANTS_HPP + +namespace boost { + namespace algorithm { + + //! Token compression mode + /*! + Specifies token compression mode for the token_finder. + */ + enum token_compress_mode_type + { + token_compress_on, //!< Compress adjacent tokens + token_compress_off //!< Do not compress adjacent tokens + }; + + } // namespace algorithm + + // pull the names to the boost namespace + using algorithm::token_compress_on; + using algorithm::token_compress_off; + +} // namespace boost + +#endif // BOOST_STRING_CONSTANTS_HPP + diff --git a/Utilities/BGL/boost/algorithm/string/detail/case_conv.hpp b/Utilities/BGL/boost/algorithm/string/detail/case_conv.hpp new file mode 100755 index 0000000000000000000000000000000000000000..c3141e947bde4052e2e660f9a02045feeb6dbd2e --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/detail/case_conv.hpp @@ -0,0 +1,121 @@ +// Boost string_algo library string_funct.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_CASE_CONV_DETAIL_HPP +#define BOOST_STRING_CASE_CONV_DETAIL_HPP + +#include <boost/algorithm/string/config.hpp> +#include <locale> +#include <functional> + +namespace boost { + namespace algorithm { + namespace detail { + +// case conversion functors -----------------------------------------------// + +#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) +#pragma warning(push) +#pragma warning(disable:4512) //assignment operator could not be generated +#endif + + // a tolower functor + template<typename CharT> + struct to_lowerF : public std::unary_function<CharT, CharT> + { + // Constructor + to_lowerF( const std::locale& Loc ) : m_Loc( Loc ) {} + + // Operation + CharT operator ()( CharT Ch ) const + { + #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL) + return std::tolower( Ch); + #else + return std::tolower<CharT>( Ch, m_Loc ); + #endif + } + private: + const std::locale& m_Loc; + }; + + // a toupper functor + template<typename CharT> + struct to_upperF : public std::unary_function<CharT, CharT> + { + // Constructor + to_upperF( const std::locale& Loc ) : m_Loc( Loc ) {} + + // Operation + CharT operator ()( CharT Ch ) const + { + #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL) + return std::toupper( Ch); + #else + return std::toupper<CharT>( Ch, m_Loc ); + #endif + } + private: + const std::locale& m_Loc; + }; + +#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) +#pragma warning(pop) +#endif + +// algorithm implementation ------------------------------------------------------------------------- + + // Transform a range + template<typename OutputIteratorT, typename RangeT, typename FunctorT> + OutputIteratorT transform_range_copy( + OutputIteratorT Output, + const RangeT& Input, + FunctorT Functor) + { + return std::transform( + ::boost::begin(Input), + ::boost::end(Input), + Output, + Functor); + } + + // Transform a range (in-place) + template<typename RangeT, typename FunctorT> + void transform_range( + const RangeT& Input, + FunctorT Functor) + { + std::transform( + ::boost::begin(Input), + ::boost::end(Input), + ::boost::begin(Input), + Functor); + } + + template<typename SequenceT, typename RangeT, typename FunctorT> + inline SequenceT transform_range_copy( + const RangeT& Input, + FunctorT Functor) + { + return SequenceT( + ::boost::make_transform_iterator( + ::boost::begin(Input), + Functor), + ::boost::make_transform_iterator( + ::boost::end(Input), + Functor)); + } + + } // namespace detail + } // namespace algorithm +} // namespace boost + + +#endif // BOOST_STRING_CASE_CONV_DETAIL_HPP diff --git a/Utilities/BGL/boost/algorithm/string/detail/classification.hpp b/Utilities/BGL/boost/algorithm/string/detail/classification.hpp new file mode 100755 index 0000000000000000000000000000000000000000..e5e09591c22bba3db21eda4172fdc068f2f17e93 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/detail/classification.hpp @@ -0,0 +1,353 @@ +// Boost string_algo library classification.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_CLASSIFICATION_DETAIL_HPP +#define BOOST_STRING_CLASSIFICATION_DETAIL_HPP + +#include <boost/algorithm/string/config.hpp> +#include <algorithm> +#include <functional> +#include <locale> + +#include <boost/range/begin.hpp> +#include <boost/range/end.hpp> + +#include <boost/algorithm/string/predicate_facade.hpp> +#include <boost/type_traits/remove_const.hpp> + +namespace boost { + namespace algorithm { + namespace detail { + +// classification functors -----------------------------------------------// + + // is_classified functor + struct is_classifiedF : + public predicate_facade<is_classifiedF> + { + // Boost.Lambda support + template <class Args> struct sig { typedef bool type; }; + + // Constructor from a locale + is_classifiedF(std::ctype_base::mask Type, std::locale const & Loc = std::locale()) : + m_Type(Type), m_Locale(Loc) {} + // Operation + template<typename CharT> + bool operator()( CharT Ch ) const + { + return std::use_facet< std::ctype<CharT> >(m_Locale).is( m_Type, Ch ); + } + + #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x582) && !defined(_USE_OLD_RW_STL) + template<> + bool operator()( char const Ch ) const + { + return std::use_facet< std::ctype<char> >(m_Locale).is( m_Type, Ch ); + } + #endif + + private: + std::ctype_base::mask m_Type; + std::locale m_Locale; + }; + + + // is_any_of functor + /* + returns true if the value is from the specified set + */ + template<typename CharT> + struct is_any_ofF : + public predicate_facade<is_any_ofF<CharT> > + { + private: + // set cannot operate on const value-type + typedef typename ::boost::remove_const<CharT>::type set_value_type; + + public: + // Boost.Lambda support + template <class Args> struct sig { typedef bool type; }; + + // Constructor + template<typename RangeT> + is_any_ofF( const RangeT& Range ) : m_Size(0) + { + // Prepare storage + m_Storage.m_dynSet=0; + + std::size_t Size=::boost::distance(Range); + m_Size=Size; + set_value_type* Storage=0; + + if(use_fixed_storage(m_Size)) + { + // Use fixed storage + Storage=&m_Storage.m_fixSet[0]; + } + else + { + // Use dynamic storage + m_Storage.m_dynSet=new set_value_type[m_Size]; + Storage=m_Storage.m_dynSet; + } + + // Use fixed storage + ::std::copy(::boost::begin(Range), ::boost::end(Range), Storage); + ::std::sort(Storage, Storage+m_Size); + } + + // Copy constructor + is_any_ofF(const is_any_ofF& Other) : m_Size(Other.m_Size) + { + // Prepare storage + m_Storage.m_dynSet=0; + const set_value_type* SrcStorage=0; + set_value_type* DestStorage=0; + + if(use_fixed_storage(m_Size)) + { + // Use fixed storage + DestStorage=&m_Storage.m_fixSet[0]; + SrcStorage=&Other.m_Storage.m_fixSet[0]; + } + else + { + // Use dynamic storage + m_Storage.m_dynSet=new set_value_type[m_Size]; + DestStorage=m_Storage.m_dynSet; + SrcStorage=Other.m_Storage.m_dynSet; + } + + // Use fixed storage + ::memcpy(DestStorage, SrcStorage, sizeof(set_value_type)*m_Size); + } + + // Destructor + ~is_any_ofF() + { + if(!use_fixed_storage(m_Size) && m_Storage.m_dynSet!=0) + { + delete [] m_Storage.m_dynSet; + } + } + + // Assignment + is_any_ofF& operator=(const is_any_ofF& Other) + { + // Handle self assignment + if(this==&Other) return *this; + + // Prepare storage + const set_value_type* SrcStorage; + set_value_type* DestStorage; + + if(use_fixed_storage(Other.m_Size)) + { + // Use fixed storage + DestStorage=&m_Storage.m_fixSet[0]; + SrcStorage=&Other.m_Storage.m_fixSet[0]; + + // Delete old storage if was present + if(!use_fixed_storage(m_Size) && m_Storage.m_dynSet!=0) + { + delete [] m_Storage.m_dynSet; + } + + // Set new size + m_Size=Other.m_Size; + } + else + { + // Other uses dynamic storage + SrcStorage=Other.m_Storage.m_dynSet; + + // Check what kind of storage are we using right now + if(use_fixed_storage(m_Size)) + { + // Using fixed storage, allocate new + set_value_type* pTemp=new set_value_type[Other.m_Size]; + DestStorage=pTemp; + m_Storage.m_dynSet=pTemp; + m_Size=Other.m_Size; + } + else + { + // Using dynamic storage, check if can reuse + if(m_Storage.m_dynSet!=0 && m_Size>=Other.m_Size && m_Size<Other.m_Size*2) + { + // Reuse the current storage + DestStorage=m_Storage.m_dynSet; + m_Size=Other.m_Size; + } + else + { + // Allocate the new one + set_value_type* pTemp=new set_value_type[Other.m_Size]; + DestStorage=pTemp; + + // Delete old storage if necessary + if(m_Storage.m_dynSet!=0) + { + delete [] m_Storage.m_dynSet; + } + // Store the new storage + m_Storage.m_dynSet=pTemp; + // Set new size + m_Size=Other.m_Size; + } + } + } + + // Copy the data + ::memcpy(DestStorage, SrcStorage, sizeof(set_value_type)*m_Size); + + return *this; + } + + // Operation + template<typename Char2T> + bool operator()( Char2T Ch ) const + { + const set_value_type* Storage= + (use_fixed_storage(m_Size)) + ? &m_Storage.m_fixSet[0] + : m_Storage.m_dynSet; + + return ::std::binary_search(Storage, Storage+m_Size, Ch); + } + private: + // check if the size is eligible for fixed storage + static bool use_fixed_storage(std::size_t size) + { + return size<=sizeof(set_value_type*)*2; + } + + + private: + // storage + // The actual used storage is selected on the type + union + { + set_value_type* m_dynSet; + set_value_type m_fixSet[sizeof(set_value_type*)*2]; + } + m_Storage; + + // storage size + ::std::size_t m_Size; + }; + + // is_from_range functor + /* + returns true if the value is from the specified range. + (i.e. x>=From && x>=To) + */ + template<typename CharT> + struct is_from_rangeF : + public predicate_facade< is_from_rangeF<CharT> > + { + // Boost.Lambda support + template <class Args> struct sig { typedef bool type; }; + + // Constructor + is_from_rangeF( CharT From, CharT To ) : m_From(From), m_To(To) {} + + // Operation + template<typename Char2T> + bool operator()( Char2T Ch ) const + { + return ( m_From <= Ch ) && ( Ch <= m_To ); + } + + private: + CharT m_From; + CharT m_To; + }; + + // class_and composition predicate + template<typename Pred1T, typename Pred2T> + struct pred_andF : + public predicate_facade< pred_andF<Pred1T,Pred2T> > + { + public: + + // Boost.Lambda support + template <class Args> struct sig { typedef bool type; }; + + // Constructor + pred_andF( Pred1T Pred1, Pred2T Pred2 ) : + m_Pred1(Pred1), m_Pred2(Pred2) {} + + // Operation + template<typename CharT> + bool operator()( CharT Ch ) const + { + return m_Pred1(Ch) && m_Pred2(Ch); + } + + private: + Pred1T m_Pred1; + Pred2T m_Pred2; + }; + + // class_or composition predicate + template<typename Pred1T, typename Pred2T> + struct pred_orF : + public predicate_facade< pred_orF<Pred1T,Pred2T> > + { + public: + // Boost.Lambda support + template <class Args> struct sig { typedef bool type; }; + + // Constructor + pred_orF( Pred1T Pred1, Pred2T Pred2 ) : + m_Pred1(Pred1), m_Pred2(Pred2) {} + + // Operation + template<typename CharT> + bool operator()( CharT Ch ) const + { + return m_Pred1(Ch) || m_Pred2(Ch); + } + + private: + Pred1T m_Pred1; + Pred2T m_Pred2; + }; + + // class_not composition predicate + template< typename PredT > + struct pred_notF : + public predicate_facade< pred_notF<PredT> > + { + public: + // Boost.Lambda support + template <class Args> struct sig { typedef bool type; }; + + // Constructor + pred_notF( PredT Pred ) : m_Pred(Pred) {} + + // Operation + template<typename CharT> + bool operator()( CharT Ch ) const + { + return !m_Pred(Ch); + } + + private: + PredT m_Pred; + }; + + } // namespace detail + } // namespace algorithm +} // namespace boost + + +#endif // BOOST_STRING_CLASSIFICATION_DETAIL_HPP diff --git a/Utilities/BGL/boost/algorithm/string/detail/find_format.hpp b/Utilities/BGL/boost/algorithm/string/detail/find_format.hpp new file mode 100755 index 0000000000000000000000000000000000000000..1c6e006d8e20f019f3a78e17da9bedf495e5327b --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/detail/find_format.hpp @@ -0,0 +1,194 @@ +// Boost string_algo library find_format.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_FIND_FORMAT_DETAIL_HPP +#define BOOST_STRING_FIND_FORMAT_DETAIL_HPP + +#include <boost/algorithm/string/config.hpp> +#include <boost/range/iterator_range.hpp> +#include <boost/range/const_iterator.hpp> +#include <boost/range/iterator.hpp> +#include <boost/algorithm/string/detail/find_format_store.hpp> +#include <boost/algorithm/string/detail/replace_storage.hpp> + +namespace boost { + namespace algorithm { + namespace detail { + +// find_format_copy (iterator variant) implementation -------------------------------// + + template< + typename OutputIteratorT, + typename InputT, + typename FormatterT, + typename FindResultT, + typename FormatResultT > + inline OutputIteratorT find_format_copy_impl2( + OutputIteratorT Output, + const InputT& Input, + FormatterT Formatter, + const FindResultT& FindResult, + const FormatResultT& FormatResult ) + { + typedef find_format_store< + BOOST_STRING_TYPENAME + range_const_iterator<InputT>::type, + FormatterT, + FormatResultT > store_type; + + // Create store for the find result + store_type M( FindResult, FormatResult, Formatter ); + + if ( !M ) + { + // Match not found - return original sequence + std::copy( ::boost::begin(Input), ::boost::end(Input), Output ); + return Output; + } + + // Copy the beginning of the sequence + std::copy( ::boost::begin(Input), ::boost::begin(M), Output ); + // Format find result + // Copy formated result + std::copy( ::boost::begin(M.format_result()), ::boost::end(M.format_result()), Output ); + // Copy the rest of the sequence + std::copy( M.end(), ::boost::end(Input), Output ); + + return Output; + } + + template< + typename OutputIteratorT, + typename InputT, + typename FormatterT, + typename FindResultT > + inline OutputIteratorT find_format_copy_impl( + OutputIteratorT Output, + const InputT& Input, + FormatterT Formatter, + const FindResultT& FindResult ) + { + return ::boost::algorithm::detail::find_format_copy_impl2( + Output, + Input, + Formatter, + FindResult, + Formatter(FindResult) ); + } + + +// find_format_copy implementation --------------------------------------------------// + + template< + typename InputT, + typename FormatterT, + typename FindResultT, + typename FormatResultT > + inline InputT find_format_copy_impl2( + const InputT& Input, + FormatterT Formatter, + const FindResultT& FindResult, + const FormatResultT& FormatResult) + { + typedef find_format_store< + BOOST_STRING_TYPENAME + range_const_iterator<InputT>::type, + FormatterT, + FormatResultT > store_type; + + // Create store for the find result + store_type M( FindResult, FormatResult, Formatter ); + + if ( !M ) + { + // Match not found - return original sequence + return InputT( Input ); + } + + InputT Output; + // Copy the beginning of the sequence + insert( Output, ::boost::end(Output), ::boost::begin(Input), M.begin() ); + // Copy formated result + insert( Output, ::boost::end(Output), M.format_result() ); + // Copy the rest of the sequence + insert( Output, ::boost::end(Output), M.end(), ::boost::end(Input) ); + + return Output; + } + + template< + typename InputT, + typename FormatterT, + typename FindResultT > + inline InputT find_format_copy_impl( + const InputT& Input, + FormatterT Formatter, + const FindResultT& FindResult) + { + return ::boost::algorithm::detail::find_format_copy_impl2( + Input, + Formatter, + FindResult, + Formatter(FindResult) ); + } + + // replace implementation ----------------------------------------------------// + + template< + typename InputT, + typename FormatterT, + typename FindResultT, + typename FormatResultT > + inline void find_format_impl2( + InputT& Input, + FormatterT Formatter, + const FindResultT& FindResult, + const FormatResultT& FormatResult) + { + typedef find_format_store< + BOOST_STRING_TYPENAME + range_iterator<InputT>::type, + FormatterT, + FormatResultT > store_type; + + // Create store for the find result + store_type M( FindResult, FormatResult, Formatter ); + + if ( !M ) + { + // Search not found - return original sequence + return; + } + + // Replace match + ::boost::algorithm::detail::replace( Input, M.begin(), M.end(), M.format_result() ); + } + + template< + typename InputT, + typename FormatterT, + typename FindResultT > + inline void find_format_impl( + InputT& Input, + FormatterT Formatter, + const FindResultT& FindResult) + { + ::boost::algorithm::detail::find_format_impl2( + Input, + Formatter, + FindResult, + Formatter(FindResult) ); + } + + } // namespace detail + } // namespace algorithm +} // namespace boost + +#endif // BOOST_STRING_FIND_FORMAT_DETAIL_HPP diff --git a/Utilities/BGL/boost/algorithm/string/detail/find_format_all.hpp b/Utilities/BGL/boost/algorithm/string/detail/find_format_all.hpp new file mode 100755 index 0000000000000000000000000000000000000000..873388b0003b96342d754515927296a412837b15 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/detail/find_format_all.hpp @@ -0,0 +1,263 @@ +// Boost string_algo library find_format_all.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_FIND_FORMAT_ALL_DETAIL_HPP +#define BOOST_STRING_FIND_FORMAT_ALL_DETAIL_HPP + +#include <boost/algorithm/string/config.hpp> +#include <boost/range/iterator_range.hpp> +#include <boost/range/const_iterator.hpp> +#include <boost/range/value_type.hpp> +#include <boost/algorithm/string/detail/find_format_store.hpp> +#include <boost/algorithm/string/detail/replace_storage.hpp> + +namespace boost { + namespace algorithm { + namespace detail { + +// find_format_all_copy (iterator variant) implementation ---------------------------// + + template< + typename OutputIteratorT, + typename InputT, + typename FinderT, + typename FormatterT, + typename FindResultT, + typename FormatResultT > + inline OutputIteratorT find_format_all_copy_impl2( + OutputIteratorT Output, + const InputT& Input, + FinderT Finder, + FormatterT Formatter, + const FindResultT& FindResult, + const FormatResultT& FormatResult ) + { + typedef BOOST_STRING_TYPENAME + range_const_iterator<InputT>::type input_iterator_type; + + typedef find_format_store< + input_iterator_type, + FormatterT, + FormatResultT > store_type; + + // Create store for the find result + store_type M( FindResult, FormatResult, Formatter ); + + // Initialize last match + input_iterator_type LastMatch=::boost::begin(Input); + + // Iterate through all matches + while( M ) + { + // Copy the beginning of the sequence + std::copy( LastMatch, M.begin(), Output ); + // Copy formated result + std::copy( ::boost::begin(M.format_result()), ::boost::end(M.format_result()), Output ); + + // Proceed to the next match + LastMatch=M.end(); + M=Finder( LastMatch, ::boost::end(Input) ); + } + + // Copy the rest of the sequence + std::copy( LastMatch, ::boost::end(Input), Output ); + + return Output; + } + + template< + typename OutputIteratorT, + typename InputT, + typename FinderT, + typename FormatterT, + typename FindResultT > + inline OutputIteratorT find_format_all_copy_impl( + OutputIteratorT Output, + const InputT& Input, + FinderT Finder, + FormatterT Formatter, + const FindResultT& FindResult ) + { + return ::boost::algorithm::detail::find_format_all_copy_impl2( + Output, + Input, + Finder, + Formatter, + FindResult, + Formatter(FindResult) ); + } + + // find_format_all_copy implementation ----------------------------------------------// + + template< + typename InputT, + typename FinderT, + typename FormatterT, + typename FindResultT, + typename FormatResultT > + inline InputT find_format_all_copy_impl2( + const InputT& Input, + FinderT Finder, + FormatterT Formatter, + const FindResultT& FindResult, + const FormatResultT& FormatResult) + { + typedef BOOST_STRING_TYPENAME + range_const_iterator<InputT>::type input_iterator_type; + + typedef find_format_store< + input_iterator_type, + FormatterT, + FormatResultT > store_type; + + // Create store for the find result + store_type M( FindResult, FormatResult, Formatter ); + + // Initialize last match + input_iterator_type LastMatch=::boost::begin(Input); + + // Output temporary + InputT Output; + + // Iterate through all matches + while( M ) + { + // Copy the beginning of the sequence + insert( Output, ::boost::end(Output), LastMatch, M.begin() ); + // Copy formated result + insert( Output, ::boost::end(Output), M.format_result() ); + + // Proceed to the next match + LastMatch=M.end(); + M=Finder( LastMatch, ::boost::end(Input) ); + } + + // Copy the rest of the sequence + ::boost::algorithm::detail::insert( Output, ::boost::end(Output), LastMatch, ::boost::end(Input) ); + + return Output; + } + + template< + typename InputT, + typename FinderT, + typename FormatterT, + typename FindResultT > + inline InputT find_format_all_copy_impl( + const InputT& Input, + FinderT Finder, + FormatterT Formatter, + const FindResultT& FindResult) + { + return ::boost::algorithm::detail::find_format_all_copy_impl2( + Input, + Finder, + Formatter, + FindResult, + Formatter(FindResult) ); + } + + // find_format_all implementation ------------------------------------------------// + + template< + typename InputT, + typename FinderT, + typename FormatterT, + typename FindResultT, + typename FormatResultT > + inline void find_format_all_impl2( + InputT& Input, + FinderT Finder, + FormatterT Formatter, + FindResultT FindResult, + FormatResultT FormatResult) + { + typedef BOOST_STRING_TYPENAME + range_iterator<InputT>::type input_iterator_type; + typedef find_format_store< + input_iterator_type, + FormatterT, + FormatResultT > store_type; + + // Create store for the find result + store_type M( FindResult, FormatResult, Formatter ); + + // Instantiate replacement storage + std::deque< + BOOST_STRING_TYPENAME range_value<InputT>::type> Storage; + + // Initialize replacement iterators + input_iterator_type InsertIt=::boost::begin(Input); + input_iterator_type SearchIt=::boost::begin(Input); + + while( M ) + { + // process the segment + InsertIt=process_segment( + Storage, + Input, + InsertIt, + SearchIt, + M.begin() ); + + // Adjust search iterator + SearchIt=M.end(); + + // Copy formated replace to the storage + ::boost::algorithm::detail::copy_to_storage( Storage, M.format_result() ); + + // Find range for a next match + M=Finder( SearchIt, ::boost::end(Input) ); + } + + // process the last segment + InsertIt=::boost::algorithm::detail::process_segment( + Storage, + Input, + InsertIt, + SearchIt, + ::boost::end(Input) ); + + if ( Storage.empty() ) + { + // Truncate input + ::boost::algorithm::detail::erase( Input, InsertIt, ::boost::end(Input) ); + } + else + { + // Copy remaining data to the end of input + ::boost::algorithm::detail::insert( Input, ::boost::end(Input), Storage.begin(), Storage.end() ); + } + } + + template< + typename InputT, + typename FinderT, + typename FormatterT, + typename FindResultT > + inline void find_format_all_impl( + InputT& Input, + FinderT Finder, + FormatterT Formatter, + FindResultT FindResult) + { + ::boost::algorithm::detail::find_format_all_impl2( + Input, + Finder, + Formatter, + FindResult, + Formatter(FindResult) ); + } + + } // namespace detail + } // namespace algorithm +} // namespace boost + +#endif // BOOST_STRING_FIND_FORMAT_ALL_DETAIL_HPP diff --git a/Utilities/BGL/boost/algorithm/string/detail/find_format_store.hpp b/Utilities/BGL/boost/algorithm/string/detail/find_format_store.hpp new file mode 100755 index 0000000000000000000000000000000000000000..a91f8b2afad4ad82e2e2506c179059827c26a8e7 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/detail/find_format_store.hpp @@ -0,0 +1,78 @@ +// Boost string_algo library find_format_store.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_FIND_FORMAT_STORE_DETAIL_HPP +#define BOOST_STRING_FIND_FORMAT_STORE_DETAIL_HPP + +#include <boost/algorithm/string/config.hpp> +#include <boost/range/iterator_range.hpp> + +namespace boost { + namespace algorithm { + namespace detail { + +// temporary format and find result storage --------------------------------// + +#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) +#pragma warning(push) +#pragma warning(disable:4512) //assignment operator could not be generated +#endif + template< + typename ForwardIteratorT, + typename FormatterT, + typename FormatResultT > + class find_format_store : + public iterator_range<ForwardIteratorT> + { + public: + // typedefs + typedef iterator_range<ForwardIteratorT> base_type; + typedef FormatterT formatter_type; + typedef FormatResultT format_result_type; + + public: + // Construction + find_format_store( + const base_type& FindResult, + const format_result_type& FormatResult, + const formatter_type& Formatter ) : + base_type(FindResult), + m_FormatResult(FormatResult), + m_Formatter(Formatter) {} + + // Assignment + template< typename FindResultT > + find_format_store& operator=( FindResultT FindResult ) + { + iterator_range<ForwardIteratorT>::operator=(FindResult); + m_FormatResult=m_Formatter(FindResult); + + return *this; + } + + // Retrieve format result + const format_result_type& format_result() + { + return m_FormatResult; + } + + private: + format_result_type m_FormatResult; + const formatter_type& m_Formatter; + }; + +#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) +#pragma warning(pop) +#endif + } // namespace detail + } // namespace algorithm +} // namespace boost + +#endif // BOOST_STRING_FIND_FORMAT_STORE_DETAIL_HPP diff --git a/Utilities/BGL/boost/algorithm/string/detail/find_iterator.hpp b/Utilities/BGL/boost/algorithm/string/detail/find_iterator.hpp new file mode 100755 index 0000000000000000000000000000000000000000..e2d27f08682af1b2d9c155e9bd2276bad2a8d017 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/detail/find_iterator.hpp @@ -0,0 +1,87 @@ +// Boost string_algo library find_iterator.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_FIND_ITERATOR_DETAIL_HPP +#define BOOST_STRING_FIND_ITERATOR_DETAIL_HPP + +#include <boost/algorithm/string/config.hpp> +#include <boost/range/iterator_range.hpp> +#include <boost/iterator/iterator_facade.hpp> +#include <boost/iterator/iterator_categories.hpp> +#include <boost/function.hpp> + +namespace boost { + namespace algorithm { + namespace detail { + +// find_iterator base -----------------------------------------------// + + // Find iterator base + template<typename IteratorT> + class find_iterator_base + { + protected: + // typedefs + typedef IteratorT input_iterator_type; + typedef iterator_range<IteratorT> match_type; + typedef function2< + match_type, + input_iterator_type, + input_iterator_type> finder_type; + + protected: + // Protected construction/destruction + + // Default constructor + find_iterator_base() {}; + // Copy construction + find_iterator_base( const find_iterator_base& Other ) : + m_Finder(Other.m_Finder) {} + + // Constructor + template<typename FinderT> + find_iterator_base( FinderT Finder, int ) : + m_Finder(Finder) {} + + // Destructor + ~find_iterator_base() {} + + // Find operation + match_type do_find( + input_iterator_type Begin, + input_iterator_type End ) const + { + if (!m_Finder.empty()) + { + return m_Finder(Begin,End); + } + else + { + return match_type(End,End); + } + } + + // Check + bool is_null() const + { + return m_Finder.empty(); + } + + private: + // Finder + finder_type m_Finder; + }; + + } // namespace detail + } // namespace algorithm +} // namespace boost + + +#endif // BOOST_STRING_FIND_ITERATOR_DETAIL_HPP diff --git a/Utilities/BGL/boost/algorithm/string/detail/finder.hpp b/Utilities/BGL/boost/algorithm/string/detail/finder.hpp new file mode 100755 index 0000000000000000000000000000000000000000..c418fadb558204a3c1d461f08b4d9562d5447313 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/detail/finder.hpp @@ -0,0 +1,646 @@ +// Boost string_algo library finder.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2006. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_FINDER_DETAIL_HPP +#define BOOST_STRING_FINDER_DETAIL_HPP + +#include <boost/algorithm/string/config.hpp> +#include <boost/algorithm/string/constants.hpp> +#include <boost/detail/iterator.hpp> + +#include <boost/range/iterator_range.hpp> +#include <boost/range/begin.hpp> +#include <boost/range/end.hpp> +#include <boost/range/empty.hpp> +#include <boost/range/as_literal.hpp> + +namespace boost { + namespace algorithm { + namespace detail { + + +// find first functor -----------------------------------------------// + + // find a subsequence in the sequence ( functor ) + /* + Returns a pair <begin,end> marking the subsequence in the sequence. + If the find fails, functor returns <End,End> + */ + template<typename SearchIteratorT,typename PredicateT> + struct first_finderF + { + typedef SearchIteratorT search_iterator_type; + + // Construction + template< typename SearchT > + first_finderF( const SearchT& Search, PredicateT Comp ) : + m_Search(::boost::begin(Search), ::boost::end(Search)), m_Comp(Comp) {} + first_finderF( + search_iterator_type SearchBegin, + search_iterator_type SearchEnd, + PredicateT Comp ) : + m_Search(SearchBegin, SearchEnd), m_Comp(Comp) {} + + // Operation + template< typename ForwardIteratorT > + iterator_range<ForwardIteratorT> + operator()( + ForwardIteratorT Begin, + ForwardIteratorT End ) const + { + typedef iterator_range<ForwardIteratorT> result_type; + typedef ForwardIteratorT input_iterator_type; + + // Outer loop + for(input_iterator_type OuterIt=Begin; + OuterIt!=End; + ++OuterIt) + { + // Sanity check + if( boost::empty(m_Search) ) + return result_type( End, End ); + + input_iterator_type InnerIt=OuterIt; + search_iterator_type SubstrIt=m_Search.begin(); + for(; + InnerIt!=End && SubstrIt!=m_Search.end(); + ++InnerIt,++SubstrIt) + { + if( !( m_Comp(*InnerIt,*SubstrIt) ) ) + break; + } + + // Substring matching succeeded + if ( SubstrIt==m_Search.end() ) + return result_type( OuterIt, InnerIt ); + } + + return result_type( End, End ); + } + + private: + iterator_range<search_iterator_type> m_Search; + PredicateT m_Comp; + }; + +// find last functor -----------------------------------------------// + + // find the last match a subseqeunce in the sequence ( functor ) + /* + Returns a pair <begin,end> marking the subsequence in the sequence. + If the find fails, returns <End,End> + */ + template<typename SearchIteratorT, typename PredicateT> + struct last_finderF + { + typedef SearchIteratorT search_iterator_type; + typedef first_finderF< + search_iterator_type, + PredicateT> first_finder_type; + + // Construction + template< typename SearchT > + last_finderF( const SearchT& Search, PredicateT Comp ) : + m_Search(::boost::begin(Search), ::boost::end(Search)), m_Comp(Comp) {} + last_finderF( + search_iterator_type SearchBegin, + search_iterator_type SearchEnd, + PredicateT Comp ) : + m_Search(SearchBegin, SearchEnd), m_Comp(Comp) {} + + // Operation + template< typename ForwardIteratorT > + iterator_range<ForwardIteratorT> + operator()( + ForwardIteratorT Begin, + ForwardIteratorT End ) const + { + typedef iterator_range<ForwardIteratorT> result_type; + + if( boost::empty(m_Search) ) + return result_type( End, End ); + + typedef BOOST_STRING_TYPENAME boost::detail:: + iterator_traits<ForwardIteratorT>::iterator_category category; + + return findit( Begin, End, category() ); + } + + private: + // forward iterator + template< typename ForwardIteratorT > + iterator_range<ForwardIteratorT> + findit( + ForwardIteratorT Begin, + ForwardIteratorT End, + std::forward_iterator_tag ) const + { + typedef ForwardIteratorT input_iterator_type; + typedef iterator_range<ForwardIteratorT> result_type; + + first_finder_type first_finder( + m_Search.begin(), m_Search.end(), m_Comp ); + + result_type M=first_finder( Begin, End ); + result_type Last=M; + + while( M ) + { + Last=M; + M=first_finder( ::boost::end(M), End ); + } + + return Last; + } + + // bidirectional iterator + template< typename ForwardIteratorT > + iterator_range<ForwardIteratorT> + findit( + ForwardIteratorT Begin, + ForwardIteratorT End, + std::bidirectional_iterator_tag ) const + { + typedef iterator_range<ForwardIteratorT> result_type; + typedef ForwardIteratorT input_iterator_type; + + // Outer loop + for(input_iterator_type OuterIt=End; + OuterIt!=Begin; ) + { + input_iterator_type OuterIt2=--OuterIt; + + input_iterator_type InnerIt=OuterIt2; + search_iterator_type SubstrIt=m_Search.begin(); + for(; + InnerIt!=End && SubstrIt!=m_Search.end(); + ++InnerIt,++SubstrIt) + { + if( !( m_Comp(*InnerIt,*SubstrIt) ) ) + break; + } + + // Substring matching succeeded + if( SubstrIt==m_Search.end() ) + return result_type( OuterIt2, InnerIt ); + } + + return result_type( End, End ); + } + + private: + iterator_range<search_iterator_type> m_Search; + PredicateT m_Comp; + }; + +// find n-th functor -----------------------------------------------// + + // find the n-th match of a subsequence in the sequence ( functor ) + /* + Returns a pair <begin,end> marking the subsequence in the sequence. + If the find fails, returns <End,End> + */ + template<typename SearchIteratorT, typename PredicateT> + struct nth_finderF + { + typedef SearchIteratorT search_iterator_type; + typedef first_finderF< + search_iterator_type, + PredicateT> first_finder_type; + typedef last_finderF< + search_iterator_type, + PredicateT> last_finder_type; + + // Construction + template< typename SearchT > + nth_finderF( + const SearchT& Search, + int Nth, + PredicateT Comp) : + m_Search(::boost::begin(Search), ::boost::end(Search)), + m_Nth(Nth), + m_Comp(Comp) {} + nth_finderF( + search_iterator_type SearchBegin, + search_iterator_type SearchEnd, + int Nth, + PredicateT Comp) : + m_Search(SearchBegin, SearchEnd), + m_Nth(Nth), + m_Comp(Comp) {} + + // Operation + template< typename ForwardIteratorT > + iterator_range<ForwardIteratorT> + operator()( + ForwardIteratorT Begin, + ForwardIteratorT End ) const + { + if(m_Nth>=0) + { + return find_forward(Begin, End, m_Nth); + } + else + { + return find_backward(Begin, End, -m_Nth); + } + + } + + private: + // Implementation helpers + template< typename ForwardIteratorT > + iterator_range<ForwardIteratorT> + find_forward( + ForwardIteratorT Begin, + ForwardIteratorT End, + unsigned int N) const + { + typedef ForwardIteratorT input_iterator_type; + typedef iterator_range<ForwardIteratorT> result_type; + + // Sanity check + if( boost::empty(m_Search) ) + return result_type( End, End ); + + // Instantiate find functor + first_finder_type first_finder( + m_Search.begin(), m_Search.end(), m_Comp ); + + result_type M( Begin, Begin ); + + for( unsigned int n=0; n<=N; ++n ) + { + // find next match + M=first_finder( ::boost::end(M), End ); + + if ( !M ) + { + // Subsequence not found, return + return M; + } + } + + return M; + } + + template< typename ForwardIteratorT > + iterator_range<ForwardIteratorT> + find_backward( + ForwardIteratorT Begin, + ForwardIteratorT End, + unsigned int N) const + { + typedef ForwardIteratorT input_iterator_type; + typedef iterator_range<ForwardIteratorT> result_type; + + // Sanity check + if( boost::empty(m_Search) ) + return result_type( End, End ); + + // Instantiate find functor + last_finder_type last_finder( + m_Search.begin(), m_Search.end(), m_Comp ); + + result_type M( End, End ); + + for( unsigned int n=1; n<=N; ++n ) + { + // find next match + M=last_finder( Begin, ::boost::begin(M) ); + + if ( !M ) + { + // Subsequence not found, return + return M; + } + } + + return M; + } + + + private: + iterator_range<search_iterator_type> m_Search; + int m_Nth; + PredicateT m_Comp; + }; + +// find head/tail implementation helpers ---------------------------// + + template<typename ForwardIteratorT> + iterator_range<ForwardIteratorT> + find_head_impl( + ForwardIteratorT Begin, + ForwardIteratorT End, + unsigned int N, + std::forward_iterator_tag ) + { + typedef ForwardIteratorT input_iterator_type; + typedef iterator_range<ForwardIteratorT> result_type; + + input_iterator_type It=Begin; + for( + unsigned int Index=0; + Index<N && It!=End; ++Index,++It ) {}; + + return result_type( Begin, It ); + } + + template< typename ForwardIteratorT > + iterator_range<ForwardIteratorT> + find_head_impl( + ForwardIteratorT Begin, + ForwardIteratorT End, + unsigned int N, + std::random_access_iterator_tag ) + { + typedef ForwardIteratorT input_iterator_type; + typedef iterator_range<ForwardIteratorT> result_type; + + if ( (End<=Begin) || ( static_cast<unsigned int>(End-Begin) < N ) ) + return result_type( Begin, End ); + + return result_type(Begin,Begin+N); + } + + // Find head implementation + template<typename ForwardIteratorT> + iterator_range<ForwardIteratorT> + find_head_impl( + ForwardIteratorT Begin, + ForwardIteratorT End, + unsigned int N ) + { + typedef BOOST_STRING_TYPENAME boost::detail:: + iterator_traits<ForwardIteratorT>::iterator_category category; + + return ::boost::algorithm::detail::find_head_impl( Begin, End, N, category() ); + } + + template< typename ForwardIteratorT > + iterator_range<ForwardIteratorT> + find_tail_impl( + ForwardIteratorT Begin, + ForwardIteratorT End, + unsigned int N, + std::forward_iterator_tag ) + { + typedef ForwardIteratorT input_iterator_type; + typedef iterator_range<ForwardIteratorT> result_type; + + unsigned int Index=0; + input_iterator_type It=Begin; + input_iterator_type It2=Begin; + + // Advance It2 by N increments + for( Index=0; Index<N && It2!=End; ++Index,++It2 ) {}; + + // Advance It, It2 to the end + for(; It2!=End; ++It,++It2 ) {}; + + return result_type( It, It2 ); + } + + template< typename ForwardIteratorT > + iterator_range<ForwardIteratorT> + find_tail_impl( + ForwardIteratorT Begin, + ForwardIteratorT End, + unsigned int N, + std::bidirectional_iterator_tag ) + { + typedef ForwardIteratorT input_iterator_type; + typedef iterator_range<ForwardIteratorT> result_type; + + input_iterator_type It=End; + for( + unsigned int Index=0; + Index<N && It!=Begin; ++Index,--It ) {}; + + return result_type( It, End ); + } + + template< typename ForwardIteratorT > + iterator_range<ForwardIteratorT> + find_tail_impl( + ForwardIteratorT Begin, + ForwardIteratorT End, + unsigned int N, + std::random_access_iterator_tag ) + { + typedef ForwardIteratorT input_iterator_type; + typedef iterator_range<ForwardIteratorT> result_type; + + if ( (End<=Begin) || ( static_cast<unsigned int>(End-Begin) < N ) ) + return result_type( Begin, End ); + + return result_type( End-N, End ); + } + + // Operation + template< typename ForwardIteratorT > + iterator_range<ForwardIteratorT> + find_tail_impl( + ForwardIteratorT Begin, + ForwardIteratorT End, + unsigned int N ) + { + typedef BOOST_STRING_TYPENAME boost::detail:: + iterator_traits<ForwardIteratorT>::iterator_category category; + + return ::boost::algorithm::detail::find_tail_impl( Begin, End, N, category() ); + } + + + +// find head functor -----------------------------------------------// + + + // find a head in the sequence ( functor ) + /* + This functor find a head of the specified range. For + a specified N, the head is a subsequence of N starting + elements of the range. + */ + struct head_finderF + { + // Construction + head_finderF( int N ) : m_N(N) {} + + // Operation + template< typename ForwardIteratorT > + iterator_range<ForwardIteratorT> + operator()( + ForwardIteratorT Begin, + ForwardIteratorT End ) const + { + if(m_N>=0) + { + return ::boost::algorithm::detail::find_head_impl( Begin, End, m_N ); + } + else + { + iterator_range<ForwardIteratorT> Res= + ::boost::algorithm::detail::find_tail_impl( Begin, End, -m_N ); + + return ::boost::make_iterator_range(Begin, Res.begin()); + } + } + + private: + int m_N; + }; + +// find tail functor -----------------------------------------------// + + + // find a tail in the sequence ( functor ) + /* + This functor find a tail of the specified range. For + a specified N, the head is a subsequence of N starting + elements of the range. + */ + struct tail_finderF + { + // Construction + tail_finderF( int N ) : m_N(N) {} + + // Operation + template< typename ForwardIteratorT > + iterator_range<ForwardIteratorT> + operator()( + ForwardIteratorT Begin, + ForwardIteratorT End ) const + { + if(m_N>=0) + { + return ::boost::algorithm::detail::find_tail_impl( Begin, End, m_N ); + } + else + { + iterator_range<ForwardIteratorT> Res= + ::boost::algorithm::detail::find_head_impl( Begin, End, -m_N ); + + return ::boost::make_iterator_range(Res.end(), End); + } + } + + private: + int m_N; + }; + +// find token functor -----------------------------------------------// + + // find a token in a sequence ( functor ) + /* + This find functor finds a token specified be a predicate + in a sequence. It is equivalent of std::find algorithm, + with an exception that it return range instead of a single + iterator. + + If bCompress is set to true, adjacent matching tokens are + concatenated into one match. + */ + template< typename PredicateT > + struct token_finderF + { + // Construction + token_finderF( + PredicateT Pred, + token_compress_mode_type eCompress=token_compress_off ) : + m_Pred(Pred), m_eCompress(eCompress) {} + + // Operation + template< typename ForwardIteratorT > + iterator_range<ForwardIteratorT> + operator()( + ForwardIteratorT Begin, + ForwardIteratorT End ) const + { + typedef iterator_range<ForwardIteratorT> result_type; + + ForwardIteratorT It=std::find_if( Begin, End, m_Pred ); + + if( It==End ) + { + return result_type( End, End ); + } + else + { + ForwardIteratorT It2=It; + + if( m_eCompress==token_compress_on ) + { + // Find first non-matching character + while( It2!=End && m_Pred(*It2) ) ++It2; + } + else + { + // Advance by one position + ++It2; + } + + return result_type( It, It2 ); + } + } + + private: + PredicateT m_Pred; + token_compress_mode_type m_eCompress; + }; + +// find range functor -----------------------------------------------// + + // find a range in the sequence ( functor ) + /* + This functor actually does not perform any find operation. + It always returns given iterator range as a result. + */ + template<typename ForwardIterator1T> + struct range_finderF + { + typedef ForwardIterator1T input_iterator_type; + typedef iterator_range<input_iterator_type> result_type; + + // Construction + range_finderF( + input_iterator_type Begin, + input_iterator_type End ) : m_Range(Begin, End) {} + + range_finderF(const iterator_range<input_iterator_type>& Range) : + m_Range(Range) {} + + // Operation + template< typename ForwardIterator2T > + iterator_range<ForwardIterator2T> + operator()( + ForwardIterator2T, + ForwardIterator2T ) const + { +#if BOOST_WORKAROUND( __MWERKS__, <= 0x3003 ) + return iterator_range<const ForwardIterator2T>(this->m_Range); +#elif BOOST_WORKAROUND(BOOST_MSVC, <= 1300) + return iterator_range<ForwardIterator2T>(m_Range.begin(), m_Range.end()); +#else + return m_Range; +#endif + } + + private: + iterator_range<input_iterator_type> m_Range; + }; + + + } // namespace detail + } // namespace algorithm +} // namespace boost + +#endif // BOOST_STRING_FINDER_DETAIL_HPP diff --git a/Utilities/BGL/boost/algorithm/string/detail/finder_regex.hpp b/Utilities/BGL/boost/algorithm/string/detail/finder_regex.hpp new file mode 100755 index 0000000000000000000000000000000000000000..a5239b83e9bc4431ff8e42b85d8478872f2dcc10 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/detail/finder_regex.hpp @@ -0,0 +1,122 @@ +// Boost string_algo library find_regex.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_FINDER_REGEX_DETAIL_HPP +#define BOOST_STRING_FINDER_REGEX_DETAIL_HPP + +#include <boost/algorithm/string/config.hpp> +#include <boost/regex.hpp> + +#include <boost/range/iterator_range.hpp> +#include <boost/range/begin.hpp> +#include <boost/range/end.hpp> + +namespace boost { + namespace algorithm { + namespace detail { + +// regex find functor -----------------------------------------------// + + // regex search result + template<typename IteratorT> + struct regex_search_result : + public iterator_range<IteratorT> + { + typedef regex_search_result<IteratorT> type; + typedef iterator_range<IteratorT> base_type; + typedef BOOST_STRING_TYPENAME base_type::value_type value_type; + typedef BOOST_STRING_TYPENAME base_type::difference_type difference_type; + typedef BOOST_STRING_TYPENAME base_type::const_iterator const_iterator; + typedef BOOST_STRING_TYPENAME base_type::iterator iterator; + typedef boost::match_results<iterator> match_results_type; + + // Construction + + // Construction from the match result + regex_search_result( const match_results_type& MatchResults ) : + base_type( MatchResults[0].first, MatchResults[0].second ), + m_MatchResults( MatchResults ) {} + + // Construction of empty match. End iterator has to be specified + regex_search_result( IteratorT End ) : + base_type( End, End ) {} + + regex_search_result( const regex_search_result& Other ) : + base_type( Other.begin(), Other.end() ), + m_MatchResults( Other.m_MatchResults ) {} + + // Assignment + regex_search_result& operator=( const regex_search_result& Other ) + { + base_type::operator=( Other ); + m_MatchResults=Other.m_MatchResults; + return *this; + } + + // Match result retrival + const match_results_type& match_results() const + { + return m_MatchResults; + } + + private: + // Saved matchresult + match_results_type m_MatchResults; + }; + + // find_regex + /* + Regex based search functor + */ + template<typename RegExT> + struct find_regexF + { + typedef RegExT regex_type; + typedef const RegExT& regex_reference_type; + + // Construction + find_regexF( regex_reference_type Rx, match_flag_type MatchFlags = match_default ) : + m_Rx(Rx), m_MatchFlags(MatchFlags) {} + + // Operation + template< typename ForwardIteratorT > + regex_search_result<ForwardIteratorT> + operator()( + ForwardIteratorT Begin, + ForwardIteratorT End ) const + { + typedef ForwardIteratorT input_iterator_type; + typedef regex_search_result<ForwardIteratorT> result_type; + + // instantiate match result + match_results<input_iterator_type> result; + // search for a match + if ( ::boost::regex_search( Begin, End, result, m_Rx, m_MatchFlags ) ) + { + // construct a result + return result_type( result ); + } + else + { + // empty result + return result_type( End ); + } + } + + private: + regex_reference_type m_Rx; // Regexp + match_flag_type m_MatchFlags; // match flags + }; + + } // namespace detail + } // namespace algorithm +} // namespace boost + +#endif // BOOST_STRING_FIND_DETAIL_HPP diff --git a/Utilities/BGL/boost/algorithm/string/detail/formatter.hpp b/Utilities/BGL/boost/algorithm/string/detail/formatter.hpp new file mode 100755 index 0000000000000000000000000000000000000000..994ab24583f19fde56fae22b1436986746899583 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/detail/formatter.hpp @@ -0,0 +1,94 @@ +// Boost string_algo library formatter.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for updates, documentation, and revision history. + +#ifndef BOOST_STRING_FORMATTER_DETAIL_HPP +#define BOOST_STRING_FORMATTER_DETAIL_HPP + + +#include <boost/range/iterator_range.hpp> +#include <boost/range/begin.hpp> +#include <boost/range/end.hpp> +#include <boost/range/const_iterator.hpp> + +#include <boost/algorithm/string/detail/util.hpp> + +// generic replace functors -----------------------------------------------// + +namespace boost { + namespace algorithm { + namespace detail { + +// const format functor ----------------------------------------------------// + + // constant format functor + template<typename RangeT> + struct const_formatF + { + private: + typedef BOOST_STRING_TYPENAME + range_const_iterator<RangeT>::type format_iterator; + typedef iterator_range<format_iterator> result_type; + + public: + // Construction + const_formatF(const RangeT& Format) : + m_Format(::boost::begin(Format), ::boost::end(Format)) {} + + // Operation +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) + template<typename Range2T> + result_type& operator()(const Range2T&) + { + return m_Format; + } +#endif + + template<typename Range2T> + const result_type& operator()(const Range2T&) const + { + return m_Format; + } + + private: + result_type m_Format; + }; + +// identity format functor ----------------------------------------------------// + + // identity format functor + template<typename RangeT> + struct identity_formatF + { + // Operation + template< typename Range2T > + const RangeT& operator()(const Range2T& Replace) const + { + return RangeT(::boost::begin(Replace), ::boost::end(Replace)); + } + }; + +// empty format functor ( used by erase ) ------------------------------------// + + // empty format functor + template< typename CharT > + struct empty_formatF + { + template< typename ReplaceT > + empty_container<CharT> operator()(const ReplaceT&) const + { + return empty_container<CharT>(); + } + }; + + } // namespace detail + } // namespace algorithm +} // namespace boost + +#endif // BOOST_STRING_FORMATTER_DETAIL_HPP diff --git a/Utilities/BGL/boost/algorithm/string/detail/formatter_regex.hpp b/Utilities/BGL/boost/algorithm/string/detail/formatter_regex.hpp new file mode 100755 index 0000000000000000000000000000000000000000..20ebc9620963d757a5d9c95c67a94c0ddb322208 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/detail/formatter_regex.hpp @@ -0,0 +1,61 @@ +// Boost string_algo library formatter_regex.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_FORMATTER_REGEX_DETAIL_HPP +#define BOOST_STRING_FORMATTER_REGEX_DETAIL_HPP + +#include <boost/algorithm/string/config.hpp> +#include <string> +#include <boost/regex.hpp> +#include <boost/algorithm/string/detail/finder_regex.hpp> + +namespace boost { + namespace algorithm { + namespace detail { + +// regex format functor -----------------------------------------// + + // regex format functor + template<typename StringT> + struct regex_formatF + { + private: + typedef StringT result_type; + typedef BOOST_STRING_TYPENAME StringT::value_type char_type; + + public: + // Construction + regex_formatF( const StringT& Fmt, match_flag_type Flags=format_default ) : + m_Fmt(Fmt), m_Flags( Flags ) {} + + template<typename InputIteratorT> + result_type operator()( + const regex_search_result<InputIteratorT>& Replace ) const + { + if ( Replace.empty() ) + { + return result_type(); + } + else + { + return Replace.match_results().format( m_Fmt, m_Flags ); + } + } + private: + const StringT& m_Fmt; + match_flag_type m_Flags; + }; + + + } // namespace detail + } // namespace algorithm +} // namespace boost + +#endif // BOOST_STRING_FORMATTER_DETAIL_HPP diff --git a/Utilities/BGL/boost/algorithm/string/detail/predicate.hpp b/Utilities/BGL/boost/algorithm/string/detail/predicate.hpp new file mode 100755 index 0000000000000000000000000000000000000000..bd95d40c870eddb2099d0f96a1fd36b8b724a5c7 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/detail/predicate.hpp @@ -0,0 +1,77 @@ +// Boost string_algo library predicate.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_PREDICATE_DETAIL_HPP +#define BOOST_STRING_PREDICATE_DETAIL_HPP + +#include <iterator> +#include <boost/algorithm/string/find.hpp> + +namespace boost { + namespace algorithm { + namespace detail { + +// ends_with predicate implementation ----------------------------------// + + template< + typename ForwardIterator1T, + typename ForwardIterator2T, + typename PredicateT> + inline bool ends_with_iter_select( + ForwardIterator1T Begin, + ForwardIterator1T End, + ForwardIterator2T SubBegin, + ForwardIterator2T SubEnd, + PredicateT Comp, + std::bidirectional_iterator_tag) + { + ForwardIterator1T it=End; + ForwardIterator2T pit=SubEnd; + for(;it!=Begin && pit!=SubBegin;) + { + if( !(Comp(*(--it),*(--pit))) ) + return false; + } + + return pit==SubBegin; + } + + template< + typename ForwardIterator1T, + typename ForwardIterator2T, + typename PredicateT> + inline bool ends_with_iter_select( + ForwardIterator1T Begin, + ForwardIterator1T End, + ForwardIterator2T SubBegin, + ForwardIterator2T SubEnd, + PredicateT Comp, + std::forward_iterator_tag) + { + if ( SubBegin==SubEnd ) + { + // empty subsequence check + return true; + } + + iterator_range<ForwardIterator1T> Result + =last_finder( + ::boost::make_iterator_range(SubBegin, SubEnd), + Comp)(Begin, End); + + return !Result.empty() && Result.end()==End; + } + + } // namespace detail + } // namespace algorithm +} // namespace boost + + +#endif // BOOST_STRING_PREDICATE_DETAIL_HPP diff --git a/Utilities/BGL/boost/algorithm/string/detail/replace_storage.hpp b/Utilities/BGL/boost/algorithm/string/detail/replace_storage.hpp new file mode 100755 index 0000000000000000000000000000000000000000..13f4e08b47bfe16a7943a2a7728f7cc1b88f0faa --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/detail/replace_storage.hpp @@ -0,0 +1,159 @@ +// Boost string_algo library replace_storage.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_REPLACE_STORAGE_DETAIL_HPP +#define BOOST_STRING_REPLACE_STORAGE_DETAIL_HPP + +#include <boost/algorithm/string/config.hpp> +#include <algorithm> +#include <boost/mpl/bool.hpp> +#include <boost/algorithm/string/sequence_traits.hpp> +#include <boost/algorithm/string/detail/sequence.hpp> + +namespace boost { + namespace algorithm { + namespace detail { + +// storage handling routines -----------------------------------------------// + + template< typename StorageT, typename OutputIteratorT > + inline OutputIteratorT move_from_storage( + StorageT& Storage, + OutputIteratorT DestBegin, + OutputIteratorT DestEnd ) + { + OutputIteratorT OutputIt=DestBegin; + + while( !Storage.empty() && OutputIt!=DestEnd ) + { + *OutputIt=Storage.front(); + Storage.pop_front(); + ++OutputIt; + } + + return OutputIt; + } + + template< typename StorageT, typename WhatT > + inline void copy_to_storage( + StorageT& Storage, + const WhatT& What ) + { + Storage.insert( Storage.end(), ::boost::begin(What), ::boost::end(What) ); + } + + +// process segment routine -----------------------------------------------// + + template< bool HasStableIterators > + struct process_segment_helper + { + // Optimized version of process_segment for generic sequence + template< + typename StorageT, + typename InputT, + typename ForwardIteratorT > + ForwardIteratorT operator()( + StorageT& Storage, + InputT& /*Input*/, + ForwardIteratorT InsertIt, + ForwardIteratorT SegmentBegin, + ForwardIteratorT SegmentEnd ) + { + // Copy data from the storage until the beginning of the segment + ForwardIteratorT It=::boost::algorithm::detail::move_from_storage( Storage, InsertIt, SegmentBegin ); + + // 3 cases are possible : + // a) Storage is empty, It==SegmentBegin + // b) Storage is empty, It!=SegmentBegin + // c) Storage is not empty + + if( Storage.empty() ) + { + if( It==SegmentBegin ) + { + // Case a) everything is grand, just return end of segment + return SegmentEnd; + } + else + { + // Case b) move the segment backwards + return std::copy( SegmentBegin, SegmentEnd, It ); + } + } + else + { + // Case c) -> shift the segment to the left and keep the overlap in the storage + while( It!=SegmentEnd ) + { + // Store value into storage + Storage.push_back( *It ); + // Get the top from the storage and put it here + *It=Storage.front(); + Storage.pop_front(); + + // Advance + ++It; + } + + return It; + } + } + }; + + template<> + struct process_segment_helper< true > + { + // Optimized version of process_segment for list-like sequence + template< + typename StorageT, + typename InputT, + typename ForwardIteratorT > + ForwardIteratorT operator()( + StorageT& Storage, + InputT& Input, + ForwardIteratorT InsertIt, + ForwardIteratorT SegmentBegin, + ForwardIteratorT SegmentEnd ) + + { + // Call replace to do the job + ::boost::algorithm::detail::replace( Input, InsertIt, SegmentBegin, Storage ); + // Empty the storage + Storage.clear(); + // Iterators were not changed, simply return the end of segment + return SegmentEnd; + } + }; + + // Process one segment in the replace_all algorithm + template< + typename StorageT, + typename InputT, + typename ForwardIteratorT > + inline ForwardIteratorT process_segment( + StorageT& Storage, + InputT& Input, + ForwardIteratorT InsertIt, + ForwardIteratorT SegmentBegin, + ForwardIteratorT SegmentEnd ) + { + return + process_segment_helper< + has_stable_iterators<InputT>::value>()( + Storage, Input, InsertIt, SegmentBegin, SegmentEnd ); + } + + + } // namespace detail + } // namespace algorithm +} // namespace boost + +#endif // BOOST_STRING_REPLACE_STORAGE_DETAIL_HPP diff --git a/Utilities/BGL/boost/algorithm/string/detail/sequence.hpp b/Utilities/BGL/boost/algorithm/string/detail/sequence.hpp new file mode 100755 index 0000000000000000000000000000000000000000..8c8bd9755c13cde9c66138e8f857c3f48690e740 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/detail/sequence.hpp @@ -0,0 +1,200 @@ +// Boost string_algo library sequence.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_DETAIL_SEQUENCE_HPP +#define BOOST_STRING_DETAIL_SEQUENCE_HPP + +#include <boost/algorithm/string/config.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/mpl/logical.hpp> +#include <boost/range/begin.hpp> +#include <boost/range/end.hpp> + +#include <boost/algorithm/string/sequence_traits.hpp> + +namespace boost { + namespace algorithm { + namespace detail { + +// insert helpers -------------------------------------------------// + + template< typename InputT, typename ForwardIteratorT > + inline void insert( + InputT& Input, + BOOST_STRING_TYPENAME InputT::iterator At, + ForwardIteratorT Begin, + ForwardIteratorT End ) + { + Input.insert( At, Begin, End ); + } + + template< typename InputT, typename InsertT > + inline void insert( + InputT& Input, + BOOST_STRING_TYPENAME InputT::iterator At, + const InsertT& Insert ) + { + ::boost::algorithm::detail::insert( Input, At, ::boost::begin(Insert), ::boost::end(Insert) ); + } + +// erase helper ---------------------------------------------------// + + // Erase a range in the sequence + /* + Returns the iterator pointing just after the erase subrange + */ + template< typename InputT > + inline typename InputT::iterator erase( + InputT& Input, + BOOST_STRING_TYPENAME InputT::iterator From, + BOOST_STRING_TYPENAME InputT::iterator To ) + { + return Input.erase( From, To ); + } + +// replace helper implementation ----------------------------------// + + // Optimized version of replace for generic sequence containers + // Assumption: insert and erase are expensive + template< bool HasConstTimeOperations > + struct replace_const_time_helper + { + template< typename InputT, typename ForwardIteratorT > + void operator()( + InputT& Input, + BOOST_STRING_TYPENAME InputT::iterator From, + BOOST_STRING_TYPENAME InputT::iterator To, + ForwardIteratorT Begin, + ForwardIteratorT End ) + { + // Copy data to the container ( as much as possible ) + ForwardIteratorT InsertIt=Begin; + BOOST_STRING_TYPENAME InputT::iterator InputIt=From; + for(; InsertIt!=End && InputIt!=To; InsertIt++, InputIt++ ) + { + *InputIt=*InsertIt; + } + + if ( InsertIt!=End ) + { + // Replace sequence is longer, insert it + Input.insert( InputIt, InsertIt, End ); + } + else + { + if ( InputIt!=To ) + { + // Replace sequence is shorter, erase the rest + Input.erase( InputIt, To ); + } + } + } + }; + + template<> + struct replace_const_time_helper< true > + { + // Const-time erase and insert methods -> use them + template< typename InputT, typename ForwardIteratorT > + void operator()( + InputT& Input, + BOOST_STRING_TYPENAME InputT::iterator From, + BOOST_STRING_TYPENAME InputT::iterator To, + ForwardIteratorT Begin, + ForwardIteratorT End ) + { + BOOST_STRING_TYPENAME InputT::iterator At=Input.erase( From, To ); + if ( Begin!=End ) + { + if(!Input.empty()) + { + Input.insert( At, Begin, End ); + } + else + { + Input.insert( Input.begin(), Begin, End ); + } + } + } + }; + + // No native replace method + template< bool HasNative > + struct replace_native_helper + { + template< typename InputT, typename ForwardIteratorT > + void operator()( + InputT& Input, + BOOST_STRING_TYPENAME InputT::iterator From, + BOOST_STRING_TYPENAME InputT::iterator To, + ForwardIteratorT Begin, + ForwardIteratorT End ) + { + replace_const_time_helper< + boost::mpl::and_< + has_const_time_insert<InputT>, + has_const_time_erase<InputT> >::value >()( + Input, From, To, Begin, End ); + } + }; + + // Container has native replace method + template<> + struct replace_native_helper< true > + { + template< typename InputT, typename ForwardIteratorT > + void operator()( + InputT& Input, + BOOST_STRING_TYPENAME InputT::iterator From, + BOOST_STRING_TYPENAME InputT::iterator To, + ForwardIteratorT Begin, + ForwardIteratorT End ) + { + Input.replace( From, To, Begin, End ); + } + }; + +// replace helper -------------------------------------------------// + + template< typename InputT, typename ForwardIteratorT > + inline void replace( + InputT& Input, + BOOST_STRING_TYPENAME InputT::iterator From, + BOOST_STRING_TYPENAME InputT::iterator To, + ForwardIteratorT Begin, + ForwardIteratorT End ) + { + replace_native_helper< has_native_replace<InputT>::value >()( + Input, From, To, Begin, End ); + } + + template< typename InputT, typename InsertT > + inline void replace( + InputT& Input, + BOOST_STRING_TYPENAME InputT::iterator From, + BOOST_STRING_TYPENAME InputT::iterator To, + const InsertT& Insert ) + { + if(From!=To) + { + ::boost::algorithm::detail::replace( Input, From, To, ::boost::begin(Insert), ::boost::end(Insert) ); + } + else + { + ::boost::algorithm::detail::insert( Input, From, ::boost::begin(Insert), ::boost::end(Insert) ); + } + } + + } // namespace detail + } // namespace algorithm +} // namespace boost + + +#endif // BOOST_STRING_DETAIL_SEQUENCE_HPP diff --git a/Utilities/BGL/boost/algorithm/string/detail/trim.hpp b/Utilities/BGL/boost/algorithm/string/detail/trim.hpp new file mode 100755 index 0000000000000000000000000000000000000000..b53072c0060d8333b832105ec745516e2ac41a98 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/detail/trim.hpp @@ -0,0 +1,95 @@ +// Boost string_algo library trim.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_TRIM_DETAIL_HPP +#define BOOST_STRING_TRIM_DETAIL_HPP + +#include <boost/algorithm/string/config.hpp> +#include <boost/detail/iterator.hpp> + +namespace boost { + namespace algorithm { + namespace detail { + +// trim iterator helper -----------------------------------------------// + + template< typename ForwardIteratorT, typename PredicateT > + inline ForwardIteratorT trim_end_iter_select( + ForwardIteratorT InBegin, + ForwardIteratorT InEnd, + PredicateT IsSpace, + std::forward_iterator_tag ) + { + ForwardIteratorT TrimIt=InBegin; + + for( ForwardIteratorT It=InBegin; It!=InEnd; ++It ) + { + if ( !IsSpace(*It) ) + { + TrimIt=It; + ++TrimIt; + } + } + + return TrimIt; + } + + template< typename ForwardIteratorT, typename PredicateT > + inline ForwardIteratorT trim_end_iter_select( + ForwardIteratorT InBegin, + ForwardIteratorT InEnd, + PredicateT IsSpace, + std::bidirectional_iterator_tag ) + { + for( ForwardIteratorT It=InEnd; It!=InBegin; ) + { + if ( !IsSpace(*(--It)) ) + return ++It; + } + + return InBegin; + } + // Search for first non matching character from the beginning of the sequence + template< typename ForwardIteratorT, typename PredicateT > + inline ForwardIteratorT trim_begin( + ForwardIteratorT InBegin, + ForwardIteratorT InEnd, + PredicateT IsSpace ) + { + ForwardIteratorT It=InBegin; + for(; It!=InEnd; ++It ) + { + if (!IsSpace(*It)) + return It; + } + + return It; + } + + // Search for first non matching character from the end of the sequence + template< typename ForwardIteratorT, typename PredicateT > + inline ForwardIteratorT trim_end( + ForwardIteratorT InBegin, + ForwardIteratorT InEnd, + PredicateT IsSpace ) + { + typedef BOOST_STRING_TYPENAME boost::detail:: + iterator_traits<ForwardIteratorT>::iterator_category category; + + return ::boost::algorithm::detail::trim_end_iter_select( InBegin, InEnd, IsSpace, category() ); + } + + + } // namespace detail + } // namespace algorithm +} // namespace boost + + +#endif // BOOST_STRING_TRIM_DETAIL_HPP diff --git a/Utilities/BGL/boost/algorithm/string/detail/util.hpp b/Utilities/BGL/boost/algorithm/string/detail/util.hpp new file mode 100755 index 0000000000000000000000000000000000000000..8e03a5dbd25c47dd913ddea04e2c371a8581d8f9 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/detail/util.hpp @@ -0,0 +1,106 @@ +// Boost string_algo library util.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_UTIL_DETAIL_HPP +#define BOOST_STRING_UTIL_DETAIL_HPP + +#include <boost/algorithm/string/config.hpp> +#include <functional> +#include <boost/range/iterator_range.hpp> + +namespace boost { + namespace algorithm { + namespace detail { + +// empty container -----------------------------------------------// + + // empty_container + /* + This class represents always empty container, + containing elements of type CharT. + + It is supposed to be used in a const version only + */ + template< typename CharT > + struct empty_container + { + typedef empty_container<CharT> type; + typedef CharT value_type; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + typedef const value_type& reference; + typedef const value_type& const_reference; + typedef const value_type* iterator; + typedef const value_type* const_iterator; + + + // Operations + const_iterator begin() const + { + return reinterpret_cast<const_iterator>(0); + } + + const_iterator end() const + { + return reinterpret_cast<const_iterator>(0); + } + + bool empty() const + { + return false; + } + + size_type size() const + { + return 0; + } + }; + +// bounded copy algorithm -----------------------------------------------// + + // Bounded version of the std::copy algorithm + template<typename InputIteratorT, typename OutputIteratorT> + inline OutputIteratorT bounded_copy( + InputIteratorT First, + InputIteratorT Last, + OutputIteratorT DestFirst, + OutputIteratorT DestLast ) + { + InputIteratorT InputIt=First; + OutputIteratorT OutputIt=DestFirst; + for(; InputIt!=Last && OutputIt!=DestLast; InputIt++, OutputIt++ ) + { + *OutputIt=*InputIt; + } + + return OutputIt; + } + +// iterator range utilities -----------------------------------------// + + // copy range functor + template< + typename SeqT, + typename IteratorT=BOOST_STRING_TYPENAME SeqT::const_iterator > + struct copy_iterator_rangeF : + public std::unary_function< iterator_range<IteratorT>, SeqT > + { + SeqT operator()( const iterator_range<IteratorT>& Range ) const + { + return copy_range<SeqT>(Range); + } + }; + + } // namespace detail + } // namespace algorithm +} // namespace boost + + +#endif // BOOST_STRING_UTIL_DETAIL_HPP diff --git a/Utilities/BGL/boost/algorithm/string/erase.hpp b/Utilities/BGL/boost/algorithm/string/erase.hpp new file mode 100755 index 0000000000000000000000000000000000000000..6e8856b3132ff597e1ad5c18dd2a1555e88bbbb9 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/erase.hpp @@ -0,0 +1,844 @@ +// Boost string_algo library erase.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2006. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_ERASE_HPP +#define BOOST_STRING_ERASE_HPP + +#include <boost/algorithm/string/config.hpp> + +#include <boost/range/iterator_range.hpp> +#include <boost/range/begin.hpp> +#include <boost/range/end.hpp> +#include <boost/range/iterator.hpp> +#include <boost/range/const_iterator.hpp> + +#include <boost/algorithm/string/find_format.hpp> +#include <boost/algorithm/string/finder.hpp> +#include <boost/algorithm/string/formatter.hpp> + +/*! \file + Defines various erase algorithms. Each algorithm removes + part(s) of the input according to a searching criteria. +*/ + +namespace boost { + namespace algorithm { + +// erase_range -------------------------------------------------------// + + //! Erase range algorithm + /*! + Remove the given range from the input. The result is a modified copy of + the input. It is returned as a sequence or copied to the output iterator. + + \param Output An output iterator to which the result will be copied + \param Input An input sequence + \param SearchRange A range in the input to be removed + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template<typename OutputIteratorT, typename RangeT> + inline OutputIteratorT erase_range_copy( + OutputIteratorT Output, + const RangeT& Input, + const iterator_range< + BOOST_STRING_TYPENAME + range_const_iterator<RangeT>::type>& SearchRange ) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::range_finder(SearchRange), + ::boost::algorithm::empty_formatter(Input) ); + } + + //! Erase range algorithm + /*! + \overload + */ + template<typename SequenceT> + inline SequenceT erase_range_copy( + const SequenceT& Input, + const iterator_range< + BOOST_STRING_TYPENAME + range_const_iterator<SequenceT>::type>& SearchRange ) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::range_finder(SearchRange), + ::boost::algorithm::empty_formatter(Input) ); + } + + //! Erase range algorithm + /*! + Remove the given range from the input. + The input sequence is modified in-place. + + \param Input An input sequence + \param SearchRange A range in the input to be removed + */ + template<typename SequenceT> + inline void erase_range( + SequenceT& Input, + const iterator_range< + BOOST_STRING_TYPENAME + range_iterator<SequenceT>::type>& SearchRange ) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::range_finder(SearchRange), + ::boost::algorithm::empty_formatter(Input) ); + } + +// erase_first --------------------------------------------------------// + + //! Erase first algorithm + /*! + Remove the first occurrence of the substring from the input. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param Search A substring to be searched for + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename Range1T, + typename Range2T> + inline OutputIteratorT erase_first_copy( + OutputIteratorT Output, + const Range1T& Input, + const Range2T& Search ) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::first_finder(Search), + ::boost::algorithm::empty_formatter(Input) ); + } + + //! Erase first algorithm + /*! + \overload + */ + template<typename SequenceT, typename RangeT> + inline SequenceT erase_first_copy( + const SequenceT& Input, + const RangeT& Search ) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::first_finder(Search), + ::boost::algorithm::empty_formatter(Input) ); + } + + //! Erase first algorithm + /*! + Remove the first occurrence of the substring from the input. + The input sequence is modified in-place. + + \param Input An input string + \param Search A substring to be searched for. + */ + template<typename SequenceT, typename RangeT> + inline void erase_first( + SequenceT& Input, + const RangeT& Search ) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::first_finder(Search), + ::boost::algorithm::empty_formatter(Input) ); + } + +// erase_first ( case insensitive ) ------------------------------------// + + //! Erase first algorithm ( case insensitive ) + /*! + Remove the first occurrence of the substring from the input. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + Searching is case insensitive. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param Search A substring to be searched for + \param Loc A locale used for case insensitive comparison + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename Range1T, + typename Range2T> + inline OutputIteratorT ierase_first_copy( + OutputIteratorT Output, + const Range1T& Input, + const Range2T& Search, + const std::locale& Loc=std::locale() ) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::first_finder(Search, is_iequal(Loc)), + ::boost::algorithm::empty_formatter(Input) ); + } + + //! Erase first algorithm ( case insensitive ) + /*! + \overload + */ + template<typename SequenceT, typename RangeT> + inline SequenceT ierase_first_copy( + const SequenceT& Input, + const RangeT& Search, + const std::locale& Loc=std::locale() ) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::first_finder(Search, is_iequal(Loc)), + ::boost::algorithm::empty_formatter(Input) ); + } + + //! Erase first algorithm ( case insensitive ) + /*! + Remove the first occurrence of the substring from the input. + The input sequence is modified in-place. Searching is case insensitive. + + \param Input An input string + \param Search A substring to be searched for + \param Loc A locale used for case insensitive comparison + */ + template<typename SequenceT, typename RangeT> + inline void ierase_first( + SequenceT& Input, + const RangeT& Search, + const std::locale& Loc=std::locale() ) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::first_finder(Search, is_iequal(Loc)), + ::boost::algorithm::empty_formatter(Input) ); + } + +// erase_last --------------------------------------------------------// + + //! Erase last algorithm + /*! + Remove the last occurrence of the substring from the input. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param Search A substring to be searched for. + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename Range1T, + typename Range2T> + inline OutputIteratorT erase_last_copy( + OutputIteratorT Output, + const Range1T& Input, + const Range2T& Search ) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::last_finder(Search), + ::boost::algorithm::empty_formatter(Input) ); + } + + //! Erase last algorithm + /*! + \overload + */ + template<typename SequenceT, typename RangeT> + inline SequenceT erase_last_copy( + const SequenceT& Input, + const RangeT& Search ) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::last_finder(Search), + ::boost::algorithm::empty_formatter(Input) ); + } + + //! Erase last algorithm + /*! + Remove the last occurrence of the substring from the input. + The input sequence is modified in-place. + + \param Input An input string + \param Search A substring to be searched for + */ + template<typename SequenceT, typename RangeT> + inline void erase_last( + SequenceT& Input, + const RangeT& Search ) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::last_finder(Search), + ::boost::algorithm::empty_formatter(Input) ); + } + +// erase_last ( case insensitive ) ------------------------------------// + + //! Erase last algorithm ( case insensitive ) + /*! + Remove the last occurrence of the substring from the input. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + Searching is case insensitive. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param Search A substring to be searched for + \param Loc A locale used for case insensitive comparison + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename Range1T, + typename Range2T> + inline OutputIteratorT ierase_last_copy( + OutputIteratorT Output, + const Range1T& Input, + const Range2T& Search, + const std::locale& Loc=std::locale() ) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::last_finder(Search, is_iequal(Loc)), + ::boost::algorithm::empty_formatter(Input) ); + } + + //! Erase last algorithm ( case insensitive ) + /*! + \overload + */ + template<typename SequenceT, typename RangeT> + inline SequenceT ierase_last_copy( + const SequenceT& Input, + const RangeT& Search, + const std::locale& Loc=std::locale() ) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::last_finder(Search, is_iequal(Loc)), + ::boost::algorithm::empty_formatter(Input) ); + } + + //! Erase last algorithm ( case insensitive ) + /*! + Remove the last occurrence of the substring from the input. + The input sequence is modified in-place. Searching is case insensitive. + + \param Input An input string + \param Search A substring to be searched for + \param Loc A locale used for case insensitive comparison + */ + template<typename SequenceT, typename RangeT> + inline void ierase_last( + SequenceT& Input, + const RangeT& Search, + const std::locale& Loc=std::locale() ) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::last_finder(Search, is_iequal(Loc)), + ::boost::algorithm::empty_formatter(Input) ); + } + +// erase_nth --------------------------------------------------------------------// + + //! Erase nth algorithm + /*! + Remove the Nth occurrence of the substring in the input. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param Search A substring to be searched for + \param Nth An index of the match to be replaced. The index is 0-based. + For negative N, matches are counted from the end of string. + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename Range1T, + typename Range2T> + inline OutputIteratorT erase_nth_copy( + OutputIteratorT Output, + const Range1T& Input, + const Range2T& Search, + int Nth ) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::nth_finder(Search, Nth), + ::boost::algorithm::empty_formatter(Input) ); + } + + //! Erase nth algorithm + /*! + \overload + */ + template<typename SequenceT, typename RangeT> + inline SequenceT erase_nth_copy( + const SequenceT& Input, + const RangeT& Search, + int Nth ) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::nth_finder(Search, Nth), + ::boost::algorithm::empty_formatter(Input) ); + } + + //! Erase nth algorithm + /*! + Remove the Nth occurrence of the substring in the input. + The input sequence is modified in-place. + + \param Input An input string + \param Search A substring to be searched for. + \param Nth An index of the match to be replaced. The index is 0-based. + For negative N, matches are counted from the end of string. + */ + template<typename SequenceT, typename RangeT> + inline void erase_nth( + SequenceT& Input, + const RangeT& Search, + int Nth ) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::nth_finder(Search, Nth), + ::boost::algorithm::empty_formatter(Input) ); + } + +// erase_nth ( case insensitive ) ---------------------------------------------// + + //! Erase nth algorithm ( case insensitive ) + /*! + Remove the Nth occurrence of the substring in the input. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + Searching is case insensitive. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param Search A substring to be searched for. + \param Nth An index of the match to be replaced. The index is 0-based. + For negative N, matches are counted from the end of string. + \param Loc A locale used for case insensitive comparison + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename Range1T, + typename Range2T> + inline OutputIteratorT ierase_nth_copy( + OutputIteratorT Output, + const Range1T& Input, + const Range2T& Search, + int Nth, + const std::locale& Loc=std::locale() ) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::nth_finder(Search, Nth, is_iequal(Loc)), + ::boost::algorithm::empty_formatter(Input) ); + } + + //! Erase nth algorithm + /*! + \overload + */ + template<typename SequenceT, typename RangeT> + inline SequenceT ierase_nth_copy( + const SequenceT& Input, + const RangeT& Search, + int Nth, + const std::locale& Loc=std::locale() ) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::nth_finder(Search, Nth, is_iequal(Loc)), + empty_formatter(Input) ); + } + + //! Erase nth algorithm + /*! + Remove the Nth occurrence of the substring in the input. + The input sequence is modified in-place. Searching is case insensitive. + + \param Input An input string + \param Search A substring to be searched for. + \param Nth An index of the match to be replaced. The index is 0-based. + For negative N, matches are counted from the end of string. + \param Loc A locale used for case insensitive comparison + */ + template<typename SequenceT, typename RangeT> + inline void ierase_nth( + SequenceT& Input, + const RangeT& Search, + int Nth, + const std::locale& Loc=std::locale() ) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::nth_finder(Search, Nth, is_iequal(Loc)), + ::boost::algorithm::empty_formatter(Input) ); + } + + +// erase_all --------------------------------------------------------// + + //! Erase all algorithm + /*! + Remove all the occurrences of the string from the input. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + + + \param Output An output iterator to which the result will be copied + \param Input An input sequence + \param Search A substring to be searched for. + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename Range1T, + typename Range2T> + inline OutputIteratorT erase_all_copy( + OutputIteratorT Output, + const Range1T& Input, + const Range2T& Search ) + { + return ::boost::algorithm::find_format_all_copy( + Output, + Input, + ::boost::algorithm::first_finder(Search), + ::boost::algorithm::empty_formatter(Input) ); + } + + //! Erase all algorithm + /*! + \overload + */ + template<typename SequenceT, typename RangeT> + inline SequenceT erase_all_copy( + const SequenceT& Input, + const RangeT& Search ) + { + return ::boost::algorithm::find_format_all_copy( + Input, + ::boost::algorithm::first_finder(Search), + ::boost::algorithm::empty_formatter(Input) ); + } + + //! Erase all algorithm + /*! + Remove all the occurrences of the string from the input. + The input sequence is modified in-place. + + \param Input An input string + \param Search A substring to be searched for. + */ + template<typename SequenceT, typename RangeT> + inline void erase_all( + SequenceT& Input, + const RangeT& Search ) + { + ::boost::algorithm::find_format_all( + Input, + ::boost::algorithm::first_finder(Search), + ::boost::algorithm::empty_formatter(Input) ); + } + +// erase_all ( case insensitive ) ------------------------------------// + + //! Erase all algorithm ( case insensitive ) + /*! + Remove all the occurrences of the string from the input. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + Searching is case insensitive. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param Search A substring to be searched for + \param Loc A locale used for case insensitive comparison + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename Range1T, + typename Range2T> + inline OutputIteratorT ierase_all_copy( + OutputIteratorT Output, + const Range1T& Input, + const Range2T& Search, + const std::locale& Loc=std::locale() ) + { + return ::boost::algorithm::find_format_all_copy( + Output, + Input, + ::boost::algorithm::first_finder(Search, is_iequal(Loc)), + ::boost::algorithm::empty_formatter(Input) ); + } + + //! Erase all algorithm ( case insensitive ) + /*! + \overload + */ + template<typename SequenceT, typename RangeT> + inline SequenceT ierase_all_copy( + const SequenceT& Input, + const RangeT& Search, + const std::locale& Loc=std::locale() ) + { + return ::boost::algorithm::find_format_all_copy( + Input, + ::boost::algorithm::first_finder(Search, is_iequal(Loc)), + ::boost::algorithm::empty_formatter(Input) ); + } + + //! Erase all algorithm ( case insensitive ) + /*! + Remove all the occurrences of the string from the input. + The input sequence is modified in-place. Searching is case insensitive. + + \param Input An input string + \param Search A substring to be searched for. + \param Loc A locale used for case insensitive comparison + */ + template<typename SequenceT, typename RangeT> + inline void ierase_all( + SequenceT& Input, + const RangeT& Search, + const std::locale& Loc=std::locale() ) + { + ::boost::algorithm::find_format_all( + Input, + ::boost::algorithm::first_finder(Search, is_iequal(Loc)), + ::boost::algorithm::empty_formatter(Input) ); + } + +// erase_head --------------------------------------------------------------------// + + //! Erase head algorithm + /*! + Remove the head from the input. The head is a prefix of a sequence of given size. + If the sequence is shorter then required, the whole string is + considered to be the head. The result is a modified copy of the input. + It is returned as a sequence or copied to the output iterator. + + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param N Length of the head. + For N>=0, at most N characters are extracted. + For N<0, size(Input)-|N| characters are extracted. + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename RangeT> + inline OutputIteratorT erase_head_copy( + OutputIteratorT Output, + const RangeT& Input, + int N ) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::head_finder(N), + ::boost::algorithm::empty_formatter( Input ) ); + } + + //! Erase head algorithm + /*! + \overload + */ + template<typename SequenceT> + inline SequenceT erase_head_copy( + const SequenceT& Input, + int N ) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::head_finder(N), + ::boost::algorithm::empty_formatter( Input ) ); + } + + //! Erase head algorithm + /*! + Remove the head from the input. The head is a prefix of a sequence of given size. + If the sequence is shorter then required, the whole string is + considered to be the head. The input sequence is modified in-place. + + \param Input An input string + \param N Length of the head + For N>=0, at most N characters are extracted. + For N<0, size(Input)-|N| characters are extracted. + */ + template<typename SequenceT> + inline void erase_head( + SequenceT& Input, + int N ) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::head_finder(N), + ::boost::algorithm::empty_formatter( Input ) ); + } + +// erase_tail --------------------------------------------------------------------// + + //! Erase tail algorithm + /*! + Remove the tail from the input. The tail is a suffix of a sequence of given size. + If the sequence is shorter then required, the whole string is + considered to be the tail. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param N Length of the head. + For N>=0, at most N characters are extracted. + For N<0, size(Input)-|N| characters are extracted. + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename RangeT> + inline OutputIteratorT erase_tail_copy( + OutputIteratorT Output, + const RangeT& Input, + int N ) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::tail_finder(N), + ::boost::algorithm::empty_formatter( Input ) ); + } + + //! Erase tail algorithm + /*! + \overload + */ + template<typename SequenceT> + inline SequenceT erase_tail_copy( + const SequenceT& Input, + int N ) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::tail_finder(N), + ::boost::algorithm::empty_formatter( Input ) ); + } + + //! Erase tail algorithm + /*! + Remove the tail from the input. The tail is a suffix of a sequence of given size. + If the sequence is shorter then required, the whole string is + considered to be the tail. The input sequence is modified in-place. + + \param Input An input string + \param N Length of the head + For N>=0, at most N characters are extracted. + For N<0, size(Input)-|N| characters are extracted. + */ + template<typename SequenceT> + inline void erase_tail( + SequenceT& Input, + int N ) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::tail_finder(N), + ::boost::algorithm::empty_formatter( Input ) ); + } + + } // namespace algorithm + + // pull names into the boost namespace + using algorithm::erase_range_copy; + using algorithm::erase_range; + using algorithm::erase_first_copy; + using algorithm::erase_first; + using algorithm::ierase_first_copy; + using algorithm::ierase_first; + using algorithm::erase_last_copy; + using algorithm::erase_last; + using algorithm::ierase_last_copy; + using algorithm::ierase_last; + using algorithm::erase_nth_copy; + using algorithm::erase_nth; + using algorithm::ierase_nth_copy; + using algorithm::ierase_nth; + using algorithm::erase_all_copy; + using algorithm::erase_all; + using algorithm::ierase_all_copy; + using algorithm::ierase_all; + using algorithm::erase_head_copy; + using algorithm::erase_head; + using algorithm::erase_tail_copy; + using algorithm::erase_tail; + +} // namespace boost + + +#endif // BOOST_ERASE_HPP diff --git a/Utilities/BGL/boost/algorithm/string/find.hpp b/Utilities/BGL/boost/algorithm/string/find.hpp new file mode 100755 index 0000000000000000000000000000000000000000..5c4775a6a3864913d893873156e705554bce7e3d --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/find.hpp @@ -0,0 +1,334 @@ +// Boost string_algo library find.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_FIND_HPP +#define BOOST_STRING_FIND_HPP + +#include <boost/algorithm/string/config.hpp> + +#include <boost/range/iterator_range.hpp> +#include <boost/range/begin.hpp> +#include <boost/range/end.hpp> +#include <boost/range/iterator.hpp> +#include <boost/range/as_literal.hpp> + +#include <boost/algorithm/string/finder.hpp> +#include <boost/algorithm/string/compare.hpp> +#include <boost/algorithm/string/constants.hpp> + +/*! \file + Defines a set of find algorithms. The algorithms are searching + for a substring of the input. The result is given as an \c iterator_range + delimiting the substring. +*/ + +namespace boost { + namespace algorithm { + +// Generic find -----------------------------------------------// + + //! Generic find algorithm + /*! + Search the input using the given finder. + + \param Input A string which will be searched. + \param Finder Finder object used for searching. + \return + An \c iterator_range delimiting the match. + Returned iterator is either \c RangeT::iterator or + \c RangeT::const_iterator, depending on the constness of + the input parameter. + */ + template<typename RangeT, typename FinderT> + inline iterator_range< + BOOST_STRING_TYPENAME range_iterator<RangeT>::type> + find( + RangeT& Input, + const FinderT& Finder) + { + iterator_range<BOOST_STRING_TYPENAME range_iterator<RangeT>::type> lit_input(::boost::as_literal(Input)); + + return Finder(::boost::begin(lit_input),::boost::end(lit_input)); + } + +// find_first -----------------------------------------------// + + //! Find first algorithm + /*! + Search for the first occurrence of the substring in the input. + + \param Input A string which will be searched. + \param Search A substring to be searched for. + \return + An \c iterator_range delimiting the match. + Returned iterator is either \c RangeT::iterator or + \c RangeT::const_iterator, depending on the constness of + the input parameter. + + \note This function provides the strong exception-safety guarantee + */ + template<typename Range1T, typename Range2T> + inline iterator_range< + BOOST_STRING_TYPENAME range_iterator<Range1T>::type> + find_first( + Range1T& Input, + const Range2T& Search) + { + return ::boost::algorithm::find(Input, ::boost::algorithm::first_finder(Search)); + } + + //! Find first algorithm ( case insensitive ) + /*! + Search for the first occurence of the substring in the input. + Searching is case insensitive. + + \param Input A string which will be searched. + \param Search A substring to be searched for. + \param Loc A locale used for case insensitive comparison + \return + An \c iterator_range delimiting the match. + Returned iterator is either \c Range1T::iterator or + \c Range1T::const_iterator, depending on the constness of + the input parameter. + + \note This function provides the strong exception-safety guarantee + */ + template<typename Range1T, typename Range2T> + inline iterator_range< + BOOST_STRING_TYPENAME range_iterator<Range1T>::type> + ifind_first( + Range1T& Input, + const Range2T& Search, + const std::locale& Loc=std::locale()) + { + return ::boost::algorithm::find(Input, ::boost::algorithm::first_finder(Search,is_iequal(Loc))); + } + +// find_last -----------------------------------------------// + + //! Find last algorithm + /*! + Search for the last occurrence of the substring in the input. + + \param Input A string which will be searched. + \param Search A substring to be searched for. + \return + An \c iterator_range delimiting the match. + Returned iterator is either \c Range1T::iterator or + \c Range1T::const_iterator, depending on the constness of + the input parameter. + + \note This function provides the strong exception-safety guarantee + */ + template<typename Range1T, typename Range2T> + inline iterator_range< + BOOST_STRING_TYPENAME range_iterator<Range1T>::type> + find_last( + Range1T& Input, + const Range2T& Search) + { + return ::boost::algorithm::find(Input, ::boost::algorithm::last_finder(Search)); + } + + //! Find last algorithm ( case insensitive ) + /*! + Search for the last match a string in the input. + Searching is case insensitive. + + \param Input A string which will be searched. + \param Search A substring to be searched for. + \param Loc A locale used for case insensitive comparison + \return + An \c iterator_range delimiting the match. + Returned iterator is either \c Range1T::iterator or + \c Range1T::const_iterator, depending on the constness of + the input parameter. + + \note This function provides the strong exception-safety guarantee + */ + template<typename Range1T, typename Range2T> + inline iterator_range< + BOOST_STRING_TYPENAME range_iterator<Range1T>::type> + ifind_last( + Range1T& Input, + const Range2T& Search, + const std::locale& Loc=std::locale()) + { + return ::boost::algorithm::find(Input, ::boost::algorithm::last_finder(Search, is_iequal(Loc))); + } + +// find_nth ----------------------------------------------------------------------// + + //! Find n-th algorithm + /*! + Search for the n-th (zero-indexed) occurrence of the substring in the + input. + + \param Input A string which will be searched. + \param Search A substring to be searched for. + \param Nth An index (zero-indexed) of the match to be found. + For negative N, the matches are counted from the end of string. + \return + An \c iterator_range delimiting the match. + Returned iterator is either \c Range1T::iterator or + \c Range1T::const_iterator, depending on the constness of + the input parameter. + */ + template<typename Range1T, typename Range2T> + inline iterator_range< + BOOST_STRING_TYPENAME range_iterator<Range1T>::type> + find_nth( + Range1T& Input, + const Range2T& Search, + int Nth) + { + return ::boost::algorithm::find(Input, ::boost::algorithm::nth_finder(Search,Nth)); + } + + //! Find n-th algorithm ( case insensitive ). + /*! + Search for the n-th (zero-indexed) occurrence of the substring in the + input. Searching is case insensitive. + + \param Input A string which will be searched. + \param Search A substring to be searched for. + \param Nth An index (zero-indexed) of the match to be found. + For negative N, the matches are counted from the end of string. + \param Loc A locale used for case insensitive comparison + \return + An \c iterator_range delimiting the match. + Returned iterator is either \c Range1T::iterator or + \c Range1T::const_iterator, depending on the constness of + the input parameter. + + + \note This function provides the strong exception-safety guarantee + */ + template<typename Range1T, typename Range2T> + inline iterator_range< + BOOST_STRING_TYPENAME range_iterator<Range1T>::type> + ifind_nth( + Range1T& Input, + const Range2T& Search, + int Nth, + const std::locale& Loc=std::locale()) + { + return ::boost::algorithm::find(Input, ::boost::algorithm::nth_finder(Search,Nth,is_iequal(Loc))); + } + +// find_head ----------------------------------------------------------------------// + + //! Find head algorithm + /*! + Get the head of the input. Head is a prefix of the string of the + given size. If the input is shorter then required, whole input if considered + to be the head. + + \param Input An input string + \param N Length of the head + For N>=0, at most N characters are extracted. + For N<0, size(Input)-|N| characters are extracted. + \return + An \c iterator_range delimiting the match. + Returned iterator is either \c Range1T::iterator or + \c Range1T::const_iterator, depending on the constness of + the input parameter. + + \note This function provides the strong exception-safety guarantee + */ + template<typename RangeT> + inline iterator_range< + BOOST_STRING_TYPENAME range_iterator<RangeT>::type> + find_head( + RangeT& Input, + int N) + { + return ::boost::algorithm::find(Input, ::boost::algorithm::head_finder(N)); + } + +// find_tail ----------------------------------------------------------------------// + + //! Find tail algorithm + /*! + Get the head of the input. Head is a suffix of the string of the + given size. If the input is shorter then required, whole input if considered + to be the tail. + + \param Input An input string + \param N Length of the tail. + For N>=0, at most N characters are extracted. + For N<0, size(Input)-|N| characters are extracted. + \return + An \c iterator_range delimiting the match. + Returned iterator is either \c RangeT::iterator or + \c RangeT::const_iterator, depending on the constness of + the input parameter. + + + \note This function provides the strong exception-safety guarantee + */ + template<typename RangeT> + inline iterator_range< + BOOST_STRING_TYPENAME range_iterator<RangeT>::type> + find_tail( + RangeT& Input, + int N) + { + return ::boost::algorithm::find(Input, ::boost::algorithm::tail_finder(N)); + } + +// find_token --------------------------------------------------------------------// + + //! Find token algorithm + /*! + Look for a given token in the string. Token is a character that matches the + given predicate. + If the "token compress mode" is enabled, adjacent tokens are considered to be one match. + + \param Input A input string. + \param Pred An unary predicate to identify a token + \param eCompress Enable/Disable compressing of adjacent tokens + \return + An \c iterator_range delimiting the match. + Returned iterator is either \c RangeT::iterator or + \c RangeT::const_iterator, depending on the constness of + the input parameter. + + \note This function provides the strong exception-safety guarantee + */ + template<typename RangeT, typename PredicateT> + inline iterator_range< + BOOST_STRING_TYPENAME range_iterator<RangeT>::type> + find_token( + RangeT& Input, + PredicateT Pred, + token_compress_mode_type eCompress=token_compress_off) + { + return ::boost::algorithm::find(Input, ::boost::algorithm::token_finder(Pred, eCompress)); + } + + } // namespace algorithm + + // pull names to the boost namespace + using algorithm::find; + using algorithm::find_first; + using algorithm::ifind_first; + using algorithm::find_last; + using algorithm::ifind_last; + using algorithm::find_nth; + using algorithm::ifind_nth; + using algorithm::find_head; + using algorithm::find_tail; + using algorithm::find_token; + +} // namespace boost + + +#endif // BOOST_STRING_FIND_HPP diff --git a/Utilities/BGL/boost/algorithm/string/find_format.hpp b/Utilities/BGL/boost/algorithm/string/find_format.hpp new file mode 100755 index 0000000000000000000000000000000000000000..c66c9b0ab3888334a8df67fc739ef78403f856a8 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/find_format.hpp @@ -0,0 +1,287 @@ +// Boost string_algo library find_format.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_FIND_FORMAT_HPP +#define BOOST_STRING_FIND_FORMAT_HPP + +#include <deque> +#include <boost/detail/iterator.hpp> +#include <boost/range/iterator_range.hpp> +#include <boost/range/begin.hpp> +#include <boost/range/end.hpp> +#include <boost/range/const_iterator.hpp> +#include <boost/range/as_literal.hpp> + +#include <boost/algorithm/string/concept.hpp> +#include <boost/algorithm/string/detail/find_format.hpp> +#include <boost/algorithm/string/detail/find_format_all.hpp> + +/*! \file + Defines generic replace algorithms. Each algorithm replaces + part(s) of the input. The part to be replaced is looked up using a Finder object. + Result of finding is then used by a Formatter object to generate the replacement. +*/ + +namespace boost { + namespace algorithm { + +// generic replace -----------------------------------------------------------------// + + //! Generic replace algorithm + /*! + Use the Finder to search for a substring. Use the Formatter to format + this substring and replace it in the input. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + + \param Output An output iterator to which the result will be copied + \param Input An input sequence + \param Finder A Finder object used to search for a match to be replaced + \param Formatter A Formatter object used to format a match + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename RangeT, + typename FinderT, + typename FormatterT> + inline OutputIteratorT find_format_copy( + OutputIteratorT Output, + const RangeT& Input, + FinderT Finder, + FormatterT Formatter ) + { + // Concept check + BOOST_CONCEPT_ASSERT(( + FinderConcept< + FinderT, + BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> + )); + BOOST_CONCEPT_ASSERT(( + FormatterConcept< + FormatterT, + FinderT,BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> + )); + + iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_input(::boost::as_literal(Input)); + + return detail::find_format_copy_impl( + Output, + lit_input, + Formatter, + Finder( ::boost::begin(lit_input), ::boost::end(lit_input) ) ); + } + + //! Generic replace algorithm + /*! + \overload + */ + template< + typename SequenceT, + typename FinderT, + typename FormatterT> + inline SequenceT find_format_copy( + const SequenceT& Input, + FinderT Finder, + FormatterT Formatter ) + { + // Concept check + BOOST_CONCEPT_ASSERT(( + FinderConcept< + FinderT, + BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type> + )); + BOOST_CONCEPT_ASSERT(( + FormatterConcept< + FormatterT, + FinderT,BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type> + )); + + return detail::find_format_copy_impl( + Input, + Formatter, + Finder(::boost::begin(Input), ::boost::end(Input))); + } + + //! Generic replace algorithm + /*! + Use the Finder to search for a substring. Use the Formatter to format + this substring and replace it in the input. The input is modified in-place. + + \param Input An input sequence + \param Finder A Finder object used to search for a match to be replaced + \param Formatter A Formatter object used to format a match + */ + template< + typename SequenceT, + typename FinderT, + typename FormatterT> + inline void find_format( + SequenceT& Input, + FinderT Finder, + FormatterT Formatter) + { + // Concept check + BOOST_CONCEPT_ASSERT(( + FinderConcept< + FinderT, + BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type> + )); + BOOST_CONCEPT_ASSERT(( + FormatterConcept< + FormatterT, + FinderT,BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type> + )); + + detail::find_format_impl( + Input, + Formatter, + Finder(::boost::begin(Input), ::boost::end(Input))); + } + + +// find_format_all generic ----------------------------------------------------------------// + + //! Generic replace all algorithm + /*! + Use the Finder to search for a substring. Use the Formatter to format + this substring and replace it in the input. Repeat this for all matching + substrings. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + + \param Output An output iterator to which the result will be copied + \param Input An input sequence + \param Finder A Finder object used to search for a match to be replaced + \param Formatter A Formatter object used to format a match + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename RangeT, + typename FinderT, + typename FormatterT> + inline OutputIteratorT find_format_all_copy( + OutputIteratorT Output, + const RangeT& Input, + FinderT Finder, + FormatterT Formatter) + { + // Concept check + BOOST_CONCEPT_ASSERT(( + FinderConcept< + FinderT, + BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> + )); + BOOST_CONCEPT_ASSERT(( + FormatterConcept< + FormatterT, + FinderT,BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> + )); + + iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_input(::boost::as_literal(Input)); + + return detail::find_format_all_copy_impl( + Output, + lit_input, + Finder, + Formatter, + Finder(::boost::begin(lit_input), ::boost::end(lit_input))); + } + + //! Generic replace all algorithm + /*! + \overload + */ + template< + typename SequenceT, + typename FinderT, + typename FormatterT > + inline SequenceT find_format_all_copy( + const SequenceT& Input, + FinderT Finder, + FormatterT Formatter ) + { + // Concept check + BOOST_CONCEPT_ASSERT(( + FinderConcept< + FinderT, + BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type> + )); + BOOST_CONCEPT_ASSERT(( + FormatterConcept< + FormatterT, + FinderT,BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type> + )); + + return detail::find_format_all_copy_impl( + Input, + Finder, + Formatter, + Finder( ::boost::begin(Input), ::boost::end(Input) ) ); + } + + //! Generic replace all algorithm + /*! + Use the Finder to search for a substring. Use the Formatter to format + this substring and replace it in the input. Repeat this for all matching + substrings.The input is modified in-place. + + \param Input An input sequence + \param Finder A Finder object used to search for a match to be replaced + \param Formatter A Formatter object used to format a match + */ + template< + typename SequenceT, + typename FinderT, + typename FormatterT > + inline void find_format_all( + SequenceT& Input, + FinderT Finder, + FormatterT Formatter ) + { + // Concept check + BOOST_CONCEPT_ASSERT(( + FinderConcept< + FinderT, + BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type> + )); + BOOST_CONCEPT_ASSERT(( + FormatterConcept< + FormatterT, + FinderT,BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type> + )); + + detail::find_format_all_impl( + Input, + Finder, + Formatter, + Finder(::boost::begin(Input), ::boost::end(Input))); + + } + + } // namespace algorithm + + // pull the names to the boost namespace + using algorithm::find_format_copy; + using algorithm::find_format; + using algorithm::find_format_all_copy; + using algorithm::find_format_all; + +} // namespace boost + + +#endif // BOOST_STRING_FIND_FORMAT_HPP diff --git a/Utilities/BGL/boost/algorithm/string/find_iterator.hpp b/Utilities/BGL/boost/algorithm/string/find_iterator.hpp new file mode 100755 index 0000000000000000000000000000000000000000..53733cd0436f023c2a961e3c299dfc4ac8c5db90 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/find_iterator.hpp @@ -0,0 +1,375 @@ +// Boost string_algo library find_iterator.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2004. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_FIND_ITERATOR_HPP +#define BOOST_STRING_FIND_ITERATOR_HPP + +#include <boost/algorithm/string/config.hpp> +#include <boost/iterator/iterator_facade.hpp> +#include <boost/iterator/iterator_categories.hpp> + +#include <boost/range/iterator_range.hpp> +#include <boost/range/begin.hpp> +#include <boost/range/end.hpp> +#include <boost/range/iterator.hpp> +#include <boost/range/as_literal.hpp> + +#include <boost/algorithm/string/detail/find_iterator.hpp> + +/*! \file + Defines find iterator classes. Find iterator repeatedly applies a Finder + to the specified input string to search for matches. Dereferencing + the iterator yields the current match or a range between the last and the current + match depending on the iterator used. +*/ + +namespace boost { + namespace algorithm { + +// find_iterator -----------------------------------------------// + + //! find_iterator + /*! + Find iterator encapsulates a Finder and allows + for incremental searching in a string. + Each increment moves the iterator to the next match. + + Find iterator is a readable forward traversal iterator. + + Dereferencing the iterator yields an iterator_range delimiting + the current match. + */ + template<typename IteratorT> + class find_iterator : + public iterator_facade< + find_iterator<IteratorT>, + const iterator_range<IteratorT>, + forward_traversal_tag >, + private detail::find_iterator_base<IteratorT> + { + private: + // facade support + friend class ::boost::iterator_core_access; + + private: + // typedefs + + typedef detail::find_iterator_base<IteratorT> base_type; + typedef BOOST_STRING_TYPENAME + base_type::input_iterator_type input_iterator_type; + typedef BOOST_STRING_TYPENAME + base_type::match_type match_type; + + public: + //! Default constructor + /*! + Construct null iterator. All null iterators are equal. + + \post eof()==true + */ + find_iterator() {} + + //! Copy constructor + /*! + Construct a copy of the find_iterator + */ + find_iterator( const find_iterator& Other ) : + base_type(Other), + m_Match(Other.m_Match), + m_End(Other.m_End) {} + + //! Constructor + /*! + Construct new find_iterator for a given finder + and a range. + */ + template<typename FinderT> + find_iterator( + IteratorT Begin, + IteratorT End, + FinderT Finder ) : + detail::find_iterator_base<IteratorT>(Finder,0), + m_Match(Begin,Begin), + m_End(End) + { + increment(); + } + + //! Constructor + /*! + Construct new find_iterator for a given finder + and a range. + */ + template<typename FinderT, typename RangeT> + find_iterator( + RangeT& Col, + FinderT Finder ) : + detail::find_iterator_base<IteratorT>(Finder,0) + { + iterator_range<BOOST_STRING_TYPENAME range_iterator<RangeT>::type> lit_col(::boost::as_literal(Col)); + m_Match=::boost::make_iterator_range(::boost::begin(lit_col), ::boost::begin(lit_col)); + m_End=::boost::end(lit_col); + + increment(); + } + + private: + // iterator operations + + // dereference + const match_type& dereference() const + { + return m_Match; + } + + // increment + void increment() + { + m_Match=this->do_find(m_Match.end(),m_End); + } + + // comparison + bool equal( const find_iterator& Other ) const + { + bool bEof=eof(); + bool bOtherEof=Other.eof(); + + return bEof || bOtherEof ? bEof==bOtherEof : + ( + m_Match==Other.m_Match && + m_End==Other.m_End + ); + } + + public: + // operations + + //! Eof check + /*! + Check the eof condition. Eof condition means that + there is nothing more to be searched i.e. find_iterator + is after the last match. + */ + bool eof() const + { + return + this->is_null() || + ( + m_Match.begin() == m_End && + m_Match.end() == m_End + ); + } + + private: + // Attributes + match_type m_Match; + input_iterator_type m_End; + }; + + //! find iterator construction helper + /*! + * Construct a find iterator to iterate through the specified string + */ + template<typename RangeT, typename FinderT> + inline find_iterator< + BOOST_STRING_TYPENAME range_iterator<RangeT>::type> + make_find_iterator( + RangeT& Collection, + FinderT Finder) + { + return find_iterator<BOOST_STRING_TYPENAME range_iterator<RangeT>::type>( + Collection, Finder); + } + +// split iterator -----------------------------------------------// + + //! split_iterator + /*! + Split iterator encapsulates a Finder and allows + for incremental searching in a string. + Unlike the find iterator, split iterator iterates + through gaps between matches. + + Find iterator is a readable forward traversal iterator. + + Dereferencing the iterator yields an iterator_range delimiting + the current match. + */ + template<typename IteratorT> + class split_iterator : + public iterator_facade< + split_iterator<IteratorT>, + const iterator_range<IteratorT>, + forward_traversal_tag >, + private detail::find_iterator_base<IteratorT> + { + private: + // facade support + friend class ::boost::iterator_core_access; + + private: + // typedefs + + typedef detail::find_iterator_base<IteratorT> base_type; + typedef BOOST_STRING_TYPENAME + base_type::input_iterator_type input_iterator_type; + typedef BOOST_STRING_TYPENAME + base_type::match_type match_type; + + public: + //! Default constructor + /*! + Construct null iterator. All null iterators are equal. + + \post eof()==true + */ + split_iterator() {} + //! Copy constructor + /*! + Construct a copy of the split_iterator + */ + split_iterator( const split_iterator& Other ) : + base_type(Other), + m_Match(Other.m_Match), + m_Next(Other.m_Next), + m_End(Other.m_End), + m_bEof(false) + {} + + //! Constructor + /*! + Construct new split_iterator for a given finder + and a range. + */ + template<typename FinderT> + split_iterator( + IteratorT Begin, + IteratorT End, + FinderT Finder ) : + detail::find_iterator_base<IteratorT>(Finder,0), + m_Match(Begin,Begin), + m_Next(Begin), + m_End(End), + m_bEof(false) + { + increment(); + } + //! Constructor + /*! + Construct new split_iterator for a given finder + and a collection. + */ + template<typename FinderT, typename RangeT> + split_iterator( + RangeT& Col, + FinderT Finder ) : + detail::find_iterator_base<IteratorT>(Finder,0), + m_bEof(false) + { + iterator_range<BOOST_STRING_TYPENAME range_iterator<RangeT>::type> lit_col(::boost::as_literal(Col)); + m_Match=make_iterator_range(::boost::begin(lit_col), ::boost::begin(lit_col)); + m_Next=::boost::begin(lit_col); + m_End=::boost::end(lit_col); + + increment(); + } + + + private: + // iterator operations + + // dereference + const match_type& dereference() const + { + return m_Match; + } + + // increment + void increment() + { + match_type FindMatch=this->do_find( m_Next, m_End ); + + if(FindMatch.begin()==m_End && FindMatch.end()==m_End) + { + if(m_Match.end()==m_End) + { + // Mark iterator as eof + m_bEof=true; + } + } + + m_Match=match_type( m_Next, FindMatch.begin() ); + m_Next=FindMatch.end(); + } + + // comparison + bool equal( const split_iterator& Other ) const + { + bool bEof=eof(); + bool bOtherEof=Other.eof(); + + return bEof || bOtherEof ? bEof==bOtherEof : + ( + m_Match==Other.m_Match && + m_Next==Other.m_Next && + m_End==Other.m_End + ); + } + + public: + // operations + + //! Eof check + /*! + Check the eof condition. Eof condition means that + there is nothing more to be searched i.e. find_iterator + is after the last match. + */ + bool eof() const + { + return this->is_null() || m_bEof; + } + + private: + // Attributes + match_type m_Match; + input_iterator_type m_Next; + input_iterator_type m_End; + bool m_bEof; + }; + + //! split iterator construction helper + /*! + * Construct a split iterator to iterate through the specified collection + */ + template<typename RangeT, typename FinderT> + inline split_iterator< + BOOST_STRING_TYPENAME range_iterator<RangeT>::type> + make_split_iterator( + RangeT& Collection, + FinderT Finder) + { + return split_iterator<BOOST_STRING_TYPENAME range_iterator<RangeT>::type>( + Collection, Finder); + } + + + } // namespace algorithm + + // pull names to the boost namespace + using algorithm::find_iterator; + using algorithm::make_find_iterator; + using algorithm::split_iterator; + using algorithm::make_split_iterator; + +} // namespace boost + + +#endif // BOOST_STRING_FIND_ITERATOR_HPP diff --git a/Utilities/BGL/boost/algorithm/string/finder.hpp b/Utilities/BGL/boost/algorithm/string/finder.hpp new file mode 100755 index 0000000000000000000000000000000000000000..2ddca4d35a7bb55cb9ad3b1f16921e3a78524f11 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/finder.hpp @@ -0,0 +1,270 @@ +// Boost string_algo library finder.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2006. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_FINDER_HPP +#define BOOST_STRING_FINDER_HPP + +#include <boost/algorithm/string/config.hpp> + +#include <boost/range/iterator_range.hpp> +#include <boost/range/begin.hpp> +#include <boost/range/end.hpp> +#include <boost/range/iterator.hpp> +#include <boost/range/const_iterator.hpp> + +#include <boost/algorithm/string/constants.hpp> +#include <boost/algorithm/string/detail/finder.hpp> +#include <boost/algorithm/string/compare.hpp> + +/*! \file + Defines Finder generators. Finder object is a functor which is able to + find a substring matching a specific criteria in the input. + Finders are used as a pluggable components for replace, find + and split facilities. This header contains generator functions + for finders provided in this library. +*/ + +namespace boost { + namespace algorithm { + +// Finder generators ------------------------------------------// + + //! "First" finder + /*! + Construct the \c first_finder. The finder searches for the first + occurrence of the string in a given input. + The result is given as an \c iterator_range delimiting the match. + + \param Search A substring to be searched for. + \param Comp An element comparison predicate + \return An instance of the \c first_finder object + */ + template<typename RangeT> + inline detail::first_finderF< + BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type, + is_equal> + first_finder( const RangeT& Search ) + { + return + detail::first_finderF< + BOOST_STRING_TYPENAME + range_const_iterator<RangeT>::type, + is_equal>( ::boost::as_literal(Search), is_equal() ) ; + } + + //! "First" finder + /*! + \overload + */ + template<typename RangeT,typename PredicateT> + inline detail::first_finderF< + BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type, + PredicateT> + first_finder( + const RangeT& Search, PredicateT Comp ) + { + return + detail::first_finderF< + BOOST_STRING_TYPENAME + range_const_iterator<RangeT>::type, + PredicateT>( ::boost::as_literal(Search), Comp ); + } + + //! "Last" finder + /*! + Construct the \c last_finder. The finder searches for the last + occurrence of the string in a given input. + The result is given as an \c iterator_range delimiting the match. + + \param Search A substring to be searched for. + \param Comp An element comparison predicate + \return An instance of the \c last_finder object + */ + template<typename RangeT> + inline detail::last_finderF< + BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type, + is_equal> + last_finder( const RangeT& Search ) + { + return + detail::last_finderF< + BOOST_STRING_TYPENAME + range_const_iterator<RangeT>::type, + is_equal>( ::boost::as_literal(Search), is_equal() ); + } + //! "Last" finder + /*! + \overload + */ + template<typename RangeT, typename PredicateT> + inline detail::last_finderF< + BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type, + PredicateT> + last_finder( const RangeT& Search, PredicateT Comp ) + { + return + detail::last_finderF< + BOOST_STRING_TYPENAME + range_const_iterator<RangeT>::type, + PredicateT>( ::boost::as_literal(Search), Comp ) ; + } + + //! "Nth" finder + /*! + Construct the \c nth_finder. The finder searches for the n-th (zero-indexed) + occurrence of the string in a given input. + The result is given as an \c iterator_range delimiting the match. + + \param Search A substring to be searched for. + \param Nth An index of the match to be find + \param Comp An element comparison predicate + \return An instance of the \c nth_finder object + */ + template<typename RangeT> + inline detail::nth_finderF< + BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type, + is_equal> + nth_finder( + const RangeT& Search, + int Nth) + { + return + detail::nth_finderF< + BOOST_STRING_TYPENAME + range_const_iterator<RangeT>::type, + is_equal>( ::boost::as_literal(Search), Nth, is_equal() ) ; + } + //! "Nth" finder + /*! + \overload + */ + template<typename RangeT, typename PredicateT> + inline detail::nth_finderF< + BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type, + PredicateT> + nth_finder( + const RangeT& Search, + int Nth, + PredicateT Comp ) + { + return + detail::nth_finderF< + BOOST_STRING_TYPENAME + range_const_iterator<RangeT>::type, + PredicateT>( ::boost::as_literal(Search), Nth, Comp ); + } + + //! "Head" finder + /*! + Construct the \c head_finder. The finder returns a head of a given + input. The head is a prefix of a string up to n elements in + size. If an input has less then n elements, whole input is + considered a head. + The result is given as an \c iterator_range delimiting the match. + + \param N The size of the head + \return An instance of the \c head_finder object + */ + inline detail::head_finderF + head_finder( int N ) + { + return detail::head_finderF(N); + } + + //! "Tail" finder + /*! + Construct the \c tail_finder. The finder returns a tail of a given + input. The tail is a suffix of a string up to n elements in + size. If an input has less then n elements, whole input is + considered a head. + The result is given as an \c iterator_range delimiting the match. + + \param N The size of the head + \return An instance of the \c tail_finder object + */ + inline detail::tail_finderF + tail_finder( int N ) + { + return detail::tail_finderF(N); + } + + //! "Token" finder + /*! + Construct the \c token_finder. The finder searches for a token + specified by a predicate. It is similar to std::find_if + algorithm, with an exception that it return a range of + instead of a single iterator. + + If "compress token mode" is enabled, adjacent matching tokens are + concatenated into one match. Thus the finder can be used to + search for continuous segments of characters satisfying the + given predicate. + + The result is given as an \c iterator_range delimiting the match. + + \param Pred An element selection predicate + \param eCompress Compress flag + \return An instance of the \c token_finder object + */ + template< typename PredicateT > + inline detail::token_finderF<PredicateT> + token_finder( + PredicateT Pred, + token_compress_mode_type eCompress=token_compress_off ) + { + return detail::token_finderF<PredicateT>( Pred, eCompress ); + } + + //! "Range" finder + /*! + Construct the \c range_finder. The finder does not perform + any operation. It simply returns the given range for + any input. + + \param Begin Beginning of the range + \param End End of the range + \param Range The range. + \return An instance of the \c range_finger object + */ + template< typename ForwardIteratorT > + inline detail::range_finderF<ForwardIteratorT> + range_finder( + ForwardIteratorT Begin, + ForwardIteratorT End ) + { + return detail::range_finderF<ForwardIteratorT>( Begin, End ); + } + + //! "Range" finder + /*! + \overload + */ + template< typename ForwardIteratorT > + inline detail::range_finderF<ForwardIteratorT> + range_finder( iterator_range<ForwardIteratorT> Range ) + { + return detail::range_finderF<ForwardIteratorT>( Range ); + } + + } // namespace algorithm + + // pull the names to the boost namespace + using algorithm::first_finder; + using algorithm::last_finder; + using algorithm::nth_finder; + using algorithm::head_finder; + using algorithm::tail_finder; + using algorithm::token_finder; + using algorithm::range_finder; + +} // namespace boost + + +#endif // BOOST_STRING_FINDER_HPP diff --git a/Utilities/BGL/boost/algorithm/string/formatter.hpp b/Utilities/BGL/boost/algorithm/string/formatter.hpp new file mode 100755 index 0000000000000000000000000000000000000000..017eb90b931205fc83c6409d9bb7f13fb21ed4f1 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/formatter.hpp @@ -0,0 +1,103 @@ +// Boost string_algo library formatter.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_FORMATTER_HPP +#define BOOST_STRING_FORMATTER_HPP + +#include <boost/detail/iterator.hpp> +#include <boost/range/value_type.hpp> +#include <boost/range/iterator_range.hpp> +#include <boost/range/as_literal.hpp> + +#include <boost/algorithm/string/detail/formatter.hpp> + +/*! \file + Defines Formatter generators. Formatter is a functor which formats + a string according to given parameters. A Formatter works + in conjunction with a Finder. A Finder can provide additional information + for a specific Formatter. An example of such a cooperation is regex_finder + and regex_formatter. + + Formatters are used as pluggable components for replace facilities. + This header contains generator functions for the Formatters provided in this library. +*/ + +namespace boost { + namespace algorithm { + +// generic formatters ---------------------------------------------------------------// + + //! Constant formatter + /*! + Construct the \c const_formatter. Const formatter always returns + the same value, regardless of the parameter. + + \param Format A predefined value used as a result for formating + \return An instance of the \c const_formatter object. + */ + template<typename RangeT> + inline detail::const_formatF< + iterator_range< + BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> > + const_formatter(const RangeT& Format) + { + return detail::const_formatF< + iterator_range< + BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >(::boost::as_literal(Format)); + } + + //! Identity formatter + /*! + Construct the \c identity_formatter. Identity formatter always returns + the parameter. + + \return An instance of the \c identity_formatter object. + */ + template<typename RangeT> + inline detail::identity_formatF< + iterator_range< + BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> > + identity_formatter() + { + return detail::identity_formatF< + iterator_range< + BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >(); + } + + //! Empty formatter + /*! + Construct the \c empty_formatter. Empty formatter always returns an empty + sequence. + + \param Input container used to select a correct value_type for the + resulting empty_container<>. + \return An instance of the \c empty_formatter object. + */ + template<typename RangeT> + inline detail::empty_formatF< + BOOST_STRING_TYPENAME range_value<RangeT>::type> + empty_formatter(const RangeT&) + { + return detail::empty_formatF< + BOOST_STRING_TYPENAME range_value<RangeT>::type>(); + } + + + } // namespace algorithm + + // pull the names to the boost namespace + using algorithm::const_formatter; + using algorithm::identity_formatter; + using algorithm::empty_formatter; + +} // namespace boost + + +#endif // BOOST_FORMATTER_HPP diff --git a/Utilities/BGL/boost/algorithm/string/iter_find.hpp b/Utilities/BGL/boost/algorithm/string/iter_find.hpp new file mode 100755 index 0000000000000000000000000000000000000000..c4a2d06bbbcfb5df88f176cc40d5943a01e72a1d --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/iter_find.hpp @@ -0,0 +1,193 @@ +// Boost string_algo library iter_find.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_ITER_FIND_HPP +#define BOOST_STRING_ITER_FIND_HPP + +#include <boost/algorithm/string/config.hpp> +#include <algorithm> +#include <iterator> +#include <boost/iterator/transform_iterator.hpp> + +#include <boost/range/iterator_range.hpp> +#include <boost/range/begin.hpp> +#include <boost/range/end.hpp> +#include <boost/range/iterator.hpp> +#include <boost/range/value_type.hpp> +#include <boost/range/as_literal.hpp> + +#include <boost/algorithm/string/concept.hpp> +#include <boost/algorithm/string/find_iterator.hpp> +#include <boost/algorithm/string/detail/util.hpp> + +/*! \file + Defines generic split algorithms. Split algorithms can be + used to divide a sequence into several part according + to a given criteria. Result is given as a 'container + of containers' where elements are copies or references + to extracted parts. + + There are two algorithms provided. One iterates over matching + substrings, the other one over the gaps between these matches. +*/ + +namespace boost { + namespace algorithm { + +// iterate find ---------------------------------------------------// + + //! Iter find algorithm + /*! + This algorithm executes a given finder in iteration on the input, + until the end of input is reached, or no match is found. + Iteration is done using built-in find_iterator, so the real + searching is performed only when needed. + In each iteration new match is found and added to the result. + + \param Result A 'container container' to contain the result of search. + Both outer and inner container must have constructor taking a pair + of iterators as an argument. + Typical type of the result is + \c std::vector<boost::iterator_range<iterator>> + (each element of such a vector will container a range delimiting + a match). + \param Input A container which will be searched. + \param Finder A Finder object used for searching + \return A reference the result + + \note Prior content of the result will be overwritten. + */ + template< + typename SequenceSequenceT, + typename RangeT, + typename FinderT > + inline SequenceSequenceT& + iter_find( + SequenceSequenceT& Result, + RangeT& Input, + FinderT Finder ) + { + BOOST_CONCEPT_ASSERT(( + FinderConcept< + FinderT, + BOOST_STRING_TYPENAME range_iterator<RangeT>::type> + )); + + iterator_range<BOOST_STRING_TYPENAME range_iterator<RangeT>::type> lit_input(::boost::as_literal(Input)); + + typedef BOOST_STRING_TYPENAME + range_iterator<RangeT>::type input_iterator_type; + typedef find_iterator<input_iterator_type> find_iterator_type; + typedef detail::copy_iterator_rangeF< + BOOST_STRING_TYPENAME + range_value<SequenceSequenceT>::type, + input_iterator_type> copy_range_type; + + input_iterator_type InputEnd=::boost::end(lit_input); + + typedef transform_iterator<copy_range_type, find_iterator_type> + transform_iter_type; + + transform_iter_type itBegin= + ::boost::make_transform_iterator( + find_iterator_type( ::boost::begin(lit_input), InputEnd, Finder ), + copy_range_type()); + + transform_iter_type itEnd= + ::boost::make_transform_iterator( + find_iterator_type(), + copy_range_type()); + + SequenceSequenceT Tmp(itBegin, itEnd); + + Result.swap(Tmp); + return Result; + } + +// iterate split ---------------------------------------------------// + + //! Split find algorithm + /*! + This algorithm executes a given finder in iteration on the input, + until the end of input is reached, or no match is found. + Iteration is done using built-in find_iterator, so the real + searching is performed only when needed. + Each match is used as a separator of segments. These segments are then + returned in the result. + + \param Result A 'container container' to container the result of search. + Both outer and inner container must have constructor taking a pair + of iterators as an argument. + Typical type of the result is + \c std::vector<boost::iterator_range<iterator>> + (each element of such a vector will container a range delimiting + a match). + \param Input A container which will be searched. + \param Finder A finder object used for searching + \return A reference the result + + \note Prior content of the result will be overwritten. + */ + template< + typename SequenceSequenceT, + typename RangeT, + typename FinderT > + inline SequenceSequenceT& + iter_split( + SequenceSequenceT& Result, + RangeT& Input, + FinderT Finder ) + { + BOOST_CONCEPT_ASSERT(( + FinderConcept<FinderT, + BOOST_STRING_TYPENAME range_iterator<RangeT>::type> + )); + + iterator_range<BOOST_STRING_TYPENAME range_iterator<RangeT>::type> lit_input(::boost::as_literal(Input)); + + typedef BOOST_STRING_TYPENAME + range_iterator<RangeT>::type input_iterator_type; + typedef split_iterator<input_iterator_type> find_iterator_type; + typedef detail::copy_iterator_rangeF< + BOOST_STRING_TYPENAME + range_value<SequenceSequenceT>::type, + input_iterator_type> copy_range_type; + + input_iterator_type InputEnd=::boost::end(lit_input); + + typedef transform_iterator<copy_range_type, find_iterator_type> + transform_iter_type; + + transform_iter_type itBegin= + ::boost::make_transform_iterator( + find_iterator_type( ::boost::begin(lit_input), InputEnd, Finder ), + copy_range_type() ); + + transform_iter_type itEnd= + ::boost::make_transform_iterator( + find_iterator_type(), + copy_range_type() ); + + SequenceSequenceT Tmp(itBegin, itEnd); + + Result.swap(Tmp); + return Result; + } + + } // namespace algorithm + + // pull names to the boost namespace + using algorithm::iter_find; + using algorithm::iter_split; + +} // namespace boost + + +#endif // BOOST_STRING_ITER_FIND_HPP diff --git a/Utilities/BGL/boost/algorithm/string/join.hpp b/Utilities/BGL/boost/algorithm/string/join.hpp new file mode 100755 index 0000000000000000000000000000000000000000..cbc98d958299f76a31eadcc74af5c71ec6fe12fd --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/join.hpp @@ -0,0 +1,145 @@ +// Boost string_algo library join.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2006. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_JOIN_HPP +#define BOOST_STRING_JOIN_HPP + +#include <boost/algorithm/string/config.hpp> +#include <boost/algorithm/string/detail/sequence.hpp> +#include <boost/range/value_type.hpp> +#include <boost/range/as_literal.hpp> + +/*! \file + Defines join algorithm. + + Join algorithm is a counterpart to split algorithms. + It joins strings from a 'list' by adding user defined separator. + Additionally there is a version that allows simple filtering + by providing a predicate. +*/ + +namespace boost { + namespace algorithm { + +// join --------------------------------------------------------------// + + //! Join algorithm + /*! + This algorithm joins all strings in a 'list' into one long string. + Segments are concatenated by given separator. + + \param Input A container that holds the input strings. It must be a container-of-containers. + \param Separator A string that will separate the joined segments. + \return Concatenated string. + + \note This function provides the strong exception-safety guarantee + */ + template< typename SequenceSequenceT, typename Range1T> + inline typename range_value<SequenceSequenceT>::type + join( + const SequenceSequenceT& Input, + const Range1T& Separator) + { + // Define working types + typedef typename range_value<SequenceSequenceT>::type ResultT; + typedef typename range_const_iterator<SequenceSequenceT>::type InputIteratorT; + + // Parse input + InputIteratorT itBegin=::boost::begin(Input); + InputIteratorT itEnd=::boost::end(Input); + + // Construct container to hold the result + ResultT Result; + + // Append first element + if(itBegin!=itEnd) + { + detail::insert(Result, ::boost::end(Result), *itBegin); + ++itBegin; + } + + for(;itBegin!=itEnd; ++itBegin) + { + // Add separator + detail::insert(Result, ::boost::end(Result), ::boost::as_literal(Separator)); + // Add element + detail::insert(Result, ::boost::end(Result), *itBegin); + } + + return Result; + } + +// join_if ----------------------------------------------------------// + + //! Conditional join algorithm + /*! + This algorithm joins all strings in a 'list' into one long string. + Segments are concatenated by given separator. Only segments that + satisfy the predicate will be added to the result. + + \param Input A container that holds the input strings. It must be a container-of-containers. + \param Separator A string that will separate the joined segments. + \param Pred A segment selection predicate + \return Concatenated string. + + \note This function provides the strong exception-safety guarantee + */ + template< typename SequenceSequenceT, typename Range1T, typename PredicateT> + inline typename range_value<SequenceSequenceT>::type + join_if( + const SequenceSequenceT& Input, + const Range1T& Separator, + PredicateT Pred) + { + // Define working types + typedef typename range_value<SequenceSequenceT>::type ResultT; + typedef typename range_const_iterator<SequenceSequenceT>::type InputIteratorT; + + // Parse input + InputIteratorT itBegin=::boost::begin(Input); + InputIteratorT itEnd=::boost::end(Input); + + // Construct container to hold the result + ResultT Result; + + // Roll to the first element that will be added + while(itBegin!=itEnd && !Pred(*itBegin)) ++itBegin; + // Add this element + if(itBegin!=itEnd) + { + detail::insert(Result, ::boost::end(Result), *itBegin); + ++itBegin; + } + + for(;itBegin!=itEnd; ++itBegin) + { + if(Pred(*itBegin)) + { + // Add separator + detail::insert(Result, ::boost::end(Result), ::boost::as_literal(Separator)); + // Add element + detail::insert(Result, ::boost::end(Result), *itBegin); + } + } + + return Result; + } + + } // namespace algorithm + + // pull names to the boost namespace + using algorithm::join; + using algorithm::join_if; + +} // namespace boost + + +#endif // BOOST_STRING_JOIN_HPP + diff --git a/Utilities/BGL/boost/algorithm/string/predicate.hpp b/Utilities/BGL/boost/algorithm/string/predicate.hpp new file mode 100755 index 0000000000000000000000000000000000000000..b625405ebe8955050003d5c88aefd847722e5ef5 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/predicate.hpp @@ -0,0 +1,475 @@ +// Boost string_algo library predicate.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_PREDICATE_HPP +#define BOOST_STRING_PREDICATE_HPP + +#include <boost/algorithm/string/config.hpp> +#include <boost/range/begin.hpp> +#include <boost/range/end.hpp> +#include <boost/range/iterator.hpp> +#include <boost/range/const_iterator.hpp> +#include <boost/range/as_literal.hpp> +#include <boost/range/iterator_range.hpp> + +#include <boost/algorithm/string/compare.hpp> +#include <boost/algorithm/string/find.hpp> +#include <boost/algorithm/string/detail/predicate.hpp> + +/*! \file boost/algorithm/string/predicate.hpp + Defines string-related predicates. + The predicates determine whether a substring is contained in the input string + under various conditions: a string starts with the substring, ends with the + substring, simply contains the substring or if both strings are equal. + Additionaly the algorithm \c all() checks all elements of a container to satisfy a + condition. + + All predicates provide the strong exception guarantee. +*/ + +namespace boost { + namespace algorithm { + +// starts_with predicate -----------------------------------------------// + + //! 'Starts with' predicate + /*! + This predicate holds when the test string is a prefix of the Input. + In other words, if the input starts with the test. + When the optional predicate is specified, it is used for character-wise + comparison. + + \param Input An input sequence + \param Test A test sequence + \param Comp An element comparison predicate + \return The result of the test + + \note This function provides the strong exception-safety guarantee + */ + template<typename Range1T, typename Range2T, typename PredicateT> + inline bool starts_with( + const Range1T& Input, + const Range2T& Test, + PredicateT Comp) + { + iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range1T>::type> lit_input(::boost::as_literal(Input)); + iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range2T>::type> lit_test(::boost::as_literal(Test)); + + typedef BOOST_STRING_TYPENAME + range_const_iterator<Range1T>::type Iterator1T; + typedef BOOST_STRING_TYPENAME + range_const_iterator<Range2T>::type Iterator2T; + + Iterator1T InputEnd=::boost::end(lit_input); + Iterator2T TestEnd=::boost::end(lit_test); + + Iterator1T it=::boost::begin(lit_input); + Iterator2T pit=::boost::begin(lit_test); + for(; + it!=InputEnd && pit!=TestEnd; + ++it,++pit) + { + if( !(Comp(*it,*pit)) ) + return false; + } + + return pit==TestEnd; + } + + //! 'Starts with' predicate + /*! + \overload + */ + template<typename Range1T, typename Range2T> + inline bool starts_with( + const Range1T& Input, + const Range2T& Test) + { + return ::boost::algorithm::starts_with(Input, Test, is_equal()); + } + + //! 'Starts with' predicate ( case insensitive ) + /*! + This predicate holds when the test string is a prefix of the Input. + In other words, if the input starts with the test. + Elements are compared case insensitively. + + \param Input An input sequence + \param Test A test sequence + \param Loc A locale used for case insensitive comparison + \return The result of the test + + \note This function provides the strong exception-safety guarantee + */ + template<typename Range1T, typename Range2T> + inline bool istarts_with( + const Range1T& Input, + const Range2T& Test, + const std::locale& Loc=std::locale()) + { + return ::boost::algorithm::starts_with(Input, Test, is_iequal(Loc)); + } + + +// ends_with predicate -----------------------------------------------// + + //! 'Ends with' predicate + /*! + This predicate holds when the test string is a suffix of the Input. + In other words, if the input ends with the test. + When the optional predicate is specified, it is used for character-wise + comparison. + + + \param Input An input sequence + \param Test A test sequence + \param Comp An element comparison predicate + \return The result of the test + + \note This function provides the strong exception-safety guarantee + */ + template<typename Range1T, typename Range2T, typename PredicateT> + inline bool ends_with( + const Range1T& Input, + const Range2T& Test, + PredicateT Comp) + { + iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range1T>::type> lit_input(::boost::as_literal(Input)); + iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range2T>::type> lit_test(::boost::as_literal(Test)); + + typedef BOOST_STRING_TYPENAME + range_const_iterator<Range1T>::type Iterator1T; + typedef BOOST_STRING_TYPENAME boost::detail:: + iterator_traits<Iterator1T>::iterator_category category; + + return detail:: + ends_with_iter_select( + ::boost::begin(lit_input), + ::boost::end(lit_input), + ::boost::begin(lit_test), + ::boost::end(lit_test), + Comp, + category()); + } + + + //! 'Ends with' predicate + /*! + \overload + */ + template<typename Range1T, typename Range2T> + inline bool ends_with( + const Range1T& Input, + const Range2T& Test) + { + return ::boost::algorithm::ends_with(Input, Test, is_equal()); + } + + //! 'Ends with' predicate ( case insensitive ) + /*! + This predicate holds when the test container is a suffix of the Input. + In other words, if the input ends with the test. + Elements are compared case insensitively. + + \param Input An input sequence + \param Test A test sequence + \param Loc A locale used for case insensitive comparison + \return The result of the test + + \note This function provides the strong exception-safety guarantee + */ + template<typename Range1T, typename Range2T> + inline bool iends_with( + const Range1T& Input, + const Range2T& Test, + const std::locale& Loc=std::locale()) + { + return ::boost::algorithm::ends_with(Input, Test, is_iequal(Loc)); + } + +// contains predicate -----------------------------------------------// + + //! 'Contains' predicate + /*! + This predicate holds when the test container is contained in the Input. + When the optional predicate is specified, it is used for character-wise + comparison. + + \param Input An input sequence + \param Test A test sequence + \param Comp An element comparison predicate + \return The result of the test + + \note This function provides the strong exception-safety guarantee + */ + template<typename Range1T, typename Range2T, typename PredicateT> + inline bool contains( + const Range1T& Input, + const Range2T& Test, + PredicateT Comp) + { + iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range1T>::type> lit_input(::boost::as_literal(Input)); + iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range2T>::type> lit_test(::boost::as_literal(Test)); + + if (::boost::empty(lit_test)) + { + // Empty range is contained always + return true; + } + + // Use the temporary variable to make VACPP happy + bool bResult=(::boost::algorithm::first_finder(lit_test,Comp)(::boost::begin(lit_input), ::boost::end(lit_input))); + return bResult; + } + + //! 'Contains' predicate + /*! + \overload + */ + template<typename Range1T, typename Range2T> + inline bool contains( + const Range1T& Input, + const Range2T& Test) + { + return ::boost::algorithm::contains(Input, Test, is_equal()); + } + + //! 'Contains' predicate ( case insensitive ) + /*! + This predicate holds when the test container is contained in the Input. + Elements are compared case insensitively. + + \param Input An input sequence + \param Test A test sequence + \param Loc A locale used for case insensitive comparison + \return The result of the test + + \note This function provides the strong exception-safety guarantee + */ + template<typename Range1T, typename Range2T> + inline bool icontains( + const Range1T& Input, + const Range2T& Test, + const std::locale& Loc=std::locale()) + { + return ::boost::algorithm::contains(Input, Test, is_iequal(Loc)); + } + +// equals predicate -----------------------------------------------// + + //! 'Equals' predicate + /*! + This predicate holds when the test container is equal to the + input container i.e. all elements in both containers are same. + When the optional predicate is specified, it is used for character-wise + comparison. + + \param Input An input sequence + \param Test A test sequence + \param Comp An element comparison predicate + \return The result of the test + + \note This is a two-way version of \c std::equal algorithm + + \note This function provides the strong exception-safety guarantee + */ + template<typename Range1T, typename Range2T, typename PredicateT> + inline bool equals( + const Range1T& Input, + const Range2T& Test, + PredicateT Comp) + { + iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range1T>::type> lit_input(::boost::as_literal(Input)); + iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range2T>::type> lit_test(::boost::as_literal(Test)); + + typedef BOOST_STRING_TYPENAME + range_const_iterator<Range1T>::type Iterator1T; + typedef BOOST_STRING_TYPENAME + range_const_iterator<Range2T>::type Iterator2T; + + Iterator1T InputEnd=::boost::end(lit_input); + Iterator2T TestEnd=::boost::end(lit_test); + + Iterator1T it=::boost::begin(lit_input); + Iterator2T pit=::boost::begin(lit_test); + for(; + it!=InputEnd && pit!=TestEnd; + ++it,++pit) + { + if( !(Comp(*it,*pit)) ) + return false; + } + + return (pit==TestEnd) && (it==InputEnd); + } + + //! 'Equals' predicate + /*! + \overload + */ + template<typename Range1T, typename Range2T> + inline bool equals( + const Range1T& Input, + const Range2T& Test) + { + return ::boost::algorithm::equals(Input, Test, is_equal()); + } + + //! 'Equals' predicate ( case insensitive ) + /*! + This predicate holds when the test container is equal to the + input container i.e. all elements in both containers are same. + Elements are compared case insensitively. + + \param Input An input sequence + \param Test A test sequence + \param Loc A locale used for case insensitive comparison + \return The result of the test + + \note This is a two-way version of \c std::equal algorithm + + \note This function provides the strong exception-safety guarantee + */ + template<typename Range1T, typename Range2T> + inline bool iequals( + const Range1T& Input, + const Range2T& Test, + const std::locale& Loc=std::locale()) + { + return ::boost::algorithm::equals(Input, Test, is_iequal(Loc)); + } + +// lexicographical_compare predicate -----------------------------// + + //! Lexicographical compare predicate + /*! + This predicate is an overload of std::lexicographical_compare + for range arguments + + It check whether the first argument is lexicographically less + then the second one. + + If the optional predicate is specified, it is used for character-wise + comparison + + \param Arg1 First argument + \param Arg2 Second argument + \param Pred Comparison predicate + \return The result of the test + + \note This function provides the strong exception-safety guarantee + */ + template<typename Range1T, typename Range2T, typename PredicateT> + inline bool lexicographical_compare( + const Range1T& Arg1, + const Range2T& Arg2, + PredicateT Pred) + { + iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range1T>::type> lit_arg1(::boost::as_literal(Arg1)); + iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range2T>::type> lit_arg2(::boost::as_literal(Arg2)); + + return std::lexicographical_compare( + ::boost::begin(lit_arg1), + ::boost::end(lit_arg1), + ::boost::begin(lit_arg2), + ::boost::end(lit_arg2), + Pred); + } + + //! Lexicographical compare predicate + /*! + \overload + */ + template<typename Range1T, typename Range2T> + inline bool lexicographical_compare( + const Range1T& Arg1, + const Range2T& Arg2) + { + return ::boost::algorithm::lexicographical_compare(Arg1, Arg2, is_less()); + } + + //! Lexicographical compare predicate (case-insensitive) + /*! + This predicate is an overload of std::lexicographical_compare + for range arguments. + It check whether the first argument is lexicographically less + then the second one. + Elements are compared case insensitively + + + \param Arg1 First argument + \param Arg2 Second argument + \param Loc A locale used for case insensitive comparison + \return The result of the test + + \note This function provides the strong exception-safety guarantee + */ + template<typename Range1T, typename Range2T> + inline bool ilexicographical_compare( + const Range1T& Arg1, + const Range2T& Arg2, + const std::locale& Loc=std::locale()) + { + return ::boost::algorithm::lexicographical_compare(Arg1, Arg2, is_iless(Loc)); + } + + +// all predicate -----------------------------------------------// + + //! 'All' predicate + /*! + This predicate holds it all its elements satisfy a given + condition, represented by the predicate. + + \param Input An input sequence + \param Pred A predicate + \return The result of the test + + \note This function provides the strong exception-safety guarantee + */ + template<typename RangeT, typename PredicateT> + inline bool all( + const RangeT& Input, + PredicateT Pred) + { + iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_input(::boost::as_literal(Input)); + + typedef BOOST_STRING_TYPENAME + range_const_iterator<RangeT>::type Iterator1T; + + Iterator1T InputEnd=::boost::end(lit_input); + for( Iterator1T It=::boost::begin(lit_input); It!=InputEnd; ++It) + { + if (!Pred(*It)) + return false; + } + + return true; + } + + } // namespace algorithm + + // pull names to the boost namespace + using algorithm::starts_with; + using algorithm::istarts_with; + using algorithm::ends_with; + using algorithm::iends_with; + using algorithm::contains; + using algorithm::icontains; + using algorithm::equals; + using algorithm::iequals; + using algorithm::all; + using algorithm::lexicographical_compare; + using algorithm::ilexicographical_compare; + +} // namespace boost + + +#endif // BOOST_STRING_PREDICATE_HPP diff --git a/Utilities/BGL/boost/algorithm/string/predicate_facade.hpp b/Utilities/BGL/boost/algorithm/string/predicate_facade.hpp new file mode 100755 index 0000000000000000000000000000000000000000..c9d4881b41150da7689c870902e0e187fc6501be --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/predicate_facade.hpp @@ -0,0 +1,42 @@ +// Boost string_algo library predicate_facade.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_PREDICATE_FACADE_HPP +#define BOOST_STRING_PREDICATE_FACADE_HPP + +#include <boost/algorithm/string/config.hpp> + +/* + \file boost/algorith/string/predicate_facade.hpp + This file containes predicate_facade definition. This template class is used + to identify classification predicates, so they can be combined using + composition operators. +*/ + +namespace boost { + namespace algorithm { + +// predicate facade ------------------------------------------------------// + + //! Predicate facade + /*! + This class allows to recognize classification + predicates, so that they can be combined using + composition operators. + Every classification predicate must be derived from this class. + */ + template<typename Derived> + struct predicate_facade {}; + + } // namespace algorithm +} // namespace boost + + +#endif // BOOST_STRING_CLASSIFICATION_DETAIL_HPP diff --git a/Utilities/BGL/boost/algorithm/string/regex.hpp b/Utilities/BGL/boost/algorithm/string/regex.hpp new file mode 100755 index 0000000000000000000000000000000000000000..2af7872b79689c21fec2663cbf18687b51d385d9 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/regex.hpp @@ -0,0 +1,646 @@ +// Boost string_algo library regex.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_REGEX_HPP +#define BOOST_STRING_REGEX_HPP + +#include <boost/algorithm/string/config.hpp> +#include <boost/regex.hpp> + +#include <boost/range/iterator_range.hpp> +#include <boost/range/begin.hpp> +#include <boost/range/end.hpp> +#include <boost/range/iterator.hpp> +#include <boost/range/as_literal.hpp> + +#include <boost/algorithm/string/find_format.hpp> +#include <boost/algorithm/string/regex_find_format.hpp> +#include <boost/algorithm/string/formatter.hpp> +#include <boost/algorithm/string/iter_find.hpp> + +/*! \file + Defines regex variants of the algorithms. +*/ + +namespace boost { + namespace algorithm { + +// find_regex -----------------------------------------------// + + //! Find regex algorithm + /*! + Search for a substring matching the given regex in the input. + + \param Input A container which will be searched. + \param Rx A regular expression + \param Flags Regex options + \return + An \c iterator_range delimiting the match. + Returned iterator is either \c RangeT::iterator or + \c RangeT::const_iterator, depending on the constness of + the input parameter. + + \note This function provides the strong exception-safety guarantee + */ + template< + typename RangeT, + typename CharT, + typename RegexTraitsT> + inline iterator_range< + BOOST_STRING_TYPENAME range_iterator<RangeT>::type > + find_regex( + RangeT& Input, + const basic_regex<CharT, RegexTraitsT>& Rx, + match_flag_type Flags=match_default ) + { + iterator_range<BOOST_STRING_TYPENAME range_iterator<RangeT>::type> lit_input(::boost::as_literal(Input)); + + return ::boost::algorithm::regex_finder(Rx,Flags)( + ::boost::begin(lit_input), ::boost::end(lit_input) ); + } + +// replace_regex --------------------------------------------------------------------// + + //! Replace regex algorithm + /*! + Search for a substring matching given regex and format it with + the specified format. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param Rx A regular expression + \param Format Regex format definition + \param Flags Regex options + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename RangeT, + typename CharT, + typename RegexTraitsT, + typename FormatStringTraitsT, typename FormatStringAllocatorT > + inline OutputIteratorT replace_regex_copy( + OutputIteratorT Output, + const RangeT& Input, + const basic_regex<CharT, RegexTraitsT>& Rx, + const std::basic_string<CharT, FormatStringTraitsT, FormatStringAllocatorT>& Format, + match_flag_type Flags=match_default | format_default ) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::regex_finder( Rx, Flags ), + ::boost::algorithm::regex_formatter( Format, Flags ) ); + } + + //! Replace regex algorithm + /*! + \overload + */ + template< + typename SequenceT, + typename CharT, + typename RegexTraitsT, + typename FormatStringTraitsT, typename FormatStringAllocatorT > + inline SequenceT replace_regex_copy( + const SequenceT& Input, + const basic_regex<CharT, RegexTraitsT>& Rx, + const std::basic_string<CharT, FormatStringTraitsT, FormatStringAllocatorT>& Format, + match_flag_type Flags=match_default | format_default ) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::regex_finder( Rx, Flags ), + ::boost::algorithm::regex_formatter( Format, Flags ) ); + } + + //! Replace regex algorithm + /*! + Search for a substring matching given regex and format it with + the specified format. The input string is modified in-place. + + \param Input An input string + \param Rx A regular expression + \param Format Regex format definition + \param Flags Regex options + */ + template< + typename SequenceT, + typename CharT, + typename RegexTraitsT, + typename FormatStringTraitsT, typename FormatStringAllocatorT > + inline void replace_regex( + SequenceT& Input, + const basic_regex<CharT, RegexTraitsT>& Rx, + const std::basic_string<CharT, FormatStringTraitsT, FormatStringAllocatorT>& Format, + match_flag_type Flags=match_default | format_default ) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::regex_finder( Rx, Flags ), + ::boost::algorithm::regex_formatter( Format, Flags ) ); + } + +// replace_all_regex --------------------------------------------------------------------// + + //! Replace all regex algorithm + /*! + Format all substrings, matching given regex, with the specified format. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param Rx A regular expression + \param Format Regex format definition + \param Flags Regex options + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename RangeT, + typename CharT, + typename RegexTraitsT, + typename FormatStringTraitsT, typename FormatStringAllocatorT > + inline OutputIteratorT replace_all_regex_copy( + OutputIteratorT Output, + const RangeT& Input, + const basic_regex<CharT, RegexTraitsT>& Rx, + const std::basic_string<CharT, FormatStringTraitsT, FormatStringAllocatorT>& Format, + match_flag_type Flags=match_default | format_default ) + { + return ::boost::algorithm::find_format_all_copy( + Output, + Input, + ::boost::algorithm::regex_finder( Rx, Flags ), + ::boost::algorithm::regex_formatter( Format, Flags ) ); + } + + //! Replace all regex algorithm + /*! + \overload + */ + template< + typename SequenceT, + typename CharT, + typename RegexTraitsT, + typename FormatStringTraitsT, typename FormatStringAllocatorT > + inline SequenceT replace_all_regex_copy( + const SequenceT& Input, + const basic_regex<CharT, RegexTraitsT>& Rx, + const std::basic_string<CharT, FormatStringTraitsT, FormatStringAllocatorT>& Format, + match_flag_type Flags=match_default | format_default ) + { + return ::boost::algorithm::find_format_all_copy( + Input, + ::boost::algorithm::regex_finder( Rx, Flags ), + ::boost::algorithm::regex_formatter( Format, Flags ) ); + } + + //! Replace all regex algorithm + /*! + Format all substrings, matching given regex, with the specified format. + The input string is modified in-place. + + \param Input An input string + \param Rx A regular expression + \param Format Regex format definition + \param Flags Regex options + */ + template< + typename SequenceT, + typename CharT, + typename RegexTraitsT, + typename FormatStringTraitsT, typename FormatStringAllocatorT > + inline void replace_all_regex( + SequenceT& Input, + const basic_regex<CharT, RegexTraitsT>& Rx, + const std::basic_string<CharT, FormatStringTraitsT, FormatStringAllocatorT>& Format, + match_flag_type Flags=match_default | format_default ) + { + ::boost::algorithm::find_format_all( + Input, + ::boost::algorithm::regex_finder( Rx, Flags ), + ::boost::algorithm::regex_formatter( Format, Flags ) ); + } + +// erase_regex --------------------------------------------------------------------// + + //! Erase regex algorithm + /*! + Remove a substring matching given regex from the input. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param Rx A regular expression + \param Flags Regex options + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename RangeT, + typename CharT, + typename RegexTraitsT > + inline OutputIteratorT erase_regex_copy( + OutputIteratorT Output, + const RangeT& Input, + const basic_regex<CharT, RegexTraitsT>& Rx, + match_flag_type Flags=match_default ) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::regex_finder( Rx, Flags ), + ::boost::algorithm::empty_formatter( Input ) ); + } + + //! Erase regex algorithm + /*! + \overload + */ + template< + typename SequenceT, + typename CharT, + typename RegexTraitsT > + inline SequenceT erase_regex_copy( + const SequenceT& Input, + const basic_regex<CharT, RegexTraitsT>& Rx, + match_flag_type Flags=match_default ) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::regex_finder( Rx, Flags ), + ::boost::algorithm::empty_formatter( Input ) ); + } + + //! Erase regex algorithm + /*! + Remove a substring matching given regex from the input. + The input string is modified in-place. + + \param Input An input string + \param Rx A regular expression + \param Flags Regex options + */ + template< + typename SequenceT, + typename CharT, + typename RegexTraitsT > + inline void erase_regex( + SequenceT& Input, + const basic_regex<CharT, RegexTraitsT>& Rx, + match_flag_type Flags=match_default ) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::regex_finder( Rx, Flags ), + ::boost::algorithm::empty_formatter( Input ) ); + } + +// erase_all_regex --------------------------------------------------------------------// + + //! Erase all regex algorithm + /*! + Erase all substrings, matching given regex, from the input. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param Rx A regular expression + \param Flags Regex options + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename RangeT, + typename CharT, + typename RegexTraitsT > + inline OutputIteratorT erase_all_regex_copy( + OutputIteratorT Output, + const RangeT& Input, + const basic_regex<CharT, RegexTraitsT>& Rx, + match_flag_type Flags=match_default ) + { + return ::boost::algorithm::find_format_all_copy( + Output, + Input, + ::boost::algorithm::regex_finder( Rx, Flags ), + ::boost::algorithm::empty_formatter( Input ) ); + } + + //! Erase all regex algorithm + /*! + \overload + */ + template< + typename SequenceT, + typename CharT, + typename RegexTraitsT > + inline SequenceT erase_all_regex_copy( + const SequenceT& Input, + const basic_regex<CharT, RegexTraitsT>& Rx, + match_flag_type Flags=match_default ) + { + return ::boost::algorithm::find_format_all_copy( + Input, + ::boost::algorithm::regex_finder( Rx, Flags ), + ::boost::algorithm::empty_formatter( Input ) ); + } + + //! Erase all regex algorithm + /*! + Erase all substrings, matching given regex, from the input. + The input string is modified in-place. + + \param Input An input string + \param Rx A regular expression + \param Flags Regex options + */ + template< + typename SequenceT, + typename CharT, + typename RegexTraitsT> + inline void erase_all_regex( + SequenceT& Input, + const basic_regex<CharT, RegexTraitsT>& Rx, + match_flag_type Flags=match_default ) + { + ::boost::algorithm::find_format_all( + Input, + ::boost::algorithm::regex_finder( Rx, Flags ), + ::boost::algorithm::empty_formatter( Input ) ); + } + +// find_all_regex ------------------------------------------------------------------// + + //! Find all regex algorithm + /*! + This algorithm finds all substrings matching the give regex + in the input. + + Each part is copied and added as a new element to the output container. + Thus the result container must be able to hold copies + of the matches (in a compatible structure like std::string) or + a reference to it (e.g. using the iterator range class). + Examples of such a container are \c std::vector<std::string> + or \c std::list<boost::iterator_range<std::string::iterator>> + + \param Result A container that can hold copies of references to the substrings. + \param Input A container which will be searched. + \param Rx A regular expression + \param Flags Regex options + \return A reference to the result + + \note Prior content of the result will be overwritten. + + \note This function provides the strong exception-safety guarantee + */ + template< + typename SequenceSequenceT, + typename RangeT, + typename CharT, + typename RegexTraitsT > + inline SequenceSequenceT& find_all_regex( + SequenceSequenceT& Result, + const RangeT& Input, + const basic_regex<CharT, RegexTraitsT>& Rx, + match_flag_type Flags=match_default ) + { + return ::boost::algorithm::iter_find( + Result, + Input, + ::boost::algorithm::regex_finder(Rx,Flags) ); + } + +// split_regex ------------------------------------------------------------------// + + //! Split regex algorithm + /*! + Tokenize expression. This function is equivalent to C strtok. Input + sequence is split into tokens, separated by separators. Separator + is an every match of the given regex. + Each part is copied and added as a new element to the output container. + Thus the result container must be able to hold copies + of the matches (in a compatible structure like std::string) or + a reference to it (e.g. using the iterator range class). + Examples of such a container are \c std::vector<std::string> + or \c std::list<boost::iterator_range<std::string::iterator>> + + \param Result A container that can hold copies of references to the substrings. + \param Input A container which will be searched. + \param Rx A regular expression + \param Flags Regex options + \return A reference to the result + + \note Prior content of the result will be overwritten. + + \note This function provides the strong exception-safety guarantee + */ + template< + typename SequenceSequenceT, + typename RangeT, + typename CharT, + typename RegexTraitsT > + inline SequenceSequenceT& split_regex( + SequenceSequenceT& Result, + const RangeT& Input, + const basic_regex<CharT, RegexTraitsT>& Rx, + match_flag_type Flags=match_default ) + { + return ::boost::algorithm::iter_split( + Result, + Input, + ::boost::algorithm::regex_finder(Rx,Flags) ); + } + +// join_if ------------------------------------------------------------------// + +#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING + + //! Conditional join algorithm + /*! + This algorithm joins all strings in a 'list' into one long string. + Segments are concatenated by given separator. Only segments that + match the given regular expression will be added to the result + + This is a specialization of join_if algorithm. + + \param Input A container that holds the input strings. It must be a container-of-containers. + \param Separator A string that will separate the joined segments. + \param Rx A regular expression + \param Flags Regex options + \return Concatenated string. + + \note This function provides the strong exception-safety guarantee + */ + template< + typename SequenceSequenceT, + typename Range1T, + typename CharT, + typename RegexTraitsT > + inline typename range_value<SequenceSequenceT>::type + join_if( + const SequenceSequenceT& Input, + const Range1T& Separator, + const basic_regex<CharT, RegexTraitsT>& Rx, + match_flag_type Flags=match_default ) + { + // Define working types + typedef typename range_value<SequenceSequenceT>::type ResultT; + typedef typename range_const_iterator<SequenceSequenceT>::type InputIteratorT; + + // Parse input + InputIteratorT itBegin=::boost::begin(Input); + InputIteratorT itEnd=::boost::end(Input); + + // Construct container to hold the result + ResultT Result; + + + // Roll to the first element that will be added + while( + itBegin!=itEnd && + !::boost::regex_match(::boost::begin(*itBegin), ::boost::end(*itBegin), Rx, Flags)) ++itBegin; + + // Add this element + if(itBegin!=itEnd) + { + detail::insert(Result, ::boost::end(Result), *itBegin); + ++itBegin; + } + + for(;itBegin!=itEnd; ++itBegin) + { + if(::boost::regex_match(::boost::begin(*itBegin), ::boost::end(*itBegin), Rx, Flags)) + { + // Add separator + detail::insert(Result, ::boost::end(Result), ::boost::as_literal(Separator)); + // Add element + detail::insert(Result, ::boost::end(Result), *itBegin); + } + } + + return Result; + } + +#else // BOOST_NO_FUNCTION_TEMPLATE_ORDERING + + //! Conditional join algorithm + /*! + This algorithm joins all strings in a 'list' into one long string. + Segments are concatenated by given separator. Only segments that + match the given regular expression will be added to the result + + This is a specialization of join_if algorithm. + + \param Input A container that holds the input strings. It must be a container-of-containers. + \param Separator A string that will separate the joined segments. + \param Rx A regular expression + \param Flags Regex options + \return Concatenated string. + + \note This function provides the strong exception-safety guarantee + */ + template< + typename SequenceSequenceT, + typename Range1T, + typename CharT, + typename RegexTraitsT > + inline typename range_value<SequenceSequenceT>::type + join_if_regex( + const SequenceSequenceT& Input, + const Range1T& Separator, + const basic_regex<CharT, RegexTraitsT>& Rx, + match_flag_type Flags=match_default ) + { + // Define working types + typedef typename range_value<SequenceSequenceT>::type ResultT; + typedef typename range_const_iterator<SequenceSequenceT>::type InputIteratorT; + + // Parse input + InputIteratorT itBegin=::boost::begin(Input); + InputIteratorT itEnd=::boost::end(Input); + + // Construct container to hold the result + ResultT Result; + + + // Roll to the first element that will be added + while( + itBegin!=itEnd && + !::boost::regex_match(::boost::begin(*itBegin), ::boost::end(*itBegin), Rx, Flags)) ++itBegin; + + // Add this element + if(itBegin!=itEnd) + { + detail::insert(Result, ::boost::end(Result), *itBegin); + ++itBegin; + } + + for(;itBegin!=itEnd; ++itBegin) + { + if(::boost::regex_match(::boost::begin(*itBegin), ::boost::end(*itBegin), Rx, Flags)) + { + // Add separator + detail::insert(Result, ::boost::end(Result), ::boost::as_literal(Separator)); + // Add element + detail::insert(Result, ::boost::end(Result), *itBegin); + } + } + + return Result; + } + + +#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING + + } // namespace algorithm + + // pull names into the boost namespace + using algorithm::find_regex; + using algorithm::replace_regex; + using algorithm::replace_regex_copy; + using algorithm::replace_all_regex; + using algorithm::replace_all_regex_copy; + using algorithm::erase_regex; + using algorithm::erase_regex_copy; + using algorithm::erase_all_regex; + using algorithm::erase_all_regex_copy; + using algorithm::find_all_regex; + using algorithm::split_regex; + +#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING + using algorithm::join_if; +#else // BOOST_NO_FUNCTION_TEMPLATE_ORDERING + using algorithm::join_if_regex; +#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING + +} // namespace boost + + +#endif // BOOST_STRING_REGEX_HPP diff --git a/Utilities/BGL/boost/algorithm/string/regex_find_format.hpp b/Utilities/BGL/boost/algorithm/string/regex_find_format.hpp new file mode 100755 index 0000000000000000000000000000000000000000..9f861acdf5796f60856fb4cbbce48b6e48895583 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/regex_find_format.hpp @@ -0,0 +1,90 @@ +// Boost string_algo library regex_find_format.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_REGEX_FIND_FORMAT_HPP +#define BOOST_STRING_REGEX_FIND_FORMAT_HPP + +#include <boost/algorithm/string/config.hpp> +#include <boost/regex.hpp> +#include <boost/algorithm/string/detail/finder_regex.hpp> +#include <boost/algorithm/string/detail/formatter_regex.hpp> + +/*! \file + Defines the \c regex_finder and \c regex_formatter generators. These two functors + are designed to work together. \c regex_formatter uses additional information + about a match contained in the regex_finder search result. +*/ + +namespace boost { + namespace algorithm { + +// regex_finder -----------------------------------------------// + + //! "Regex" finder + /*! + Construct the \c regex_finder. Finder uses the regex engine to search + for a match. + Result is given in \c regex_search_result. This is an extension + of the iterator_range. In addition it containes match results + from the \c regex_search algorithm. + + \param Rx A regular expression + \param MatchFlags Regex search options + \return An instance of the \c regex_finder object + */ + template< + typename CharT, + typename RegexTraitsT> + inline detail::find_regexF< basic_regex<CharT, RegexTraitsT> > + regex_finder( + const basic_regex<CharT, RegexTraitsT>& Rx, + match_flag_type MatchFlags=match_default ) + { + return detail:: + find_regexF< + basic_regex<CharT, RegexTraitsT> >( Rx, MatchFlags ); + } + +// regex_formater ---------------------------------------------// + + //! Regex formatter + /*! + Construct the \c regex_formatter. Regex formatter uses the regex engine to + format a match found by the \c regex_finder. + This formatted it designed to closely cooperate with \c regex_finder. + + \param Format Regex format definition + \param Flags Format flags + \return An instance of the \c regex_formatter functor + */ + template< + typename CharT, + typename TraitsT, typename AllocT > + inline detail::regex_formatF< std::basic_string< CharT, TraitsT, AllocT > > + regex_formatter( + const std::basic_string<CharT, TraitsT, AllocT>& Format, + match_flag_type Flags=format_default ) + { + return + detail::regex_formatF< std::basic_string<CharT, TraitsT, AllocT> >( + Format, + Flags ); + } + + } // namespace algorithm + + // pull the names to the boost namespace + using algorithm::regex_finder; + using algorithm::regex_formatter; + +} // namespace boost + + +#endif // BOOST_STRING_REGEX_FIND_FORMAT_HPP diff --git a/Utilities/BGL/boost/algorithm/string/replace.hpp b/Utilities/BGL/boost/algorithm/string/replace.hpp new file mode 100755 index 0000000000000000000000000000000000000000..71a73f3813262faa46e71b69289bc50d36d2087c --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/replace.hpp @@ -0,0 +1,928 @@ +// Boost string_algo library replace.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2006. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_REPLACE_HPP +#define BOOST_STRING_REPLACE_HPP + +#include <boost/algorithm/string/config.hpp> + +#include <boost/range/iterator_range.hpp> +#include <boost/range/begin.hpp> +#include <boost/range/end.hpp> +#include <boost/range/iterator.hpp> +#include <boost/range/const_iterator.hpp> + +#include <boost/algorithm/string/find_format.hpp> +#include <boost/algorithm/string/finder.hpp> +#include <boost/algorithm/string/formatter.hpp> +#include <boost/algorithm/string/compare.hpp> + +/*! \file + Defines various replace algorithms. Each algorithm replaces + part(s) of the input according to set of searching and replace criteria. +*/ + +namespace boost { + namespace algorithm { + +// replace_range --------------------------------------------------------------------// + + //! Replace range algorithm + /*! + Replace the given range in the input string. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param SearchRange A range in the input to be substituted + \param Format A substitute string + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename Range1T, + typename Range2T> + inline OutputIteratorT replace_range_copy( + OutputIteratorT Output, + const Range1T& Input, + const iterator_range< + BOOST_STRING_TYPENAME + range_const_iterator<Range1T>::type>& SearchRange, + const Range2T& Format) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::range_finder(SearchRange), + ::boost::algorithm::const_formatter(Format)); + } + + //! Replace range algorithm + /*! + \overload + */ + template<typename SequenceT, typename RangeT> + inline SequenceT replace_range_copy( + const SequenceT& Input, + const iterator_range< + BOOST_STRING_TYPENAME + range_const_iterator<SequenceT>::type>& SearchRange, + const RangeT& Format) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::range_finder(SearchRange), + ::boost::algorithm::const_formatter(Format)); + } + + //! Replace range algorithm + /*! + Replace the given range in the input string. + The input sequence is modified in-place. + + \param Input An input string + \param SearchRange A range in the input to be substituted + \param Format A substitute string + */ + template<typename SequenceT, typename RangeT> + inline void replace_range( + SequenceT& Input, + const iterator_range< + BOOST_STRING_TYPENAME + range_iterator<SequenceT>::type>& SearchRange, + const RangeT& Format) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::range_finder(SearchRange), + ::boost::algorithm::const_formatter(Format)); + } + +// replace_first --------------------------------------------------------------------// + + //! Replace first algorithm + /*! + Replace the first match of the search substring in the input + with the format string. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param Search A substring to be searched for + \param Format A substitute string + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename Range1T, + typename Range2T, + typename Range3T> + inline OutputIteratorT replace_first_copy( + OutputIteratorT Output, + const Range1T& Input, + const Range2T& Search, + const Range3T& Format) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::first_finder(Search), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace first algorithm + /*! + \overload + */ + template<typename SequenceT, typename Range1T, typename Range2T> + inline SequenceT replace_first_copy( + const SequenceT& Input, + const Range1T& Search, + const Range2T& Format ) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::first_finder(Search), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace first algorithm + /*! + replace the first match of the search substring in the input + with the format string. The input sequence is modified in-place. + + \param Input An input string + \param Search A substring to be searched for + \param Format A substitute string + */ + template<typename SequenceT, typename Range1T, typename Range2T> + inline void replace_first( + SequenceT& Input, + const Range1T& Search, + const Range2T& Format ) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::first_finder(Search), + ::boost::algorithm::const_formatter(Format) ); + } + +// replace_first ( case insensitive ) ---------------------------------------------// + + //! Replace first algorithm ( case insensitive ) + /*! + Replace the first match of the search substring in the input + with the format string. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + Searching is case insensitive. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param Search A substring to be searched for + \param Format A substitute string + \param Loc A locale used for case insensitive comparison + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename Range1T, + typename Range2T, + typename Range3T> + inline OutputIteratorT ireplace_first_copy( + OutputIteratorT Output, + const Range1T& Input, + const Range2T& Search, + const Range3T& Format, + const std::locale& Loc=std::locale() ) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::first_finder(Search, is_iequal(Loc)), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace first algorithm ( case insensitive ) + /*! + \overload + */ + template<typename SequenceT, typename Range2T, typename Range1T> + inline SequenceT ireplace_first_copy( + const SequenceT& Input, + const Range2T& Search, + const Range1T& Format, + const std::locale& Loc=std::locale() ) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::first_finder(Search, is_iequal(Loc)), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace first algorithm ( case insensitive ) + /*! + Replace the first match of the search substring in the input + with the format string. Input sequence is modified in-place. + Searching is case insensitive. + + \param Input An input string + \param Search A substring to be searched for + \param Format A substitute string + \param Loc A locale used for case insensitive comparison + */ + template<typename SequenceT, typename Range1T, typename Range2T> + inline void ireplace_first( + SequenceT& Input, + const Range1T& Search, + const Range2T& Format, + const std::locale& Loc=std::locale() ) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::first_finder(Search, is_iequal(Loc)), + ::boost::algorithm::const_formatter(Format) ); + } + +// replace_last --------------------------------------------------------------------// + + //! Replace last algorithm + /*! + Replace the last match of the search string in the input + with the format string. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param Search A substring to be searched for + \param Format A substitute string + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename Range1T, + typename Range2T, + typename Range3T> + inline OutputIteratorT replace_last_copy( + OutputIteratorT Output, + const Range1T& Input, + const Range2T& Search, + const Range3T& Format ) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::last_finder(Search), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace last algorithm + /*! + \overload + */ + template<typename SequenceT, typename Range1T, typename Range2T> + inline SequenceT replace_last_copy( + const SequenceT& Input, + const Range1T& Search, + const Range2T& Format ) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::last_finder(Search), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace last algorithm + /*! + Replace the last match of the search string in the input + with the format string. Input sequence is modified in-place. + + \param Input An input string + \param Search A substring to be searched for + \param Format A substitute string + */ + template<typename SequenceT, typename Range1T, typename Range2T> + inline void replace_last( + SequenceT& Input, + const Range1T& Search, + const Range2T& Format ) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::last_finder(Search), + ::boost::algorithm::const_formatter(Format) ); + } + +// replace_last ( case insensitive ) -----------------------------------------------// + + //! Replace last algorithm ( case insensitive ) + /*! + Replace the last match of the search string in the input + with the format string. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + Searching is case insensitive. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param Search A substring to be searched for + \param Format A substitute string + \param Loc A locale used for case insensitive comparison + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename Range1T, + typename Range2T, + typename Range3T> + inline OutputIteratorT ireplace_last_copy( + OutputIteratorT Output, + const Range1T& Input, + const Range2T& Search, + const Range3T& Format, + const std::locale& Loc=std::locale() ) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::last_finder(Search, is_iequal(Loc)), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace last algorithm ( case insensitive ) + /*! + \overload + */ + template<typename SequenceT, typename Range1T, typename Range2T> + inline SequenceT ireplace_last_copy( + const SequenceT& Input, + const Range1T& Search, + const Range2T& Format, + const std::locale& Loc=std::locale() ) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::last_finder(Search, is_iequal(Loc)), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace last algorithm ( case insensitive ) + /*! + Replace the last match of the search string in the input + with the format string.The input sequence is modified in-place. + Searching is case insensitive. + + \param Input An input string + \param Search A substring to be searched for + \param Format A substitute string + \param Loc A locale used for case insensitive comparison + \return A reference to the modified input + */ + template<typename SequenceT, typename Range1T, typename Range2T> + inline void ireplace_last( + SequenceT& Input, + const Range1T& Search, + const Range2T& Format, + const std::locale& Loc=std::locale() ) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::last_finder(Search, is_iequal(Loc)), + ::boost::algorithm::const_formatter(Format) ); + } + +// replace_nth --------------------------------------------------------------------// + + //! Replace nth algorithm + /*! + Replace an Nth (zero-indexed) match of the search string in the input + with the format string. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param Search A substring to be searched for + \param Nth An index of the match to be replaced. The index is 0-based. + For negative N, matches are counted from the end of string. + \param Format A substitute string + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename Range1T, + typename Range2T, + typename Range3T> + inline OutputIteratorT replace_nth_copy( + OutputIteratorT Output, + const Range1T& Input, + const Range2T& Search, + int Nth, + const Range3T& Format ) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::nth_finder(Search, Nth), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace nth algorithm + /*! + \overload + */ + template<typename SequenceT, typename Range1T, typename Range2T> + inline SequenceT replace_nth_copy( + const SequenceT& Input, + const Range1T& Search, + int Nth, + const Range2T& Format ) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::nth_finder(Search, Nth), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace nth algorithm + /*! + Replace an Nth (zero-indexed) match of the search string in the input + with the format string. Input sequence is modified in-place. + + \param Input An input string + \param Search A substring to be searched for + \param Nth An index of the match to be replaced. The index is 0-based. + For negative N, matches are counted from the end of string. + \param Format A substitute string + */ + template<typename SequenceT, typename Range1T, typename Range2T> + inline void replace_nth( + SequenceT& Input, + const Range1T& Search, + int Nth, + const Range2T& Format ) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::nth_finder(Search, Nth), + ::boost::algorithm::const_formatter(Format) ); + } + +// replace_nth ( case insensitive ) -----------------------------------------------// + + //! Replace nth algorithm ( case insensitive ) + /*! + Replace an Nth (zero-indexed) match of the search string in the input + with the format string. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + Searching is case insensitive. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param Search A substring to be searched for + \param Nth An index of the match to be replaced. The index is 0-based. + For negative N, matches are counted from the end of string. + \param Format A substitute string + \param Loc A locale used for case insensitive comparison + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename Range1T, + typename Range2T, + typename Range3T> + inline OutputIteratorT ireplace_nth_copy( + OutputIteratorT Output, + const Range1T& Input, + const Range2T& Search, + int Nth, + const Range3T& Format, + const std::locale& Loc=std::locale() ) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::nth_finder(Search, Nth, is_iequal(Loc) ), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace nth algorithm ( case insensitive ) + /*! + \overload + */ + template<typename SequenceT, typename Range1T, typename Range2T> + inline SequenceT ireplace_nth_copy( + const SequenceT& Input, + const Range1T& Search, + int Nth, + const Range2T& Format, + const std::locale& Loc=std::locale() ) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::nth_finder(Search, Nth, is_iequal(Loc)), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace nth algorithm ( case insensitive ) + /*! + Replace an Nth (zero-indexed) match of the search string in the input + with the format string. Input sequence is modified in-place. + Searching is case insensitive. + + \param Input An input string + \param Search A substring to be searched for + \param Nth An index of the match to be replaced. The index is 0-based. + For negative N, matches are counted from the end of string. + \param Format A substitute string + \param Loc A locale used for case insensitive comparison + */ + template<typename SequenceT, typename Range1T, typename Range2T> + inline void ireplace_nth( + SequenceT& Input, + const Range1T& Search, + int Nth, + const Range2T& Format, + const std::locale& Loc=std::locale() ) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::nth_finder(Search, Nth, is_iequal(Loc)), + ::boost::algorithm::const_formatter(Format) ); + } + +// replace_all --------------------------------------------------------------------// + + //! Replace all algorithm + /*! + Replace all occurrences of the search string in the input + with the format string. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param Search A substring to be searched for + \param Format A substitute string + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename Range1T, + typename Range2T, + typename Range3T> + inline OutputIteratorT replace_all_copy( + OutputIteratorT Output, + const Range1T& Input, + const Range2T& Search, + const Range3T& Format ) + { + return ::boost::algorithm::find_format_all_copy( + Output, + Input, + ::boost::algorithm::first_finder(Search), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace all algorithm + /*! + \overload + */ + template<typename SequenceT, typename Range1T, typename Range2T> + inline SequenceT replace_all_copy( + const SequenceT& Input, + const Range1T& Search, + const Range2T& Format ) + { + return ::boost::algorithm::find_format_all_copy( + Input, + ::boost::algorithm::first_finder(Search), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace all algorithm + /*! + Replace all occurrences of the search string in the input + with the format string. The input sequence is modified in-place. + + \param Input An input string + \param Search A substring to be searched for + \param Format A substitute string + \return A reference to the modified input + */ + template<typename SequenceT, typename Range1T, typename Range2T> + inline void replace_all( + SequenceT& Input, + const Range1T& Search, + const Range2T& Format ) + { + ::boost::algorithm::find_format_all( + Input, + ::boost::algorithm::first_finder(Search), + ::boost::algorithm::const_formatter(Format) ); + } + +// replace_all ( case insensitive ) -----------------------------------------------// + + //! Replace all algorithm ( case insensitive ) + /*! + Replace all occurrences of the search string in the input + with the format string. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + Searching is case insensitive. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param Search A substring to be searched for + \param Format A substitute string + \param Loc A locale used for case insensitive comparison + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename Range1T, + typename Range2T, + typename Range3T> + inline OutputIteratorT ireplace_all_copy( + OutputIteratorT Output, + const Range1T& Input, + const Range2T& Search, + const Range3T& Format, + const std::locale& Loc=std::locale() ) + { + return ::boost::algorithm::find_format_all_copy( + Output, + Input, + ::boost::algorithm::first_finder(Search, is_iequal(Loc)), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace all algorithm ( case insensitive ) + /*! + \overload + */ + template<typename SequenceT, typename Range1T, typename Range2T> + inline SequenceT ireplace_all_copy( + const SequenceT& Input, + const Range1T& Search, + const Range2T& Format, + const std::locale& Loc=std::locale() ) + { + return ::boost::algorithm::find_format_all_copy( + Input, + ::boost::algorithm::first_finder(Search, is_iequal(Loc)), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace all algorithm ( case insensitive ) + /*! + Replace all occurrences of the search string in the input + with the format string.The input sequence is modified in-place. + Searching is case insensitive. + + \param Input An input string + \param Search A substring to be searched for + \param Format A substitute string + \param Loc A locale used for case insensitive comparison + */ + template<typename SequenceT, typename Range1T, typename Range2T> + inline void ireplace_all( + SequenceT& Input, + const Range1T& Search, + const Range2T& Format, + const std::locale& Loc=std::locale() ) + { + ::boost::algorithm::find_format_all( + Input, + ::boost::algorithm::first_finder(Search, is_iequal(Loc)), + ::boost::algorithm::const_formatter(Format) ); + } + +// replace_head --------------------------------------------------------------------// + + //! Replace head algorithm + /*! + Replace the head of the input with the given format string. + The head is a prefix of a string of given size. + If the sequence is shorter then required, whole string if + considered to be the head. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param N Length of the head. + For N>=0, at most N characters are extracted. + For N<0, size(Input)-|N| characters are extracted. + \param Format A substitute string + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename Range1T, + typename Range2T> + inline OutputIteratorT replace_head_copy( + OutputIteratorT Output, + const Range1T& Input, + int N, + const Range2T& Format ) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::head_finder(N), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace head algorithm + /*! + \overload + */ + template<typename SequenceT, typename RangeT> + inline SequenceT replace_head_copy( + const SequenceT& Input, + int N, + const RangeT& Format ) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::head_finder(N), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace head algorithm + /*! + Replace the head of the input with the given format string. + The head is a prefix of a string of given size. + If the sequence is shorter then required, the whole string is + considered to be the head. The input sequence is modified in-place. + + \param Input An input string + \param N Length of the head. + For N>=0, at most N characters are extracted. + For N<0, size(Input)-|N| characters are extracted. + \param Format A substitute string + */ + template<typename SequenceT, typename RangeT> + inline void replace_head( + SequenceT& Input, + int N, + const RangeT& Format ) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::head_finder(N), + ::boost::algorithm::const_formatter(Format) ); + } + +// replace_tail --------------------------------------------------------------------// + + //! Replace tail algorithm + /*! + Replace the tail of the input with the given format string. + The tail is a suffix of a string of given size. + If the sequence is shorter then required, whole string is + considered to be the tail. + The result is a modified copy of the input. It is returned as a sequence + or copied to the output iterator. + + \param Output An output iterator to which the result will be copied + \param Input An input string + \param N Length of the tail. + For N>=0, at most N characters are extracted. + For N<0, size(Input)-|N| characters are extracted. + \param Format A substitute string + \return An output iterator pointing just after the last inserted character or + a modified copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template< + typename OutputIteratorT, + typename Range1T, + typename Range2T> + inline OutputIteratorT replace_tail_copy( + OutputIteratorT Output, + const Range1T& Input, + int N, + const Range2T& Format ) + { + return ::boost::algorithm::find_format_copy( + Output, + Input, + ::boost::algorithm::tail_finder(N), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace tail algorithm + /*! + \overload + */ + template<typename SequenceT, typename RangeT> + inline SequenceT replace_tail_copy( + const SequenceT& Input, + int N, + const RangeT& Format ) + { + return ::boost::algorithm::find_format_copy( + Input, + ::boost::algorithm::tail_finder(N), + ::boost::algorithm::const_formatter(Format) ); + } + + //! Replace tail algorithm + /*! + Replace the tail of the input with the given format sequence. + The tail is a suffix of a string of given size. + If the sequence is shorter then required, the whole string is + considered to be the tail. The input sequence is modified in-place. + + \param Input An input string + \param N Length of the tail. + For N>=0, at most N characters are extracted. + For N<0, size(Input)-|N| characters are extracted. + \param Format A substitute string + */ + template<typename SequenceT, typename RangeT> + inline void replace_tail( + SequenceT& Input, + int N, + const RangeT& Format ) + { + ::boost::algorithm::find_format( + Input, + ::boost::algorithm::tail_finder(N), + ::boost::algorithm::const_formatter(Format) ); + } + + } // namespace algorithm + + // pull names to the boost namespace + using algorithm::replace_range_copy; + using algorithm::replace_range; + using algorithm::replace_first_copy; + using algorithm::replace_first; + using algorithm::ireplace_first_copy; + using algorithm::ireplace_first; + using algorithm::replace_last_copy; + using algorithm::replace_last; + using algorithm::ireplace_last_copy; + using algorithm::ireplace_last; + using algorithm::replace_nth_copy; + using algorithm::replace_nth; + using algorithm::ireplace_nth_copy; + using algorithm::ireplace_nth; + using algorithm::replace_all_copy; + using algorithm::replace_all; + using algorithm::ireplace_all_copy; + using algorithm::ireplace_all; + using algorithm::replace_head_copy; + using algorithm::replace_head; + using algorithm::replace_tail_copy; + using algorithm::replace_tail; + +} // namespace boost + +#endif // BOOST_REPLACE_HPP diff --git a/Utilities/BGL/boost/algorithm/string/sequence_traits.hpp b/Utilities/BGL/boost/algorithm/string/sequence_traits.hpp new file mode 100755 index 0000000000000000000000000000000000000000..f9f4a9c74230f4baac6985fdbe8c7db065b90738 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/sequence_traits.hpp @@ -0,0 +1,193 @@ +// Boost string_algo library sequence_traits.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_SEQUENCE_TRAITS_HPP +#define BOOST_STRING_SEQUENCE_TRAITS_HPP + +#include <boost/config.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/algorithm/string/yes_no_type.hpp> + +/*! \file + Traits defined in this header are used by various algorithms to achieve + better performance for specific containers. + Traits provide fail-safe defaults. If a container supports some of these + features, it is possible to specialize the specific trait for this container. + For lacking compilers, it is possible of define an override for a specific tester + function. + + Due to a language restriction, it is not currently possible to define specializations for + stl containers without including the corresponding header. To decrease the overhead + needed by this inclusion, user can selectively include a specialization + header for a specific container. They are located in boost/algorithm/string/stl + directory. Alternatively she can include boost/algorithm/string/std_collection_traits.hpp + header which contains specializations for all stl containers. +*/ + +namespace boost { + namespace algorithm { + +// sequence traits -----------------------------------------------// + +#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + //! Native replace tester + /*! + Declare an override of this tester function with return + type boost::string_algo::yes_type for a sequence with this property. + + \return yes_type if the container has basic_string like native replace + method. + */ + no_type has_native_replace_tester(...); + + //! Stable iterators tester + /*! + Declare an override of this tester function with return + type boost::string_algo::yes_type for a sequence with this property. + + \return yes_type if the sequence's insert/replace/erase methods do not invalidate + existing iterators. + */ + no_type has_stable_iterators_tester(...); + + //! const time insert tester + /*! + Declare an override of this tester function with return + type boost::string_algo::yes_type for a sequence with this property. + + \return yes_type if the sequence's insert method is working in constant time + */ + no_type has_const_time_insert_tester(...); + + //! const time erase tester + /*! + Declare an override of this tester function with return + type boost::string_algo::yes_type for a sequence with this property. + + \return yes_type if the sequence's erase method is working in constant time + */ + no_type has_const_time_erase_tester(...); + +#endif //BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + //! Native replace trait + /*! + This trait specifies that the sequence has \c std::string like replace method + */ + template< typename T > + class has_native_replace + { + +#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + private: + static T* t; + public: + BOOST_STATIC_CONSTANT(bool, value=( + sizeof(has_native_replace_tester(t))==sizeof(yes_type) ) ); +#else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + public: +# if BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + enum { value = false }; +# else + BOOST_STATIC_CONSTANT(bool, value=false); +# endif // BOOST_WORKAROUND( __IBMCPP__, <= 600 ) +#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + + typedef mpl::bool_<has_native_replace<T>::value> type; + }; + + + //! Stable iterators trait + /*! + This trait specifies that the sequence has stable iterators. It means + that operations like insert/erase/replace do not invalidate iterators. + */ + template< typename T > + class has_stable_iterators + { +#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + private: + static T* t; + public: + BOOST_STATIC_CONSTANT(bool, value=( + sizeof(has_stable_iterators_tester(t))==sizeof(yes_type) ) ); +#else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + public: +# if BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + enum { value = false }; +# else + BOOST_STATIC_CONSTANT(bool, value=false); +# endif // BOOST_WORKAROUND( __IBMCPP__, <= 600 ) +#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + typedef mpl::bool_<has_stable_iterators<T>::value> type; + }; + + + //! Const time insert trait + /*! + This trait specifies that the sequence's insert method has + constant time complexity. + */ + template< typename T > + class has_const_time_insert + { +#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + private: + static T* t; + public: + BOOST_STATIC_CONSTANT(bool, value=( + sizeof(has_const_time_insert_tester(t))==sizeof(yes_type) ) ); +#else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + public: +# if BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + enum { value = false }; +# else + BOOST_STATIC_CONSTANT(bool, value=false); +# endif // BOOST_WORKAROUND( __IBMCPP__, <= 600 ) +#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + typedef mpl::bool_<has_const_time_insert<T>::value> type; + }; + + + //! Const time erase trait + /*! + This trait specifies that the sequence's erase method has + constant time complexity. + */ + template< typename T > + class has_const_time_erase + { +#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + private: + static T* t; + public: + BOOST_STATIC_CONSTANT(bool, value=( + sizeof(has_const_time_erase_tester(t))==sizeof(yes_type) ) ); +#else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + public: +# if BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + enum { value = false }; +# else + BOOST_STATIC_CONSTANT(bool, value=false); +# endif // BOOST_WORKAROUND( __IBMCPP__, <= 600 ) +#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + typedef mpl::bool_<has_const_time_erase<T>::value> type; + }; + + } // namespace algorithm +} // namespace boost + + +#endif // BOOST_STRING_SEQUENCE_TRAITS_HPP diff --git a/Utilities/BGL/boost/algorithm/string/split.hpp b/Utilities/BGL/boost/algorithm/string/split.hpp new file mode 100755 index 0000000000000000000000000000000000000000..21e86c7a03d4051c9ada0aa23bb4deebc489ac55 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/split.hpp @@ -0,0 +1,163 @@ +// Boost string_algo library split.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2006. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_SPLIT_HPP +#define BOOST_STRING_SPLIT_HPP + +#include <boost/algorithm/string/config.hpp> + +#include <boost/algorithm/string/iter_find.hpp> +#include <boost/algorithm/string/finder.hpp> +#include <boost/algorithm/string/compare.hpp> + +/*! \file + Defines basic split algorithms. + Split algorithms can be used to divide a string + into several parts according to given criteria. + + Each part is copied and added as a new element to the + output container. + Thus the result container must be able to hold copies + of the matches (in a compatible structure like std::string) or + a reference to it (e.g. using the iterator range class). + Examples of such a container are \c std::vector<std::string> + or \c std::list<boost::iterator_range<std::string::iterator>> +*/ + +namespace boost { + namespace algorithm { + +// find_all ------------------------------------------------------------// + + //! Find all algorithm + /*! + This algorithm finds all occurrences of the search string + in the input. + + Each part is copied and added as a new element to the + output container. + Thus the result container must be able to hold copies + of the matches (in a compatible structure like std::string) or + a reference to it (e.g. using the iterator range class). + Examples of such a container are \c std::vector<std::string> + or \c std::list<boost::iterator_range<std::string::iterator>> + + \param Result A container that can hold copies of references to the substrings + \param Input A container which will be searched. + \param Search A substring to be searched for. + \return A reference the result + + \note Prior content of the result will be overwritten. + + \note This function provides the strong exception-safety guarantee + */ + template< typename SequenceSequenceT, typename Range1T, typename Range2T > + inline SequenceSequenceT& find_all( + SequenceSequenceT& Result, + Range1T& Input, + const Range2T& Search) + { + return ::boost::algorithm::iter_find( + Result, + Input, + ::boost::algorithm::first_finder(Search) ); + } + + //! Find all algorithm ( case insensitive ) + /*! + This algorithm finds all occurrences of the search string + in the input. + Each part is copied and added as a new element to the + output container. Thus the result container must be able to hold copies + of the matches (in a compatible structure like std::string) or + a reference to it (e.g. using the iterator range class). + Examples of such a container are \c std::vector<std::string> + or \c std::list<boost::iterator_range<std::string::iterator>> + + Searching is case insensitive. + + \param Result A container that can hold copies of references to the substrings + \param Input A container which will be searched. + \param Search A substring to be searched for. + \param Loc A locale used for case insensitive comparison + \return A reference the result + + \note Prior content of the result will be overwritten. + + \note This function provides the strong exception-safety guarantee + */ + template< typename SequenceSequenceT, typename Range1T, typename Range2T > + inline SequenceSequenceT& ifind_all( + SequenceSequenceT& Result, + Range1T& Input, + const Range2T& Search, + const std::locale& Loc=std::locale() ) + { + return ::boost::algorithm::iter_find( + Result, + Input, + ::boost::algorithm::first_finder(Search, is_iequal(Loc) ) ); + } + + +// tokenize -------------------------------------------------------------// + + //! Split algorithm + /*! + Tokenize expression. This function is equivalent to C strtok. Input + sequence is split into tokens, separated by separators. Separators + are given by means of the predicate. + + Each part is copied and added as a new element to the + output container. + Thus the result container must be able to hold copies + of the matches (in a compatible structure like std::string) or + a reference to it (e.g. using the iterator range class). + Examples of such a container are \c std::vector<std::string> + or \c std::list<boost::iterator_range<std::string::iterator>> + + \param Result A container that can hold copies of references to the substrings + \param Input A container which will be searched. + \param Pred A predicate to identify separators. This predicate is + supposed to return true if a given element is a separator. + \param eCompress If eCompress argument is set to token_compress_on, adjacent + separators are merged together. Otherwise, every two separators + delimit a token. + \return A reference the result + + \note Prior content of the result will be overwritten. + + \note This function provides the strong exception-safety guarantee + */ + template< typename SequenceSequenceT, typename RangeT, typename PredicateT > + inline SequenceSequenceT& split( + SequenceSequenceT& Result, + RangeT& Input, + PredicateT Pred, + token_compress_mode_type eCompress=token_compress_off ) + { + return ::boost::algorithm::iter_split( + Result, + Input, + ::boost::algorithm::token_finder( Pred, eCompress ) ); + } + + } // namespace algorithm + + // pull names to the boost namespace + using algorithm::find_all; + using algorithm::ifind_all; + using algorithm::split; + +} // namespace boost + + +#endif // BOOST_STRING_SPLIT_HPP + diff --git a/Utilities/BGL/boost/algorithm/string/std/list_traits.hpp b/Utilities/BGL/boost/algorithm/string/std/list_traits.hpp new file mode 100755 index 0000000000000000000000000000000000000000..3f25f6374a1d3b20cc886375d32bd649c48dfcb3 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/std/list_traits.hpp @@ -0,0 +1,85 @@ +// Boost string_algo library list_traits.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_STD_LIST_TRAITS_HPP +#define BOOST_STRING_STD_LIST_TRAITS_HPP + +#include <boost/algorithm/string/yes_no_type.hpp> +#include <list> +#include <boost/algorithm/string/sequence_traits.hpp> + +namespace boost { + namespace algorithm { + +// std::list<> traits -----------------------------------------------// + +#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + // stable iterators tester + template<typename T, typename AllocT> + yes_type has_stable_iterators_tester( const ::std::list<T,AllocT>* ); + + // const time insert tester + template<typename T, typename AllocT> + yes_type has_const_time_insert_tester( const ::std::list<T,AllocT>* ); + + // const time erase tester + template<typename T, typename AllocT> + yes_type has_const_time_erase_tester( const ::std::list<T,AllocT>* ); + + +#else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + // stable iterators trait + template<typename T, typename AllocT> + class has_stable_iterators< ::std::list<T,AllocT> > + { + public: +#if BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + enum { value = true }; +#else + BOOST_STATIC_CONSTANT(bool, value=true); +#endif // BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + typedef mpl::bool_<has_stable_iterators<T>::value> type; + }; + + // const time insert trait + template<typename T, typename AllocT> + class has_const_time_insert< ::std::list<T,AllocT> > + { + public: +#if BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + enum { value = true }; +#else + BOOST_STATIC_CONSTANT(bool, value=true); +#endif // BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + typedef mpl::bool_<has_const_time_insert<T>::value> type; + }; + + // const time erase trait + template<typename T, typename AllocT> + class has_const_time_erase< ::std::list<T,AllocT> > + { + public: +#if BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + enum { value = true }; +#else + BOOST_STATIC_CONSTANT(bool, value=true); +#endif // BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + typedef mpl::bool_<has_const_time_erase<T>::value> type; + }; +#endif + + + } // namespace algorithm +} // namespace boost + + +#endif // BOOST_STRING_STD_LIST_TRAITS_HPP diff --git a/Utilities/BGL/boost/algorithm/string/std/rope_traits.hpp b/Utilities/BGL/boost/algorithm/string/std/rope_traits.hpp new file mode 100755 index 0000000000000000000000000000000000000000..e9ae03a94ce2f643606de1508aa7a1a75423e2a4 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/std/rope_traits.hpp @@ -0,0 +1,101 @@ +// Boost string_algo library string_traits.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_STD_ROPE_TRAITS_HPP +#define BOOST_STRING_STD_ROPE_TRAITS_HPP + +#include <boost/algorithm/string/yes_no_type.hpp> +#include <rope> +#include <boost/algorithm/string/sequence_traits.hpp> + +namespace boost { + namespace algorithm { + +// SGI's std::rope<> traits -----------------------------------------------// + +#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + // native replace tester + template<typename T, typename TraitsT, typename AllocT> + yes_type has_native_replace_tester( const std::rope<T, TraitsT, AllocT>* ); + + // stable iterators tester + template<typename T, typename TraitsT, typename AllocT> + yes_type has_stable_iterators_tester( const std::rope<T, TraitsT, AllocT>* ); + + // const time insert tester + template<typename T, typename TraitsT, typename AllocT> + yes_type has_const_time_insert_tester( const std::rope<T, TraitsT, AllocT>* ); + + // const time erase tester + template<typename T, typename TraitsT, typename AllocT> + yes_type has_const_time_erase_tester( const std::rope<T, TraitsT, AllocT>* ); + +#else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + // native replace trait + template<typename T, typename TraitsT, typename AllocT> + class has_native_replace< std::rope<T,TraitsT,AllocT> > + { + public: +#if BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + enum { value = true }; +#else + BOOST_STATIC_CONSTANT(bool, value=true); +#endif // BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + typedef mpl::bool_<value> type; + }; + + // stable iterators trait + template<typename T, typename TraitsT, typename AllocT> + class has_stable_iterators< std::rope<T,TraitsT,AllocT> > + { + public: +#if BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + enum { value = true }; +#else + BOOST_STATIC_CONSTANT(bool, value=true); +#endif // BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + typedef mpl::bool_<value> type; + }; + + // const time insert trait + template<typename T, typename TraitsT, typename AllocT> + class has_const_time_insert< std::rope<T,TraitsT,AllocT> > + { + public: +#if BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + enum { value = true }; +#else + BOOST_STATIC_CONSTANT(bool, value=true); +#endif // BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + typedef mpl::bool_<value> type; + }; + + // const time erase trait + template<typename T, typename TraitsT, typename AllocT> + class has_const_time_erase< std::rope<T,TraitsT,AllocT> > + { + public: +#if BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + enum { value = true }; +#else + BOOST_STATIC_CONSTANT(bool, value=true); +#endif // BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + typedef mpl::bool_<value> type; + }; +#endif + + + } // namespace algorithm +} // namespace boost + + +#endif // BOOST_STRING_ROPE_TRAITS_HPP diff --git a/Utilities/BGL/boost/algorithm/string/std/slist_traits.hpp b/Utilities/BGL/boost/algorithm/string/std/slist_traits.hpp new file mode 100755 index 0000000000000000000000000000000000000000..c3cfe64e6603afd36ec4695f0a4c42a53e4539e5 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/std/slist_traits.hpp @@ -0,0 +1,85 @@ +// Boost string_algo library slist_traits.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_STD_SLIST_TRAITS_HPP +#define BOOST_STRING_STD_SLIST_TRAITS_HPP + +#include <boost/algorithm/string/config.hpp> +#include <boost/algorithm/string/yes_no_type.hpp> +#include BOOST_SLIST_HEADER +#include <boost/algorithm/string/sequence_traits.hpp> + +namespace boost { + namespace algorithm { + +// SGI's std::slist<> traits -----------------------------------------------// + +#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + // stable iterators tester + template<typename T, typename AllocT> + yes_type has_stable_iterators_tester( const BOOST_STD_EXTENSION_NAMESPACE::slist<T,AllocT>* ); + + // const time insert tester + template<typename T, typename AllocT> + yes_type has_const_time_insert_tester( const BOOST_STD_EXTENSION_NAMESPACE::slist<T,AllocT>* ); + + // const time erase tester + template<typename T, typename AllocT> + yes_type has_const_time_erase_tester( const BOOST_STD_EXTENSION_NAMESPACE::slist<T,AllocT>* ); + +#else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + // stable iterators trait + template<typename T, typename AllocT> + class has_stable_iterators< BOOST_STD_EXTENSION_NAMESPACE::slist<T,AllocT> > + { + public: +#if BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + enum { value = true }; +#else + BOOST_STATIC_CONSTANT(bool, value=true); +#endif // BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + typedef mpl::bool_<has_stable_iterators<T>::value> type; + }; + + // const time insert trait + template<typename T, typename AllocT> + class has_const_time_insert< BOOST_STD_EXTENSION_NAMESPACE::slist<T,AllocT> > + { + public: +#if BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + enum { value = true }; +#else + BOOST_STATIC_CONSTANT(bool, value=true); +#endif // BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + typedef mpl::bool_<has_const_time_insert<T>::value> type; + }; + + // const time erase trait + template<typename T, typename AllocT> + class has_const_time_erase< BOOST_STD_EXTENSION_NAMESPACE::slist<T,AllocT> > + { + public: +#if BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + enum { value = true }; +#else + BOOST_STATIC_CONSTANT(bool, value=true); +#endif // BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + typedef mpl::bool_<has_const_time_erase<T>::value> type; + }; +#endif + + + } // namespace algorithm +} // namespace boost + + +#endif // BOOST_STRING_STD_LIST_TRAITS_HPP diff --git a/Utilities/BGL/boost/algorithm/string/std/string_traits.hpp b/Utilities/BGL/boost/algorithm/string/std/string_traits.hpp new file mode 100755 index 0000000000000000000000000000000000000000..e67a49a0ad1881e3a5c30194c1ee1c67c4d2040f --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/std/string_traits.hpp @@ -0,0 +1,52 @@ +// Boost string_algo library string_traits.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_STD_STRING_TRAITS_HPP +#define BOOST_STRING_STD_STRING_TRAITS_HPP + +#include <boost/algorithm/string/yes_no_type.hpp> +#include <string> +#include <boost/algorithm/string/sequence_traits.hpp> + +namespace boost { + namespace algorithm { + +// std::basic_string<> traits -----------------------------------------------// + +#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + // native replace tester + template<typename T, typename TraitsT, typename AllocT> + yes_type has_native_replace_tester( const std::basic_string<T, TraitsT, AllocT>* ); + +#else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + // native replace trait + template<typename T, typename TraitsT, typename AllocT> + class has_native_replace< std::basic_string<T, TraitsT, AllocT> > + { + public: +#if BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + enum { value = true } ; +#else + BOOST_STATIC_CONSTANT(bool, value=true); +#endif // BOOST_WORKAROUND( __IBMCPP__, <= 600 ) + + typedef mpl::bool_<has_native_replace<T>::value> type; + }; + + +#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + } // namespace algorithm +} // namespace boost + + +#endif // BOOST_STRING_LIST_TRAITS_HPP diff --git a/Utilities/BGL/boost/algorithm/string/std_containers_traits.hpp b/Utilities/BGL/boost/algorithm/string/std_containers_traits.hpp new file mode 100755 index 0000000000000000000000000000000000000000..28dddc75191cec655b1c0084651ac66a609b84e8 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/std_containers_traits.hpp @@ -0,0 +1,26 @@ +// Boost string_algo library std_containers_traits.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_STD_CONTAINERS_TRAITS_HPP +#define BOOST_STRING_STD_CONTAINERS_TRAITS_HPP + +/*!\file + This file includes sequence traits for stl containers. +*/ + +#include <boost/config.hpp> +#include <boost/algorithm/string/std/string_traits.hpp> +#include <boost/algorithm/string/std/list_traits.hpp> + +#ifdef BOOST_HAS_SLIST +# include <boost/algorithm/string/std/slist_traits.hpp> +#endif + +#endif // BOOST_STRING_STD_CONTAINERS_TRAITS_HPP diff --git a/Utilities/BGL/boost/algorithm/string/trim.hpp b/Utilities/BGL/boost/algorithm/string/trim.hpp new file mode 100755 index 0000000000000000000000000000000000000000..693804ae923acbb7d6a0658ac238cc2a391f5e7d --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/trim.hpp @@ -0,0 +1,398 @@ +// Boost string_algo library trim.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_TRIM_HPP +#define BOOST_STRING_TRIM_HPP + +#include <boost/algorithm/string/config.hpp> + +#include <boost/range/begin.hpp> +#include <boost/range/end.hpp> +#include <boost/range/const_iterator.hpp> +#include <boost/range/as_literal.hpp> +#include <boost/range/iterator_range.hpp> + +#include <boost/algorithm/string/detail/trim.hpp> +#include <boost/algorithm/string/classification.hpp> +#include <locale> + +/*! \file + Defines trim algorithms. + Trim algorithms are used to remove trailing and leading spaces from a + sequence (string). Space is recognized using given locales. + + Parametric (\c _if) variants use a predicate (functor) to select which characters + are to be trimmed.. + Functions take a selection predicate as a parameter, which is used to determine + whether a character is a space. Common predicates are provided in classification.hpp header. + +*/ + +namespace boost { + namespace algorithm { + + // left trim -----------------------------------------------// + + + //! Left trim - parametric + /*! + Remove all leading spaces from the input. + The supplied predicate is used to determine which characters are considered spaces. + The result is a trimmed copy of the input. It is returned as a sequence + or copied to the output iterator + + \param Output An output iterator to which the result will be copied + \param Input An input range + \param IsSpace An unary predicate identifying spaces + \return + An output iterator pointing just after the last inserted character or + a copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template<typename OutputIteratorT, typename RangeT, typename PredicateT> + inline OutputIteratorT trim_left_copy_if( + OutputIteratorT Output, + const RangeT& Input, + PredicateT IsSpace) + { + iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_range(::boost::as_literal(Input)); + + std::copy( + ::boost::algorithm::detail::trim_begin( + ::boost::begin(lit_range), + ::boost::end(lit_range), + IsSpace ), + ::boost::end(lit_range), + Output); + + return Output; + } + + //! Left trim - parametric + /*! + \overload + */ + template<typename SequenceT, typename PredicateT> + inline SequenceT trim_left_copy_if(const SequenceT& Input, PredicateT IsSpace) + { + return SequenceT( + ::boost::algorithm::detail::trim_begin( + ::boost::begin(Input), + ::boost::end(Input), + IsSpace ), + ::boost::end(Input)); + } + + //! Left trim - parametric + /*! + Remove all leading spaces from the input. + The result is a trimmed copy of the input. + + \param Input An input sequence + \param Loc a locale used for 'space' classification + \return A trimmed copy of the input + + \note This function provides the strong exception-safety guarantee + */ + template<typename SequenceT> + inline SequenceT trim_left_copy(const SequenceT& Input, const std::locale& Loc=std::locale()) + { + return + ::boost::algorithm::trim_left_copy_if( + Input, + is_space(Loc)); + } + + //! Left trim + /*! + Remove all leading spaces from the input. The supplied predicate is + used to determine which characters are considered spaces. + The input sequence is modified in-place. + + \param Input An input sequence + \param IsSpace An unary predicate identifying spaces + */ + template<typename SequenceT, typename PredicateT> + inline void trim_left_if(SequenceT& Input, PredicateT IsSpace) + { + Input.erase( + ::boost::begin(Input), + ::boost::algorithm::detail::trim_begin( + ::boost::begin(Input), + ::boost::end(Input), + IsSpace)); + } + + //! Left trim + /*! + Remove all leading spaces from the input. + The Input sequence is modified in-place. + + \param Input An input sequence + \param Loc A locale used for 'space' classification + */ + template<typename SequenceT> + inline void trim_left(SequenceT& Input, const std::locale& Loc=std::locale()) + { + ::boost::algorithm::trim_left_if( + Input, + is_space(Loc)); + } + + // right trim -----------------------------------------------// + + //! Right trim - parametric + /*! + Remove all trailing spaces from the input. + The supplied predicate is used to determine which characters are considered spaces. + The result is a trimmed copy of the input. It is returned as a sequence + or copied to the output iterator + + \param Output An output iterator to which the result will be copied + \param Input An input range + \param IsSpace An unary predicate identifying spaces + \return + An output iterator pointing just after the last inserted character or + a copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template<typename OutputIteratorT, typename RangeT, typename PredicateT> + inline OutputIteratorT trim_right_copy_if( + OutputIteratorT Output, + const RangeT& Input, + PredicateT IsSpace ) + { + iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_range(::boost::as_literal(Input)); + + std::copy( + ::boost::begin(lit_range), + ::boost::algorithm::detail::trim_end( + ::boost::begin(lit_range), + ::boost::end(lit_range), + IsSpace ), + Output ); + + return Output; + } + + //! Right trim - parametric + /*! + \overload + */ + template<typename SequenceT, typename PredicateT> + inline SequenceT trim_right_copy_if(const SequenceT& Input, PredicateT IsSpace) + { + return SequenceT( + ::boost::begin(Input), + ::boost::algorithm::detail::trim_end( + ::boost::begin(Input), + ::boost::end(Input), + IsSpace) + ); + } + + //! Right trim + /*! + Remove all trailing spaces from the input. + The result is a trimmed copy of the input + + \param Input An input sequence + \param Loc A locale used for 'space' classification + \return A trimmed copy of the input + + \note This function provides the strong exception-safety guarantee + */ + template<typename SequenceT> + inline SequenceT trim_right_copy(const SequenceT& Input, const std::locale& Loc=std::locale()) + { + return + ::boost::algorithm::trim_right_copy_if( + Input, + is_space(Loc)); + } + + + //! Right trim - parametric + /*! + Remove all trailing spaces from the input. + The supplied predicate is used to determine which characters are considered spaces. + The input sequence is modified in-place. + + \param Input An input sequence + \param IsSpace An unary predicate identifying spaces + */ + template<typename SequenceT, typename PredicateT> + inline void trim_right_if(SequenceT& Input, PredicateT IsSpace) + { + Input.erase( + ::boost::algorithm::detail::trim_end( + ::boost::begin(Input), + ::boost::end(Input), + IsSpace ), + ::boost::end(Input) + ); + } + + + //! Right trim + /*! + Remove all trailing spaces from the input. + The input sequence is modified in-place. + + \param Input An input sequence + \param Loc A locale used for 'space' classification + */ + template<typename SequenceT> + inline void trim_right(SequenceT& Input, const std::locale& Loc=std::locale()) + { + ::boost::algorithm::trim_right_if( + Input, + is_space(Loc) ); + } + + // both side trim -----------------------------------------------// + + //! Trim - parametric + /*! + Remove all trailing and leading spaces from the input. + The supplied predicate is used to determine which characters are considered spaces. + The result is a trimmed copy of the input. It is returned as a sequence + or copied to the output iterator + + \param Output An output iterator to which the result will be copied + \param Input An input range + \param IsSpace An unary predicate identifying spaces + \return + An output iterator pointing just after the last inserted character or + a copy of the input + + \note The second variant of this function provides the strong exception-safety guarantee + */ + template<typename OutputIteratorT, typename RangeT, typename PredicateT> + inline OutputIteratorT trim_copy_if( + OutputIteratorT Output, + const RangeT& Input, + PredicateT IsSpace) + { + iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_range(::boost::as_literal(Input)); + + BOOST_STRING_TYPENAME + range_const_iterator<RangeT>::type TrimEnd= + ::boost::algorithm::detail::trim_end( + ::boost::begin(lit_range), + ::boost::end(lit_range), + IsSpace); + + std::copy( + detail::trim_begin( + ::boost::begin(lit_range), TrimEnd, IsSpace), + TrimEnd, + Output + ); + + return Output; + } + + //! Trim - parametric + /*! + \overload + */ + template<typename SequenceT, typename PredicateT> + inline SequenceT trim_copy_if(const SequenceT& Input, PredicateT IsSpace) + { + BOOST_STRING_TYPENAME + range_const_iterator<SequenceT>::type TrimEnd= + ::boost::algorithm::detail::trim_end( + ::boost::begin(Input), + ::boost::end(Input), + IsSpace); + + return SequenceT( + detail::trim_begin( + ::boost::begin(Input), + TrimEnd, + IsSpace), + TrimEnd + ); + } + + //! Trim + /*! + Remove all leading and trailing spaces from the input. + The result is a trimmed copy of the input + + \param Input An input sequence + \param Loc A locale used for 'space' classification + \return A trimmed copy of the input + + \note This function provides the strong exception-safety guarantee + */ + template<typename SequenceT> + inline SequenceT trim_copy( const SequenceT& Input, const std::locale& Loc=std::locale() ) + { + return + ::boost::algorithm::trim_copy_if( + Input, + is_space(Loc) ); + } + + //! Trim + /*! + Remove all leading and trailing spaces from the input. + The supplied predicate is used to determine which characters are considered spaces. + The input sequence is modified in-place. + + \param Input An input sequence + \param IsSpace An unary predicate identifying spaces + */ + template<typename SequenceT, typename PredicateT> + inline void trim_if(SequenceT& Input, PredicateT IsSpace) + { + ::boost::algorithm::trim_right_if( Input, IsSpace ); + ::boost::algorithm::trim_left_if( Input, IsSpace ); + } + + //! Trim + /*! + Remove all leading and trailing spaces from the input. + The input sequence is modified in-place. + + \param Input An input sequence + \param Loc A locale used for 'space' classification + */ + template<typename SequenceT> + inline void trim(SequenceT& Input, const std::locale& Loc=std::locale()) + { + ::boost::algorithm::trim_if( + Input, + is_space( Loc ) ); + } + + } // namespace algorithm + + // pull names to the boost namespace + using algorithm::trim_left; + using algorithm::trim_left_if; + using algorithm::trim_left_copy; + using algorithm::trim_left_copy_if; + using algorithm::trim_right; + using algorithm::trim_right_if; + using algorithm::trim_right_copy; + using algorithm::trim_right_copy_if; + using algorithm::trim; + using algorithm::trim_if; + using algorithm::trim_copy; + using algorithm::trim_copy_if; + +} // namespace boost + +#endif // BOOST_STRING_TRIM_HPP diff --git a/Utilities/BGL/boost/algorithm/string/yes_no_type.hpp b/Utilities/BGL/boost/algorithm/string/yes_no_type.hpp new file mode 100755 index 0000000000000000000000000000000000000000..4109763c1fc51bf3ec2f1c9ae06d7de4b46616b8 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string/yes_no_type.hpp @@ -0,0 +1,33 @@ +// Boost string_algo library yes_no_type.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2003. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_YES_NO_TYPE_DETAIL_HPP +#define BOOST_STRING_YES_NO_TYPE_DETAIL_HPP + +namespace boost { + namespace algorithm { + + // taken from boost mailing-list + // when yes_no_type will become officially + // a part of boost distribution, this header + // will be deprecated + template<int I> struct size_descriptor + { + typedef char (& type)[I]; + }; + + typedef size_descriptor<1>::type yes_type; + typedef size_descriptor<2>::type no_type; + + } // namespace algorithm +} // namespace boost + + +#endif // BOOST_STRING_YES_NO_TYPE_DETAIL_HPP diff --git a/Utilities/BGL/boost/algorithm/string_regex.hpp b/Utilities/BGL/boost/algorithm/string_regex.hpp new file mode 100755 index 0000000000000000000000000000000000000000..a77d04f026a0fb82983986327e1efa6039e378d1 --- /dev/null +++ b/Utilities/BGL/boost/algorithm/string_regex.hpp @@ -0,0 +1,23 @@ +// Boost string_algo library string_regex.hpp header file ---------------------------// + +// Copyright Pavol Droba 2002-2004. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/ for updates, documentation, and revision history. + +#ifndef BOOST_STRING_ALGO_REGEX_HPP +#define BOOST_STRING_ALGO_REGEX_HPP + +/*! \file + Cumulative include for string_algo library. + In addtion to string.hpp contains also regex-related stuff. +*/ + +#include <boost/regex.hpp> +#include <boost/algorithm/string.hpp> +#include <boost/algorithm/string/regex.hpp> + +#endif // BOOST_STRING_ALGO_REGEX_HPP diff --git a/Utilities/BGL/boost/random.hpp b/Utilities/BGL/boost/random.hpp new file mode 100755 index 0000000000000000000000000000000000000000..be053b9a4f44f790b68d4a0b7e3ba916d14ef996 --- /dev/null +++ b/Utilities/BGL/boost/random.hpp @@ -0,0 +1,75 @@ +/* boost random.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org/libs/random for documentation. + * + * $Id: random.hpp 58649 2010-01-02 21:23:17Z steven_watanabe $ + * + * Revision history + * 2000-02-18 portability fixes (thanks to Beman Dawes) + * 2000-02-21 shuffle_output, inversive_congruential_schrage, + * generator_iterator, uniform_smallint + * 2000-02-23 generic modulus arithmetic helper, removed *_schrage classes, + * implemented Streamable and EqualityComparable concepts for + * generators, added Bernoulli distribution and Box-Muller + * transform + * 2000-03-01 cauchy, lognormal, triangle distributions; fixed + * uniform_smallint; renamed gaussian to normal distribution + * 2000-03-05 implemented iterator syntax for distribution functions + * 2000-04-21 removed some optimizations for better BCC/MSVC compatibility + * 2000-05-10 adapted to BCC and MSVC + * 2000-06-13 incorporated review results + * 2000-07-06 moved basic templates from namespace detail to random + * 2000-09-23 warning removals and int64 fixes (Ed Brey) + * 2000-09-24 added lagged_fibonacci generator (Matthias Troyer) + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_HPP +#define BOOST_RANDOM_HPP + +// generators +#include <boost/random/linear_congruential.hpp> +#include <boost/random/additive_combine.hpp> +#include <boost/random/inversive_congruential.hpp> +#include <boost/random/shuffle_output.hpp> +#include <boost/random/mersenne_twister.hpp> +#include <boost/random/lagged_fibonacci.hpp> +#include <boost/random/ranlux.hpp> +#include <boost/random/linear_feedback_shift.hpp> +#include <boost/random/xor_combine.hpp> +#include <boost/random/discard_block.hpp> +#include <boost/random/subtract_with_carry.hpp> +#include <boost/random/variate_generator.hpp> + +namespace boost { + typedef random::xor_combine<random::xor_combine<random::linear_feedback_shift<uint32_t, 32, 31, 13, 12, 0>, 0, + random::linear_feedback_shift<uint32_t, 32, 29, 2, 4, 0>, 0, 0>, 0, + random::linear_feedback_shift<uint32_t, 32, 28, 3, 17, 0>, 0, 0> taus88; +} // namespace boost + +// misc +#include <boost/random/random_number_generator.hpp> + +// distributions +#include <boost/random/uniform_smallint.hpp> +#include <boost/random/uniform_int.hpp> +#include <boost/random/uniform_01.hpp> +#include <boost/random/uniform_real.hpp> +#include <boost/random/triangle_distribution.hpp> +#include <boost/random/bernoulli_distribution.hpp> +#include <boost/random/cauchy_distribution.hpp> +#include <boost/random/exponential_distribution.hpp> +#include <boost/random/geometric_distribution.hpp> +#include <boost/random/normal_distribution.hpp> +#include <boost/random/lognormal_distribution.hpp> +#include <boost/random/poisson_distribution.hpp> +#include <boost/random/gamma_distribution.hpp> +#include <boost/random/binomial_distribution.hpp> +#include <boost/random/uniform_on_sphere.hpp> + +#endif // BOOST_RANDOM_HPP diff --git a/Utilities/BGL/boost/random/additive_combine.hpp b/Utilities/BGL/boost/random/additive_combine.hpp new file mode 100755 index 0000000000000000000000000000000000000000..e4e6d566963aa42081dce6c33a5b9ae67e842278 --- /dev/null +++ b/Utilities/BGL/boost/random/additive_combine.hpp @@ -0,0 +1,134 @@ +/* boost random/additive_combine.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: additive_combine.hpp 58649 2010-01-02 21:23:17Z steven_watanabe $ + * + * Revision history + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_ADDITIVE_COMBINE_HPP +#define BOOST_RANDOM_ADDITIVE_COMBINE_HPP + +#include <iostream> +#include <algorithm> // for std::min and std::max +#include <boost/config.hpp> +#include <boost/cstdint.hpp> +#include <boost/random/detail/config.hpp> +#include <boost/random/linear_congruential.hpp> + +namespace boost { +namespace random { + +// L'Ecuyer 1988 +template<class MLCG1, class MLCG2, +#ifndef BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS + typename MLCG1::result_type +#else + int32_t +#endif + val> +class additive_combine +{ +public: + typedef MLCG1 first_base; + typedef MLCG2 second_base; + typedef typename MLCG1::result_type result_type; +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION + static const bool has_fixed_range = true; + static const result_type min_value = 1; + static const result_type max_value = MLCG1::max_value-1; +#else + enum { has_fixed_range = false }; +#endif + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 1; } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_mlcg1.max)()-1; } + + additive_combine() : _mlcg1(), _mlcg2() { } + additive_combine(typename MLCG1::result_type seed1, + typename MLCG2::result_type seed2) + : _mlcg1(seed1), _mlcg2(seed2) { } + additive_combine(result_type aseed) + : _mlcg1(aseed), _mlcg2(aseed) { } + template<class It> additive_combine(It& first, It last) + : _mlcg1(first, last), _mlcg2(first, last) { } + + void seed() + { + _mlcg1.seed(); + _mlcg2.seed(); + } + + void seed(result_type aseed) + { + _mlcg1.seed(aseed); + _mlcg2.seed(aseed); + } + + void seed(typename MLCG1::result_type seed1, + typename MLCG2::result_type seed2) + { + _mlcg1.seed(seed1); + _mlcg2.seed(seed2); + } + + template<class It> void seed(It& first, It last) + { + _mlcg1.seed(first, last); + _mlcg2.seed(first, last); + } + + result_type operator()() { + result_type z = _mlcg1() - _mlcg2(); + if(z < 1) + z += MLCG1::modulus-1; + return z; + } + static bool validation(result_type x) { return val == x; } + +#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const additive_combine& r) + { os << r._mlcg1 << " " << r._mlcg2; return os; } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, additive_combine& r) + { is >> r._mlcg1 >> std::ws >> r._mlcg2; return is; } +#endif + + friend bool operator==(const additive_combine& x, const additive_combine& y) + { return x._mlcg1 == y._mlcg1 && x._mlcg2 == y._mlcg2; } + friend bool operator!=(const additive_combine& x, const additive_combine& y) + { return !(x == y); } +#else + // Use a member function; Streamable concept not supported. + bool operator==(const additive_combine& rhs) const + { return _mlcg1 == rhs._mlcg1 && _mlcg2 == rhs._mlcg2; } + bool operator!=(const additive_combine& rhs) const + { return !(*this == rhs); } +#endif +private: + MLCG1 _mlcg1; + MLCG2 _mlcg2; +}; + +} // namespace random + +typedef random::additive_combine< + random::linear_congruential<int32_t, 40014, 0, 2147483563, 0>, + random::linear_congruential<int32_t, 40692, 0, 2147483399, 0>, + 2060321752> ecuyer1988; + +} // namespace boost + +#endif // BOOST_RANDOM_ADDITIVE_COMBINE_HPP diff --git a/Utilities/BGL/boost/random/bernoulli_distribution.hpp b/Utilities/BGL/boost/random/bernoulli_distribution.hpp new file mode 100755 index 0000000000000000000000000000000000000000..d68111473af8ffb1b5d61e1e4de84e3e2609574b --- /dev/null +++ b/Utilities/BGL/boost/random/bernoulli_distribution.hpp @@ -0,0 +1,81 @@ +/* boost random/bernoulli_distribution.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: bernoulli_distribution.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $ + * + * Revision history + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_BERNOULLI_DISTRIBUTION_HPP +#define BOOST_RANDOM_BERNOULLI_DISTRIBUTION_HPP + +#include <cassert> +#include <iostream> +#include <boost/random/detail/config.hpp> + +namespace boost { + +// Bernoulli distribution: p(true) = p, p(false) = 1-p (boolean) +template<class RealType = double> +class bernoulli_distribution +{ +public: + // In principle, this could work with both integer and floating-point + // types. Generating floating-point random numbers in the first + // place is probably more expensive, so use integer as input. + typedef int input_type; + typedef bool result_type; + + explicit bernoulli_distribution(const RealType& p_arg = RealType(0.5)) + : _p(p_arg) + { + assert(_p >= 0); + assert(_p <= 1); + } + + // compiler-generated copy ctor and assignment operator are fine + + RealType p() const { return _p; } + void reset() { } + + template<class Engine> + result_type operator()(Engine& eng) + { + if(_p == RealType(0)) + return false; + else + return RealType(eng() - (eng.min)()) <= _p * RealType((eng.max)()-(eng.min)()); + } + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const bernoulli_distribution& bd) + { + os << bd._p; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, bernoulli_distribution& bd) + { + is >> std::ws >> bd._p; + return is; + } +#endif + +private: + RealType _p; +}; + +} // namespace boost + +#endif // BOOST_RANDOM_BERNOULLI_DISTRIBUTION_HPP diff --git a/Utilities/BGL/boost/random/binomial_distribution.hpp b/Utilities/BGL/boost/random/binomial_distribution.hpp new file mode 100755 index 0000000000000000000000000000000000000000..952142fa3cb407a4c7923d6cec38519ffc45cada --- /dev/null +++ b/Utilities/BGL/boost/random/binomial_distribution.hpp @@ -0,0 +1,82 @@ +/* boost random/binomial_distribution.hpp header file + * + * Copyright Jens Maurer 2002 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: binomial_distribution.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $ + * + */ + +#ifndef BOOST_RANDOM_BINOMIAL_DISTRIBUTION_HPP +#define BOOST_RANDOM_BINOMIAL_DISTRIBUTION_HPP + +#include <boost/config/no_tr1/cmath.hpp> +#include <cassert> +#include <boost/random/detail/config.hpp> +#include <boost/random/bernoulli_distribution.hpp> + +namespace boost { + +// Knuth +template<class IntType = int, class RealType = double> +class binomial_distribution +{ +public: + typedef typename bernoulli_distribution<RealType>::input_type input_type; + typedef IntType result_type; + + explicit binomial_distribution(IntType t_arg = 1, + const RealType& p_arg = RealType(0.5)) + : _bernoulli(p_arg), _t(t_arg) + { + assert(_t >= 0); + assert(RealType(0) <= p_arg && p_arg <= RealType(1)); + } + + // compiler-generated copy ctor and assignment operator are fine + + IntType t() const { return _t; } + RealType p() const { return _bernoulli.p(); } + void reset() { } + + template<class Engine> + result_type operator()(Engine& eng) + { + // TODO: This is O(_t), but it should be O(log(_t)) for large _t + result_type n = 0; + for(IntType i = 0; i < _t; ++i) + if(_bernoulli(eng)) + ++n; + return n; + } + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const binomial_distribution& bd) + { + os << bd._bernoulli << " " << bd._t; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, binomial_distribution& bd) + { + is >> std::ws >> bd._bernoulli >> std::ws >> bd._t; + return is; + } +#endif + +private: + bernoulli_distribution<RealType> _bernoulli; + IntType _t; +}; + +} // namespace boost + +#endif // BOOST_RANDOM_BINOMIAL_DISTRIBUTION_HPP diff --git a/Utilities/BGL/boost/random/cauchy_distribution.hpp b/Utilities/BGL/boost/random/cauchy_distribution.hpp new file mode 100755 index 0000000000000000000000000000000000000000..338821276e48b13d81d7defb63c6faee9e49ff2c --- /dev/null +++ b/Utilities/BGL/boost/random/cauchy_distribution.hpp @@ -0,0 +1,90 @@ +/* boost random/cauchy_distribution.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: cauchy_distribution.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $ + * + * Revision history + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP +#define BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP + +#include <boost/config/no_tr1/cmath.hpp> +#include <iostream> +#include <boost/limits.hpp> +#include <boost/static_assert.hpp> +#include <boost/random/detail/config.hpp> + +namespace boost { + +#if defined(__GNUC__) && (__GNUC__ < 3) +// Special gcc workaround: gcc 2.95.x ignores using-declarations +// in template classes (confirmed by gcc author Martin v. Loewis) + using std::tan; +#endif + +// Cauchy distribution: p(x) = sigma/(pi*(sigma**2 + (x-median)**2)) +template<class RealType = double> +class cauchy_distribution +{ +public: + typedef RealType input_type; + typedef RealType result_type; + +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer); +#endif + + explicit cauchy_distribution(result_type median_arg = result_type(0), + result_type sigma_arg = result_type(1)) + : _median(median_arg), _sigma(sigma_arg) { } + + // compiler-generated copy ctor and assignment operator are fine + + result_type median() const { return _median; } + result_type sigma() const { return _sigma; } + void reset() { } + + template<class Engine> + result_type operator()(Engine& eng) + { + // Can we have a boost::mathconst please? + const result_type pi = result_type(3.14159265358979323846); +#ifndef BOOST_NO_STDC_NAMESPACE + using std::tan; +#endif + return _median + _sigma * tan(pi*(eng()-result_type(0.5))); + } + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const cauchy_distribution& cd) + { + os << cd._median << " " << cd._sigma; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, cauchy_distribution& cd) + { + is >> std::ws >> cd._median >> std::ws >> cd._sigma; + return is; + } +#endif + +private: + result_type _median, _sigma; +}; + +} // namespace boost + +#endif // BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP diff --git a/Utilities/BGL/boost/random/detail/config.hpp b/Utilities/BGL/boost/random/detail/config.hpp new file mode 100755 index 0000000000000000000000000000000000000000..bb834534b571ba0693f7e2e726494ebc7679eeea --- /dev/null +++ b/Utilities/BGL/boost/random/detail/config.hpp @@ -0,0 +1,18 @@ +/* boost random/detail/config.hpp header file + * + * Copyright Steven Watanabe 2009 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: config.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $ + */ + +#include <boost/config.hpp> + +#if (defined(BOOST_NO_OPERATORS_IN_NAMESPACE) || defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)) \ + && !defined(BOOST_MSVC) + #define BOOST_RANDOM_NO_STREAM_OPERATORS +#endif diff --git a/Utilities/BGL/boost/random/detail/const_mod.hpp b/Utilities/BGL/boost/random/detail/const_mod.hpp new file mode 100755 index 0000000000000000000000000000000000000000..07f75450633259cd400e0c111818a1c55898ad56 --- /dev/null +++ b/Utilities/BGL/boost/random/detail/const_mod.hpp @@ -0,0 +1,363 @@ +/* boost random/detail/const_mod.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: const_mod.hpp 58649 2010-01-02 21:23:17Z steven_watanabe $ + * + * Revision history + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_CONST_MOD_HPP +#define BOOST_RANDOM_CONST_MOD_HPP + +#include <cassert> +#include <boost/static_assert.hpp> +#include <boost/cstdint.hpp> +#include <boost/integer_traits.hpp> +#include <boost/detail/workaround.hpp> + +#include <boost/random/detail/disable_warnings.hpp> + +namespace boost { +namespace random { + +/* + * Some random number generators require modular arithmetic. Put + * everything we need here. + * IntType must be an integral type. + */ + +namespace detail { + + template<bool is_signed> + struct do_add + { }; + + template<> + struct do_add<true> + { + template<class IntType> + static IntType add(IntType m, IntType x, IntType c) + { + if (x < m - c) + return x + c; + else + return x - (m-c); + } + }; + + template<> + struct do_add<false> + { + template<class IntType> + static IntType add(IntType, IntType, IntType) + { + // difficult + assert(!"const_mod::add with c too large"); + return 0; + } + }; +} // namespace detail + +#if !(defined(__BORLANDC__) && (__BORLANDC__ == 0x560)) + +template<class IntType, IntType m> +class const_mod +{ +public: + static IntType add(IntType x, IntType c) + { + if(c == 0) + return x; + else if(c <= traits::const_max - m) // i.e. m+c < max + return add_small(x, c); + else + return detail::do_add<traits::is_signed>::add(m, x, c); + } + + static IntType mult(IntType a, IntType x) + { + if(a == 1) + return x; + else if(m <= traits::const_max/a) // i.e. a*m <= max + return mult_small(a, x); + else if(traits::is_signed && (m%a < m/a)) + return mult_schrage(a, x); + else { + // difficult + assert(!"const_mod::mult with a too large"); + return 0; + } + } + + static IntType mult_add(IntType a, IntType x, IntType c) + { + if(m <= (traits::const_max-c)/a) // i.e. a*m+c <= max + return (a*x+c) % m; + else + return add(mult(a, x), c); + } + + static IntType invert(IntType x) + { return x == 0 ? 0 : invert_euclidian(x); } + +private: + typedef integer_traits<IntType> traits; + + const_mod(); // don't instantiate + + static IntType add_small(IntType x, IntType c) + { + x += c; + if(x >= m) + x -= m; + return x; + } + + static IntType mult_small(IntType a, IntType x) + { + return a*x % m; + } + + static IntType mult_schrage(IntType a, IntType value) + { + const IntType q = m / a; + const IntType r = m % a; + + assert(r < q); // check that overflow cannot happen + + value = a*(value%q) - r*(value/q); + // An optimizer bug in the SGI MIPSpro 7.3.1.x compiler requires this + // convoluted formulation of the loop (Synge Todo) + for(;;) { + if (value > 0) + break; + value += m; + } + return value; + } + + // invert c in the finite field (mod m) (m must be prime) + static IntType invert_euclidian(IntType c) + { + // we are interested in the gcd factor for c, because this is our inverse + BOOST_STATIC_ASSERT(m > 0); +#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) + assert(boost::integer_traits<IntType>::is_signed); +#elif !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) + BOOST_STATIC_ASSERT(boost::integer_traits<IntType>::is_signed); +#endif + assert(c > 0); + IntType l1 = 0; + IntType l2 = 1; + IntType n = c; + IntType p = m; + for(;;) { + IntType q = p / n; + l1 -= q * l2; // this requires a signed IntType! + p -= q * n; + if(p == 0) + return (l2 < 1 ? l2 + m : l2); + IntType q2 = n / p; + l2 -= q2 * l1; + n -= q2 * p; + if(n == 0) + return (l1 < 1 ? l1 + m : l1); + } + } +}; + +// The modulus is exactly the word size: rely on machine overflow handling. +// Due to a GCC bug, we cannot partially specialize in the presence of +// template value parameters. +template<> +class const_mod<unsigned int, 0> +{ + typedef unsigned int IntType; +public: + static IntType add(IntType x, IntType c) { return x+c; } + static IntType mult(IntType a, IntType x) { return a*x; } + static IntType mult_add(IntType a, IntType x, IntType c) { return a*x+c; } + + // m is not prime, thus invert is not useful +private: // don't instantiate + const_mod(); +}; + +template<> +class const_mod<unsigned long, 0> +{ + typedef unsigned long IntType; +public: + static IntType add(IntType x, IntType c) { return x+c; } + static IntType mult(IntType a, IntType x) { return a*x; } + static IntType mult_add(IntType a, IntType x, IntType c) { return a*x+c; } + + // m is not prime, thus invert is not useful +private: // don't instantiate + const_mod(); +}; + +// the modulus is some power of 2: rely partly on machine overflow handling +// we only specialize for rand48 at the moment +#ifndef BOOST_NO_INT64_T +template<> +class const_mod<uint64_t, uint64_t(1) << 48> +{ + typedef uint64_t IntType; +public: + static IntType add(IntType x, IntType c) { return c == 0 ? x : mod(x+c); } + static IntType mult(IntType a, IntType x) { return mod(a*x); } + static IntType mult_add(IntType a, IntType x, IntType c) + { return mod(a*x+c); } + static IntType mod(IntType x) { return x &= ((uint64_t(1) << 48)-1); } + + // m is not prime, thus invert is not useful +private: // don't instantiate + const_mod(); +}; +#endif /* !BOOST_NO_INT64_T */ + +#else + +// +// for some reason Borland C++ Builder 6 has problems with +// the full specialisations of const_mod, define a generic version +// instead, the compiler will optimise away the const-if statements: +// + +template<class IntType, IntType m> +class const_mod +{ +public: + static IntType add(IntType x, IntType c) + { + if(0 == m) + { + return x+c; + } + else + { + if(c == 0) + return x; + else if(c <= traits::const_max - m) // i.e. m+c < max + return add_small(x, c); + else + return detail::do_add<traits::is_signed>::add(m, x, c); + } + } + + static IntType mult(IntType a, IntType x) + { + if(x == 0) + { + return a*x; + } + else + { + if(a == 1) + return x; + else if(m <= traits::const_max/a) // i.e. a*m <= max + return mult_small(a, x); + else if(traits::is_signed && (m%a < m/a)) + return mult_schrage(a, x); + else { + // difficult + assert(!"const_mod::mult with a too large"); + return 0; + } + } + } + + static IntType mult_add(IntType a, IntType x, IntType c) + { + if(m == 0) + { + return a*x+c; + } + else + { + if(m <= (traits::const_max-c)/a) // i.e. a*m+c <= max + return (a*x+c) % m; + else + return add(mult(a, x), c); + } + } + + static IntType invert(IntType x) + { return x == 0 ? 0 : invert_euclidian(x); } + +private: + typedef integer_traits<IntType> traits; + + const_mod(); // don't instantiate + + static IntType add_small(IntType x, IntType c) + { + x += c; + if(x >= m) + x -= m; + return x; + } + + static IntType mult_small(IntType a, IntType x) + { + return a*x % m; + } + + static IntType mult_schrage(IntType a, IntType value) + { + const IntType q = m / a; + const IntType r = m % a; + + assert(r < q); // check that overflow cannot happen + + value = a*(value%q) - r*(value/q); + while(value <= 0) + value += m; + return value; + } + + // invert c in the finite field (mod m) (m must be prime) + static IntType invert_euclidian(IntType c) + { + // we are interested in the gcd factor for c, because this is our inverse + BOOST_STATIC_ASSERT(m > 0); +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT(boost::integer_traits<IntType>::is_signed); +#endif + assert(c > 0); + IntType l1 = 0; + IntType l2 = 1; + IntType n = c; + IntType p = m; + for(;;) { + IntType q = p / n; + l1 -= q * l2; // this requires a signed IntType! + p -= q * n; + if(p == 0) + return (l2 < 1 ? l2 + m : l2); + IntType q2 = n / p; + l2 -= q2 * l1; + n -= q2 * p; + if(n == 0) + return (l1 < 1 ? l1 + m : l1); + } + } +}; + + +#endif + +} // namespace random +} // namespace boost + +#include <boost/random/detail/enable_warnings.hpp> + +#endif // BOOST_RANDOM_CONST_MOD_HPP diff --git a/Utilities/BGL/boost/random/detail/disable_warnings.hpp b/Utilities/BGL/boost/random/detail/disable_warnings.hpp new file mode 100755 index 0000000000000000000000000000000000000000..c638d2acdf74675786568fb74ee3c47d678e056f --- /dev/null +++ b/Utilities/BGL/boost/random/detail/disable_warnings.hpp @@ -0,0 +1,22 @@ +/* boost random/detail/disable_warnings.hpp header file + * + * Copyright Steven Watanabe 2009 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: disable_warnings.hpp 58649 2010-01-02 21:23:17Z steven_watanabe $ + * + */ + +// No #include guard. This header is intended to be included multiple times. + +#include <boost/config.hpp> + +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:4512) +#pragma warning(disable:4127) +#endif diff --git a/Utilities/BGL/boost/random/detail/enable_warnings.hpp b/Utilities/BGL/boost/random/detail/enable_warnings.hpp new file mode 100755 index 0000000000000000000000000000000000000000..12f0840efd9e3736577cb3f3b98d59abde3cd97a --- /dev/null +++ b/Utilities/BGL/boost/random/detail/enable_warnings.hpp @@ -0,0 +1,18 @@ +/* boost random/detail/enable_warnings.hpp header file + * + * Copyright Steven Watanabe 2009 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: enable_warnings.hpp 58649 2010-01-02 21:23:17Z steven_watanabe $ + * + */ + +// No #include guard. This header is intended to be included multiple times. + +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif diff --git a/Utilities/BGL/boost/random/detail/iterator_mixin.hpp b/Utilities/BGL/boost/random/detail/iterator_mixin.hpp new file mode 100755 index 0000000000000000000000000000000000000000..ca67ebb5ade41026ad5bb959299c149b7e589de5 --- /dev/null +++ b/Utilities/BGL/boost/random/detail/iterator_mixin.hpp @@ -0,0 +1,45 @@ +/* boost random/detail/iterator_mixin.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * Revision history + */ + +#ifndef BOOST_ITERATOR_MIXIN_HPP +#define BOOST_ITERATOR_MIXIN_HPP + +#include <boost/operators.hpp> + +namespace boost { + +// must be in boost namespace, otherwise the inline friend trick fails +template<class Generator, class ResultType> +class generator_iterator_mixin_adapter + : incrementable<Generator>, equality_comparable<Generator> +{ +public: + typedef std::input_iterator_tag iterator_category; + typedef ResultType value_type; + typedef std::ptrdiff_t difference_type; + typedef const value_type * pointer; + typedef const value_type & reference; + Generator& operator++() { v = cast()(); return cast(); } + const value_type& operator*() const { return v; } + +protected: + // instantiate from derived classes only + generator_iterator_mixin_adapter() { } + void iterator_init() { operator++(); } +private: + Generator & cast() { return static_cast<Generator&>(*this); } + value_type v; +}; + +} // namespace boost + +#endif // BOOST_ITERATOR_MIXIN_HPP diff --git a/Utilities/BGL/boost/random/detail/pass_through_engine.hpp b/Utilities/BGL/boost/random/detail/pass_through_engine.hpp new file mode 100755 index 0000000000000000000000000000000000000000..8627025ef165cb6e29a66d49086b5fe0b2211f63 --- /dev/null +++ b/Utilities/BGL/boost/random/detail/pass_through_engine.hpp @@ -0,0 +1,100 @@ +/* boost random/detail/uniform_int_float.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: pass_through_engine.hpp 58649 2010-01-02 21:23:17Z steven_watanabe $ + * + */ + +#ifndef BOOST_RANDOM_DETAIL_PASS_THROUGH_ENGINE_HPP +#define BOOST_RANDOM_DETAIL_PASS_THROUGH_ENGINE_HPP + +#include <boost/config.hpp> +#include <boost/random/detail/ptr_helper.hpp> +#include <boost/random/detail/disable_warnings.hpp> + +namespace boost { +namespace random { +namespace detail { + +template<class UniformRandomNumberGenerator> +class pass_through_engine +{ +private: + typedef ptr_helper<UniformRandomNumberGenerator> helper_type; + +public: + typedef typename helper_type::value_type base_type; + typedef typename base_type::result_type result_type; + + explicit pass_through_engine(UniformRandomNumberGenerator rng) + // make argument an rvalue to avoid matching Generator& constructor + : _rng(static_cast<typename helper_type::rvalue_type>(rng)) + { } + + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (base().min)(); } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (base().max)(); } + base_type& base() { return helper_type::ref(_rng); } + const base_type& base() const { return helper_type::ref(_rng); } + + result_type operator()() { return base()(); } + +private: + UniformRandomNumberGenerator _rng; +}; + +#ifndef BOOST_NO_STD_LOCALE + +template<class UniformRandomNumberGenerator, class CharT, class Traits> +std::basic_ostream<CharT,Traits>& +operator<<( + std::basic_ostream<CharT,Traits>& os + , const pass_through_engine<UniformRandomNumberGenerator>& ud + ) +{ + return os << ud.base(); +} + +template<class UniformRandomNumberGenerator, class CharT, class Traits> +std::basic_istream<CharT,Traits>& +operator>>( + std::basic_istream<CharT,Traits>& is + , const pass_through_engine<UniformRandomNumberGenerator>& ud + ) +{ + return is >> ud.base(); +} + +#else // no new streams + +template<class UniformRandomNumberGenerator> +inline std::ostream& +operator<<(std::ostream& os, + const pass_through_engine<UniformRandomNumberGenerator>& ud) +{ + return os << ud.base(); +} + +template<class UniformRandomNumberGenerator> +inline std::istream& +operator>>(std::istream& is, + const pass_through_engine<UniformRandomNumberGenerator>& ud) +{ + return is >> ud.base(); +} + +#endif + +} // namespace detail +} // namespace random +} // namespace boost + +#include <boost/random/detail/enable_warnings.hpp> + +#endif // BOOST_RANDOM_DETAIL_PASS_THROUGH_ENGINE_HPP + diff --git a/Utilities/BGL/boost/random/detail/ptr_helper.hpp b/Utilities/BGL/boost/random/detail/ptr_helper.hpp new file mode 100755 index 0000000000000000000000000000000000000000..d583afe8ed3fabd3292b0135bec183b6e357b2d2 --- /dev/null +++ b/Utilities/BGL/boost/random/detail/ptr_helper.hpp @@ -0,0 +1,94 @@ +/* boost random/detail/ptr_helper.hpp header file + * + * Copyright Jens Maurer 2002 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: ptr_helper.hpp 24096 2004-07-27 03:43:34Z dgregor $ + * + */ + +#ifndef BOOST_RANDOM_DETAIL_PTR_HELPER_HPP +#define BOOST_RANDOM_DETAIL_PTR_HELPER_HPP + +#include <boost/config.hpp> + + +namespace boost { +namespace random { +namespace detail { + +// type_traits could help here, but I don't want to depend on type_traits. +template<class T> +struct ptr_helper +{ + typedef T value_type; + typedef T& reference_type; + typedef const T& rvalue_type; + static reference_type ref(T& r) { return r; } + static const T& ref(const T& r) { return r; } +}; + +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION +template<class T> +struct ptr_helper<T&> +{ + typedef T value_type; + typedef T& reference_type; + typedef T& rvalue_type; + static reference_type ref(T& r) { return r; } + static const T& ref(const T& r) { return r; } +}; + +template<class T> +struct ptr_helper<T*> +{ + typedef T value_type; + typedef T& reference_type; + typedef T* rvalue_type; + static reference_type ref(T * p) { return *p; } + static const T& ref(const T * p) { return *p; } +}; +#endif + +} // namespace detail +} // namespace random +} // namespace boost + +// +// BOOST_RANDOM_PTR_HELPER_SPEC -- +// +// Helper macro for broken compilers defines specializations of +// ptr_helper. +// +#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION +# define BOOST_RANDOM_PTR_HELPER_SPEC(T) \ +namespace boost { namespace random { namespace detail { \ +template<> \ +struct ptr_helper<T&> \ +{ \ + typedef T value_type; \ + typedef T& reference_type; \ + typedef T& rvalue_type; \ + static reference_type ref(T& r) { return r; } \ + static const T& ref(const T& r) { return r; } \ +}; \ + \ +template<> \ +struct ptr_helper<T*> \ +{ \ + typedef T value_type; \ + typedef T& reference_type; \ + typedef T* rvalue_type; \ + static reference_type ref(T * p) { return *p; } \ + static const T& ref(const T * p) { return *p; } \ +}; \ +}}} +#else +# define BOOST_RANDOM_PTR_HELPER_SPEC(T) +#endif + +#endif // BOOST_RANDOM_DETAIL_PTR_HELPER_HPP diff --git a/Utilities/BGL/boost/random/detail/seed.hpp b/Utilities/BGL/boost/random/detail/seed.hpp new file mode 100755 index 0000000000000000000000000000000000000000..f6a7f045ec53d6bcea362bd188727fe3eb0b530d --- /dev/null +++ b/Utilities/BGL/boost/random/detail/seed.hpp @@ -0,0 +1,88 @@ +/* boost random/detail/seed.hpp header file + * + * Copyright Steven Watanabe 2009 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: seed.hpp 53871 2009-06-13 17:54:06Z steven_watanabe $ + */ + +#ifndef BOOST_RANDOM_DETAIL_SEED_HPP +#define BOOST_RANDOM_DETAIL_SEED_HPP + +#include <boost/config.hpp> + +#if !defined(BOOST_NO_SFINAE) + +#include <boost/utility/enable_if.hpp> +#include <boost/type_traits/is_arithmetic.hpp> + +namespace boost { +namespace random { +namespace detail { + +template<class T> +struct disable_seed : boost::disable_if<boost::is_arithmetic<T> > {}; + +template<class Engine, class T> +struct disable_constructor : disable_seed<T> {}; + +template<class Engine> +struct disable_constructor<Engine, Engine> { +}; + +#define BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \ + template<class Generator> \ + explicit Self(Generator& gen, typename ::boost::random::detail::disable_constructor<Self, Generator>::type* = 0) + +#define BOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \ + template<class Generator> \ + void seed(Generator& gen, typename ::boost::random::detail::disable_seed<Generator>::type* = 0) + +#define BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \ + explicit Self(const T& x) + +#define BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \ + void seed(const T& x) + +} +} +} + +#else + +#include <boost/type_traits/is_arithmetic.hpp> +#include <boost/mpl/bool.hpp> + +#define BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \ + Self(Self& other) { *this = other; } \ + Self(const Self& other) { *this = other; } \ + template<class Generator> \ + explicit Self(Generator& gen) { \ + boost_random_constructor_impl(gen, ::boost::is_arithmetic<Generator>());\ + } \ + template<class Generator> \ + void boost_random_constructor_impl(Generator& gen, ::boost::mpl::false_) + +#define BOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \ + template<class Generator> \ + void seed(Generator& gen) { \ + boost_random_seed_impl(gen, ::boost::is_arithmetic<Generator>());\ + }\ + template<class Generator>\ + void boost_random_seed_impl(Generator& gen, ::boost::mpl::false_) + +#define BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \ + explicit Self(const T& x) { boost_random_constructor_impl(x, ::boost::mpl::true_()); }\ + void boost_random_constructor_impl(const T& x, ::boost::mpl::true_) + +#define BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \ + void seed(const T& x) { boost_random_seed_impl(x, ::boost::mpl::true_()); }\ + void boost_random_seed_impl(const T& x, ::boost::mpl::true_) + +#endif + +#endif diff --git a/Utilities/BGL/boost/random/detail/signed_unsigned_tools.hpp b/Utilities/BGL/boost/random/detail/signed_unsigned_tools.hpp new file mode 100755 index 0000000000000000000000000000000000000000..c1344a3dec9495b05e03c8cd09e53813b7a8de79 --- /dev/null +++ b/Utilities/BGL/boost/random/detail/signed_unsigned_tools.hpp @@ -0,0 +1,89 @@ +/* boost random/detail/signed_unsigned_tools.hpp header file + * + * Copyright Jens Maurer 2006 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + */ + +#ifndef BOOST_RANDOM_DETAIL_SIGNED_UNSIGNED_TOOLS +#define BOOST_RANDOM_DETAIL_SIGNED_UNSIGNED_TOOLS + +#include <boost/limits.hpp> +#include <boost/config.hpp> +#include <boost/type_traits/make_unsigned.hpp> + +namespace boost { +namespace random { +namespace detail { + + +/* + * Compute x - y, we know that x >= y, return an unsigned value. + */ + +template<class T, bool sgn = std::numeric_limits<T>::is_signed> +struct subtract { }; + +template<class T> +struct subtract<T, /* signed */ false> +{ + typedef T result_type; + result_type operator()(T x, T y) { return x - y; } +}; + +template<class T> +struct subtract<T, /* signed */ true> +{ + typedef typename make_unsigned<T>::type result_type; + result_type operator()(T x, T y) + { + if (y >= 0) // because x >= y, it follows that x >= 0, too + return result_type(x) - result_type(y); + if (x >= 0) // y < 0 + // avoid the nasty two's complement case for y == min() + return result_type(x) + result_type(-(y+1)) + 1; + // both x and y are negative: no signed overflow + return result_type(x - y); + } +}; + +/* + * Compute x + y, x is unsigned, result fits in type of "y". + */ + +template<class T1, class T2, bool sgn = std::numeric_limits<T2>::is_signed> +struct add { }; + +template<class T1, class T2> +struct add<T1, T2, /* signed */ false> +{ + typedef T2 result_type; + result_type operator()(T1 x, T2 y) { return T2(x) + y; } +}; + +template<class T1, class T2> +struct add<T1, T2, /* signed */ true> +{ + typedef T2 result_type; + result_type operator()(T1 x, T2 y) + { + if (y >= 0) + return T2(x) + y; + // y < 0 + if (x >= T1(-(y+1))) // result >= 0 after subtraction + // avoid the nasty two's complement edge case for y == min() + return T2(x - T1(-(y+1)) - 1); + // abs(x) < abs(y), thus T2 able to represent x + return T2(x) + y; + } +}; + +} // namespace detail +} // namespace random +} // namespace boost + +#endif // BOOST_RANDOM_DETAIL_SIGNED_UNSIGNED_TOOLS + diff --git a/Utilities/BGL/boost/random/detail/uniform_int_float.hpp b/Utilities/BGL/boost/random/detail/uniform_int_float.hpp new file mode 100755 index 0000000000000000000000000000000000000000..8475f1bf7dcf1c49f5ba2a49e73c89aaa136e32a --- /dev/null +++ b/Utilities/BGL/boost/random/detail/uniform_int_float.hpp @@ -0,0 +1,85 @@ +/* boost random/detail/uniform_int_float.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: uniform_int_float.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $ + * + */ + +#ifndef BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP +#define BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP + +#include <boost/config.hpp> +#include <boost/random/detail/config.hpp> +#include <boost/random/uniform_01.hpp> + + +namespace boost { +namespace random { +namespace detail { + +template<class UniformRandomNumberGenerator, class IntType = unsigned long> +class uniform_int_float +{ +public: + typedef UniformRandomNumberGenerator base_type; + typedef IntType result_type; + + uniform_int_float(base_type rng, IntType min_arg = 0, IntType max_arg = 0xffffffff) + : _rng(rng), _min(min_arg), _max(max_arg) + { + init(); + } + + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; } + base_type& base() { return _rng.base(); } + const base_type& base() const { return _rng.base(); } + + result_type operator()() + { + return static_cast<IntType>(_rng() * _range) + _min; + } + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const uniform_int_float& ud) + { + os << ud._min << " " << ud._max; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, uniform_int_float& ud) + { + is >> std::ws >> ud._min >> std::ws >> ud._max; + ud.init(); + return is; + } +#endif + +private: + void init() + { + _range = static_cast<base_result>(_max-_min)+1; + } + + typedef typename base_type::result_type base_result; + uniform_01<base_type> _rng; + result_type _min, _max; + base_result _range; +}; + + +} // namespace detail +} // namespace random +} // namespace boost + +#endif // BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP diff --git a/Utilities/BGL/boost/random/discard_block.hpp b/Utilities/BGL/boost/random/discard_block.hpp new file mode 100755 index 0000000000000000000000000000000000000000..100115cafab2f6030a6e3ce8b8e6e1e794ba5e2e --- /dev/null +++ b/Utilities/BGL/boost/random/discard_block.hpp @@ -0,0 +1,123 @@ +/* boost random/discard_block.hpp header file + * + * Copyright Jens Maurer 2002 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: discard_block.hpp 53871 2009-06-13 17:54:06Z steven_watanabe $ + * + * Revision history + * 2001-03-02 created + */ + +#ifndef BOOST_RANDOM_DISCARD_BLOCK_HPP +#define BOOST_RANDOM_DISCARD_BLOCK_HPP + +#include <iostream> +#include <boost/config.hpp> +#include <boost/limits.hpp> +#include <boost/static_assert.hpp> +#include <boost/random/detail/config.hpp> + + +namespace boost { +namespace random { + +template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r> +class discard_block +{ +public: + typedef UniformRandomNumberGenerator base_type; + typedef typename base_type::result_type result_type; + + BOOST_STATIC_CONSTANT(bool, has_fixed_range = false); + BOOST_STATIC_CONSTANT(unsigned int, total_block = p); + BOOST_STATIC_CONSTANT(unsigned int, returned_block = r); + +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT(total_block >= returned_block); +#endif + + discard_block() : _rng(), _n(0) { } + explicit discard_block(const base_type & rng) : _rng(rng), _n(0) { } + template<class T> explicit discard_block(T s) : _rng(s), _n(0) {} + template<class It> discard_block(It& first, It last) + : _rng(first, last), _n(0) { } + void seed() { _rng.seed(); _n = 0; } + template<class T> void seed(T s) { _rng.seed(s); _n = 0; } + template<class It> void seed(It& first, It last) + { _n = 0; _rng.seed(first, last); } + + const base_type& base() const { return _rng; } + + result_type operator()() + { + if(_n >= returned_block) { + // discard values of random number generator + for( ; _n < total_block; ++_n) + _rng(); + _n = 0; + } + ++_n; + return _rng(); + } + + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_rng.min)(); } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_rng.max)(); } + static bool validation(result_type x) { return true; } // dummy + +#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const discard_block& s) + { + os << s._rng << " " << s._n << " "; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, discard_block& s) + { + is >> s._rng >> std::ws >> s._n >> std::ws; + return is; + } +#endif + + friend bool operator==(const discard_block& x, const discard_block& y) + { return x._rng == y._rng && x._n == y._n; } + friend bool operator!=(const discard_block& x, const discard_block& y) + { return !(x == y); } +#else + // Use a member function; Streamable concept not supported. + bool operator==(const discard_block& rhs) const + { return _rng == rhs._rng && _n == rhs._n; } + bool operator!=(const discard_block& rhs) const + { return !(*this == rhs); } +#endif + +private: + base_type _rng; + unsigned int _n; +}; + +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION +// A definition is required even for integral static constants +template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r> +const bool discard_block<UniformRandomNumberGenerator, p, r>::has_fixed_range; +template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r> +const unsigned int discard_block<UniformRandomNumberGenerator, p, r>::total_block; +template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r> +const unsigned int discard_block<UniformRandomNumberGenerator, p, r>::returned_block; +#endif + +} // namespace random + +} // namespace boost + +#endif // BOOST_RANDOM_DISCARD_BLOCK_HPP diff --git a/Utilities/BGL/boost/random/exponential_distribution.hpp b/Utilities/BGL/boost/random/exponential_distribution.hpp new file mode 100755 index 0000000000000000000000000000000000000000..8a6fc643e10d55d945ad611443f697f9299bb0f5 --- /dev/null +++ b/Utilities/BGL/boost/random/exponential_distribution.hpp @@ -0,0 +1,82 @@ +/* boost random/exponential_distribution.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: exponential_distribution.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $ + * + * Revision history + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP +#define BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP + +#include <boost/config/no_tr1/cmath.hpp> +#include <cassert> +#include <iostream> +#include <boost/limits.hpp> +#include <boost/static_assert.hpp> +#include <boost/random/detail/config.hpp> + +namespace boost { + +// exponential distribution: p(x) = lambda * exp(-lambda * x) +template<class RealType = double> +class exponential_distribution +{ +public: + typedef RealType input_type; + typedef RealType result_type; + +#if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300) + BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer); +#endif + + explicit exponential_distribution(result_type lambda_arg = result_type(1)) + : _lambda(lambda_arg) { assert(_lambda > result_type(0)); } + + // compiler-generated copy ctor and assignment operator are fine + + result_type lambda() const { return _lambda; } + + void reset() { } + + template<class Engine> + result_type operator()(Engine& eng) + { +#ifndef BOOST_NO_STDC_NAMESPACE + using std::log; +#endif + return -result_type(1) / _lambda * log(result_type(1)-eng()); + } + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const exponential_distribution& ed) + { + os << ed._lambda; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, exponential_distribution& ed) + { + is >> std::ws >> ed._lambda; + return is; + } +#endif + +private: + result_type _lambda; +}; + +} // namespace boost + +#endif // BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP diff --git a/Utilities/BGL/boost/random/gamma_distribution.hpp b/Utilities/BGL/boost/random/gamma_distribution.hpp new file mode 100755 index 0000000000000000000000000000000000000000..fca86449e097ac14f8b1ed7190aec4d67a3e0be4 --- /dev/null +++ b/Utilities/BGL/boost/random/gamma_distribution.hpp @@ -0,0 +1,134 @@ +/* boost random/gamma_distribution.hpp header file + * + * Copyright Jens Maurer 2002 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: gamma_distribution.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $ + * + */ + +#ifndef BOOST_RANDOM_GAMMA_DISTRIBUTION_HPP +#define BOOST_RANDOM_GAMMA_DISTRIBUTION_HPP + +#include <boost/config/no_tr1/cmath.hpp> +#include <cassert> +#include <boost/limits.hpp> +#include <boost/static_assert.hpp> +#include <boost/random/detail/config.hpp> +#include <boost/random/exponential_distribution.hpp> + +namespace boost { + +// Knuth +template<class RealType = double> +class gamma_distribution +{ +public: + typedef RealType input_type; + typedef RealType result_type; + +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer); +#endif + + explicit gamma_distribution(const result_type& alpha_arg = result_type(1)) + : _exp(result_type(1)), _alpha(alpha_arg) + { + assert(_alpha > result_type(0)); + init(); + } + + // compiler-generated copy ctor and assignment operator are fine + + RealType alpha() const { return _alpha; } + + void reset() { _exp.reset(); } + + template<class Engine> + result_type operator()(Engine& eng) + { +#ifndef BOOST_NO_STDC_NAMESPACE + // allow for Koenig lookup + using std::tan; using std::sqrt; using std::exp; using std::log; + using std::pow; +#endif + if(_alpha == result_type(1)) { + return _exp(eng); + } else if(_alpha > result_type(1)) { + // Can we have a boost::mathconst please? + const result_type pi = result_type(3.14159265358979323846); + for(;;) { + result_type y = tan(pi * eng()); + result_type x = sqrt(result_type(2)*_alpha-result_type(1))*y + + _alpha-result_type(1); + if(x <= result_type(0)) + continue; + if(eng() > + (result_type(1)+y*y) * exp((_alpha-result_type(1)) + *log(x/(_alpha-result_type(1))) + - sqrt(result_type(2)*_alpha + -result_type(1))*y)) + continue; + return x; + } + } else /* alpha < 1.0 */ { + for(;;) { + result_type u = eng(); + result_type y = _exp(eng); + result_type x, q; + if(u < _p) { + x = exp(-y/_alpha); + q = _p*exp(-x); + } else { + x = result_type(1)+y; + q = _p + (result_type(1)-_p) * pow(x, _alpha-result_type(1)); + } + if(u >= q) + continue; + return x; + } + } + } + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const gamma_distribution& gd) + { + os << gd._alpha; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, gamma_distribution& gd) + { + is >> std::ws >> gd._alpha; + gd.init(); + return is; + } +#endif + +private: + void init() + { +#ifndef BOOST_NO_STDC_NAMESPACE + // allow for Koenig lookup + using std::exp; +#endif + _p = exp(result_type(1)) / (_alpha + exp(result_type(1))); + } + + exponential_distribution<RealType> _exp; + result_type _alpha; + // some data precomputed from the parameters + result_type _p; +}; + +} // namespace boost + +#endif // BOOST_RANDOM_GAMMA_DISTRIBUTION_HPP diff --git a/Utilities/BGL/boost/random/geometric_distribution.hpp b/Utilities/BGL/boost/random/geometric_distribution.hpp new file mode 100755 index 0000000000000000000000000000000000000000..261bd471c9bbce8672493e9fef8b7c0587d8b150 --- /dev/null +++ b/Utilities/BGL/boost/random/geometric_distribution.hpp @@ -0,0 +1,98 @@ +/* boost random/geometric_distribution.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: geometric_distribution.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $ + * + * Revision history + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_GEOMETRIC_DISTRIBUTION_HPP +#define BOOST_RANDOM_GEOMETRIC_DISTRIBUTION_HPP + +#include <boost/config/no_tr1/cmath.hpp> // std::log +#include <cassert> +#include <iostream> +#include <boost/random/detail/config.hpp> +#include <boost/random/uniform_01.hpp> + +namespace boost { + +#if defined(__GNUC__) && (__GNUC__ < 3) +// Special gcc workaround: gcc 2.95.x ignores using-declarations +// in template classes (confirmed by gcc author Martin v. Loewis) + using std::log; +#endif + +// geometric distribution: p(i) = (1-p) * pow(p, i-1) (integer) +template<class IntType = int, class RealType = double> +class geometric_distribution +{ +public: + typedef RealType input_type; + typedef IntType result_type; + + explicit geometric_distribution(const RealType& p_arg = RealType(0.5)) + : _p(p_arg) + { + assert(RealType(0) < _p && _p < RealType(1)); + init(); + } + + // compiler-generated copy ctor and assignment operator are fine + + RealType p() const { return _p; } + void reset() { } + + template<class Engine> + result_type operator()(Engine& eng) + { +#ifndef BOOST_NO_STDC_NAMESPACE + using std::log; + using std::floor; +#endif + return IntType(floor(log(RealType(1)-eng()) / _log_p)) + IntType(1); + } + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const geometric_distribution& gd) + { + os << gd._p; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, geometric_distribution& gd) + { + is >> std::ws >> gd._p; + gd.init(); + return is; + } +#endif + +private: + void init() + { +#ifndef BOOST_NO_STDC_NAMESPACE + using std::log; +#endif + _log_p = log(_p); + } + + RealType _p; + RealType _log_p; +}; + +} // namespace boost + +#endif // BOOST_RANDOM_GEOMETRIC_DISTRIBUTION_HPP + diff --git a/Utilities/BGL/boost/random/inversive_congruential.hpp b/Utilities/BGL/boost/random/inversive_congruential.hpp new file mode 100755 index 0000000000000000000000000000000000000000..294cd5232086c7f4f5b13dd9087fc93e7127be1a --- /dev/null +++ b/Utilities/BGL/boost/random/inversive_congruential.hpp @@ -0,0 +1,129 @@ +/* boost random/inversive_congruential.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: inversive_congruential.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $ + * + * Revision history + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_INVERSIVE_CONGRUENTIAL_HPP +#define BOOST_RANDOM_INVERSIVE_CONGRUENTIAL_HPP + +#include <iostream> +#include <cassert> +#include <stdexcept> +#include <boost/config.hpp> +#include <boost/static_assert.hpp> +#include <boost/random/detail/config.hpp> +#include <boost/random/detail/const_mod.hpp> + +namespace boost { +namespace random { + +// Eichenauer and Lehn 1986 +template<class IntType, IntType a, IntType b, IntType p, IntType val> +class inversive_congruential +{ +public: + typedef IntType result_type; +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION + static const bool has_fixed_range = true; + static const result_type min_value = (b == 0 ? 1 : 0); + static const result_type max_value = p-1; +#else + BOOST_STATIC_CONSTANT(bool, has_fixed_range = false); +#endif + BOOST_STATIC_CONSTANT(result_type, multiplier = a); + BOOST_STATIC_CONSTANT(result_type, increment = b); + BOOST_STATIC_CONSTANT(result_type, modulus = p); + + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return b == 0 ? 1 : 0; } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return p-1; } + + explicit inversive_congruential(IntType y0 = 1) : value(y0) + { + BOOST_STATIC_ASSERT(b >= 0); + BOOST_STATIC_ASSERT(p > 1); + BOOST_STATIC_ASSERT(a >= 1); + if(b == 0) + assert(y0 > 0); + } + template<class It> inversive_congruential(It& first, It last) + { seed(first, last); } + + void seed(IntType y0 = 1) { value = y0; if(b == 0) assert(y0 > 0); } + template<class It> void seed(It& first, It last) + { + if(first == last) + throw std::invalid_argument("inversive_congruential::seed"); + value = *first++; + } + IntType operator()() + { + typedef const_mod<IntType, p> do_mod; + value = do_mod::mult_add(a, do_mod::invert(value), b); + return value; + } + + static bool validation(result_type x) { return val == x; } + +#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, inversive_congruential x) + { os << x.value; return os; } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, inversive_congruential& x) + { is >> x.value; return is; } +#endif + + friend bool operator==(inversive_congruential x, inversive_congruential y) + { return x.value == y.value; } + friend bool operator!=(inversive_congruential x, inversive_congruential y) + { return !(x == y); } +#else + // Use a member function; Streamable concept not supported. + bool operator==(inversive_congruential rhs) const + { return value == rhs.value; } + bool operator!=(inversive_congruential rhs) const + { return !(*this == rhs); } +#endif +private: + IntType value; +}; + +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION +// A definition is required even for integral static constants +template<class IntType, IntType a, IntType b, IntType p, IntType val> +const bool inversive_congruential<IntType, a, b, p, val>::has_fixed_range; +template<class IntType, IntType a, IntType b, IntType p, IntType val> +const typename inversive_congruential<IntType, a, b, p, val>::result_type inversive_congruential<IntType, a, b, p, val>::min_value; +template<class IntType, IntType a, IntType b, IntType p, IntType val> +const typename inversive_congruential<IntType, a, b, p, val>::result_type inversive_congruential<IntType, a, b, p, val>::max_value; +template<class IntType, IntType a, IntType b, IntType p, IntType val> +const typename inversive_congruential<IntType, a, b, p, val>::result_type inversive_congruential<IntType, a, b, p, val>::multiplier; +template<class IntType, IntType a, IntType b, IntType p, IntType val> +const typename inversive_congruential<IntType, a, b, p, val>::result_type inversive_congruential<IntType, a, b, p, val>::increment; +template<class IntType, IntType a, IntType b, IntType p, IntType val> +const typename inversive_congruential<IntType, a, b, p, val>::result_type inversive_congruential<IntType, a, b, p, val>::modulus; +#endif + +} // namespace random + +typedef random::inversive_congruential<int32_t, 9102, 2147483647-36884165, + 2147483647, 0> hellekalek1995; + +} // namespace boost + +#endif // BOOST_RANDOM_INVERSIVE_CONGRUENTIAL_HPP diff --git a/Utilities/BGL/boost/random/lagged_fibonacci.hpp b/Utilities/BGL/boost/random/lagged_fibonacci.hpp new file mode 100755 index 0000000000000000000000000000000000000000..4c46ed2f956bfd04978ade1c02a0aabad3baf606 --- /dev/null +++ b/Utilities/BGL/boost/random/lagged_fibonacci.hpp @@ -0,0 +1,469 @@ +/* boost random/lagged_fibonacci.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: lagged_fibonacci.hpp 53871 2009-06-13 17:54:06Z steven_watanabe $ + * + * Revision history + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_LAGGED_FIBONACCI_HPP +#define BOOST_RANDOM_LAGGED_FIBONACCI_HPP + +#include <boost/config/no_tr1/cmath.hpp> +#include <iostream> +#include <algorithm> // std::max +#include <iterator> +#include <boost/config/no_tr1/cmath.hpp> // std::pow +#include <boost/config.hpp> +#include <boost/limits.hpp> +#include <boost/cstdint.hpp> +#include <boost/detail/workaround.hpp> +#include <boost/random/linear_congruential.hpp> +#include <boost/random/uniform_01.hpp> +#include <boost/random/detail/config.hpp> +#include <boost/random/detail/seed.hpp> +#include <boost/random/detail/pass_through_engine.hpp> + +namespace boost { +namespace random { + +#if BOOST_WORKAROUND(_MSC_FULL_VER, BOOST_TESTED_AT(13102292)) && BOOST_MSVC > 1300 +# define BOOST_RANDOM_EXTRACT_LF +#endif + +#if defined(__APPLE_CC__) && defined(__GNUC__) && (__GNUC__ == 3) && (__GNUC_MINOR__ <= 3) +# define BOOST_RANDOM_EXTRACT_LF +#endif + +# ifdef BOOST_RANDOM_EXTRACT_LF +namespace detail +{ + template<class IStream, class F, class RealType> + IStream& + extract_lagged_fibonacci_01( + IStream& is + , F const& f + , unsigned int& i + , RealType* x + , RealType modulus) + { + is >> i >> std::ws; + for(unsigned int i = 0; i < f.long_lag; ++i) + { + RealType value; + is >> value >> std::ws; + x[i] = value / modulus; + } + return is; + } + + template<class IStream, class F, class UIntType> + IStream& + extract_lagged_fibonacci( + IStream& is + , F const& f + , unsigned int& i + , UIntType* x) + { + is >> i >> std::ws; + for(unsigned int i = 0; i < f.long_lag; ++i) + is >> x[i] >> std::ws; + return is; + } +} +# endif + +template<class UIntType, int w, unsigned int p, unsigned int q, + UIntType val = 0> +class lagged_fibonacci +{ +public: + typedef UIntType result_type; + BOOST_STATIC_CONSTANT(bool, has_fixed_range = false); + BOOST_STATIC_CONSTANT(int, word_size = w); + BOOST_STATIC_CONSTANT(unsigned int, long_lag = p); + BOOST_STATIC_CONSTANT(unsigned int, short_lag = q); + + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 0; } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return wordmask; } + + lagged_fibonacci() { init_wordmask(); seed(); } + explicit lagged_fibonacci(uint32_t value) { init_wordmask(); seed(value); } + template<class It> lagged_fibonacci(It& first, It last) + { init_wordmask(); seed(first, last); } + // compiler-generated copy ctor and assignment operator are fine + +private: + void init_wordmask() + { + wordmask = 0; + for(int j = 0; j < w; ++j) + wordmask |= (1u << j); + } + +public: + void seed(uint32_t value = 331u) + { + minstd_rand0 gen(value); + for(unsigned int j = 0; j < long_lag; ++j) + x[j] = gen() & wordmask; + i = long_lag; + } + + template<class It> + void seed(It& first, It last) + { + // word size could be smaller than the seed values + unsigned int j; + for(j = 0; j < long_lag && first != last; ++j, ++first) + x[j] = *first & wordmask; + i = long_lag; + if(first == last && j < long_lag) + throw std::invalid_argument("lagged_fibonacci::seed"); + } + + result_type operator()() + { + if(i >= long_lag) + fill(); + return x[i++]; + } + + static bool validation(result_type x) + { + return x == val; + } + +#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const lagged_fibonacci& f) + { + os << f.i << " "; + for(unsigned int i = 0; i < f.long_lag; ++i) + os << f.x[i] << " "; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT, Traits>& + operator>>(std::basic_istream<CharT, Traits>& is, lagged_fibonacci& f) + { +# ifdef BOOST_RANDOM_EXTRACT_LF + return detail::extract_lagged_fibonacci(is, f, f.i, f.x); +# else + is >> f.i >> std::ws; + for(unsigned int i = 0; i < f.long_lag; ++i) + is >> f.x[i] >> std::ws; + return is; +# endif + } +#endif + + friend bool operator==(const lagged_fibonacci& x, const lagged_fibonacci& y) + { return x.i == y.i && std::equal(x.x, x.x+long_lag, y.x); } + friend bool operator!=(const lagged_fibonacci& x, + const lagged_fibonacci& y) + { return !(x == y); } +#else + // Use a member function; Streamable concept not supported. + bool operator==(const lagged_fibonacci& rhs) const + { return i == rhs.i && std::equal(x, x+long_lag, rhs.x); } + bool operator!=(const lagged_fibonacci& rhs) const + { return !(*this == rhs); } +#endif + +private: + void fill(); + UIntType wordmask; + unsigned int i; + UIntType x[long_lag]; +}; + +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION +// A definition is required even for integral static constants +template<class UIntType, int w, unsigned int p, unsigned int q, UIntType val> +const bool lagged_fibonacci<UIntType, w, p, q, val>::has_fixed_range; +template<class UIntType, int w, unsigned int p, unsigned int q, UIntType val> +const unsigned int lagged_fibonacci<UIntType, w, p, q, val>::long_lag; +template<class UIntType, int w, unsigned int p, unsigned int q, UIntType val> +const unsigned int lagged_fibonacci<UIntType, w, p, q, val>::short_lag; +#endif + +template<class UIntType, int w, unsigned int p, unsigned int q, UIntType val> +void lagged_fibonacci<UIntType, w, p, q, val>::fill() +{ + // two loops to avoid costly modulo operations + { // extra scope for MSVC brokenness w.r.t. for scope + for(unsigned int j = 0; j < short_lag; ++j) + x[j] = (x[j] + x[j+(long_lag-short_lag)]) & wordmask; + } + for(unsigned int j = short_lag; j < long_lag; ++j) + x[j] = (x[j] + x[j-short_lag]) & wordmask; + i = 0; +} + + + +// lagged Fibonacci generator for the range [0..1) +// contributed by Matthias Troyer +// for p=55, q=24 originally by G. J. Mitchell and D. P. Moore 1958 + +template<class T, unsigned int p, unsigned int q> +struct fibonacci_validation +{ + BOOST_STATIC_CONSTANT(bool, is_specialized = false); + static T value() { return 0; } + static T tolerance() { return 0; } +}; + +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION +// A definition is required even for integral static constants +template<class T, unsigned int p, unsigned int q> +const bool fibonacci_validation<T, p, q>::is_specialized; +#endif + +#define BOOST_RANDOM_FIBONACCI_VAL(T,P,Q,V,E) \ +template<> \ +struct fibonacci_validation<T, P, Q> \ +{ \ + BOOST_STATIC_CONSTANT(bool, is_specialized = true); \ + static T value() { return V; } \ + static T tolerance() \ +{ return (std::max)(E, static_cast<T>(5*std::numeric_limits<T>::epsilon())); } \ +}; +// (The extra static_cast<T> in the std::max call above is actually +// unnecessary except for HP aCC 1.30, which claims that +// numeric_limits<double>::epsilon() doesn't actually return a double.) + +BOOST_RANDOM_FIBONACCI_VAL(double, 607, 273, 0.4293817707235914, 1e-14) +BOOST_RANDOM_FIBONACCI_VAL(double, 1279, 418, 0.9421630240437659, 1e-14) +BOOST_RANDOM_FIBONACCI_VAL(double, 2281, 1252, 0.1768114046909004, 1e-14) +BOOST_RANDOM_FIBONACCI_VAL(double, 3217, 576, 0.1956232694868209, 1e-14) +BOOST_RANDOM_FIBONACCI_VAL(double, 4423, 2098, 0.9499762202147172, 1e-14) +BOOST_RANDOM_FIBONACCI_VAL(double, 9689, 5502, 0.05737836943695162, 1e-14) +BOOST_RANDOM_FIBONACCI_VAL(double, 19937, 9842, 0.5076528587449834, 1e-14) +BOOST_RANDOM_FIBONACCI_VAL(double, 23209, 13470, 0.5414473810619185, 1e-14) +BOOST_RANDOM_FIBONACCI_VAL(double, 44497,21034, 0.254135073399297, 1e-14) + +#undef BOOST_RANDOM_FIBONACCI_VAL + +template<class RealType, int w, unsigned int p, unsigned int q> +class lagged_fibonacci_01 +{ +public: + typedef RealType result_type; + BOOST_STATIC_CONSTANT(bool, has_fixed_range = false); + BOOST_STATIC_CONSTANT(int, word_size = w); + BOOST_STATIC_CONSTANT(unsigned int, long_lag = p); + BOOST_STATIC_CONSTANT(unsigned int, short_lag = q); + + lagged_fibonacci_01() { init_modulus(); seed(); } + BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(lagged_fibonacci_01, uint32_t, value) + { init_modulus(); seed(value); } + BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(lagged_fibonacci_01, Generator, gen) + { init_modulus(); seed(gen); } + template<class It> lagged_fibonacci_01(It& first, It last) + { init_modulus(); seed(first, last); } + // compiler-generated copy ctor and assignment operator are fine + +private: + void init_modulus() + { +#ifndef BOOST_NO_STDC_NAMESPACE + // allow for Koenig lookup + using std::pow; +#endif + _modulus = pow(RealType(2), word_size); + } + +public: + void seed() { seed(331u); } + BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(lagged_fibonacci_01, uint32_t, value) + { + minstd_rand0 intgen(value); + seed(intgen); + } + + // For GCC, moving this function out-of-line prevents inlining, which may + // reduce overall object code size. However, MSVC does not grok + // out-of-line template member functions. + BOOST_RANDOM_DETAIL_GENERATOR_SEED(lagged_fibonacci, Generator, gen) + { + // use pass-by-reference, but wrap argument in pass_through_engine + typedef detail::pass_through_engine<Generator&> ref_gen; + uniform_01<ref_gen, RealType> gen01 = + uniform_01<ref_gen, RealType>(ref_gen(gen)); + // I could have used std::generate_n, but it takes "gen" by value + for(unsigned int j = 0; j < long_lag; ++j) + x[j] = gen01(); + i = long_lag; + } + + template<class It> + void seed(It& first, It last) + { +#ifndef BOOST_NO_STDC_NAMESPACE + // allow for Koenig lookup + using std::fmod; + using std::pow; +#endif + unsigned long mask = ~((~0u) << (w%32)); // now lowest w bits set + RealType two32 = pow(RealType(2), 32); + unsigned int j; + for(j = 0; j < long_lag && first != last; ++j) { + x[j] = RealType(0); + for(int k = 0; k < w/32 && first != last; ++k, ++first) + x[j] += *first / pow(two32,k+1); + if(first != last && mask != 0) { + x[j] += fmod((*first & mask) / _modulus, RealType(1)); + ++first; + } + } + i = long_lag; + if(first == last && j < long_lag) + throw std::invalid_argument("lagged_fibonacci_01::seed"); + } + + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(0); } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(1); } + + result_type operator()() + { + if(i >= long_lag) + fill(); + return x[i++]; + } + + static bool validation(result_type x) + { + result_type v = fibonacci_validation<result_type, p, q>::value(); + result_type epsilon = fibonacci_validation<result_type, p, q>::tolerance(); + // std::abs is a source of trouble: sometimes, it's not overloaded + // for double, plus the usual namespace std noncompliance -> avoid it + // using std::abs; + // return abs(x - v) < 5 * epsilon + return x > v - epsilon && x < v + epsilon; + } + +#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const lagged_fibonacci_01&f) + { +#ifndef BOOST_NO_STDC_NAMESPACE + // allow for Koenig lookup + using std::pow; +#endif + os << f.i << " "; + std::ios_base::fmtflags oldflags = os.flags(os.dec | os.fixed | os.left); + for(unsigned int i = 0; i < f.long_lag; ++i) + os << f.x[i] * f._modulus << " "; + os.flags(oldflags); + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT, Traits>& + operator>>(std::basic_istream<CharT, Traits>& is, lagged_fibonacci_01& f) + { +# ifdef BOOST_RANDOM_EXTRACT_LF + return detail::extract_lagged_fibonacci_01(is, f, f.i, f.x, f._modulus); +# else + is >> f.i >> std::ws; + for(unsigned int i = 0; i < f.long_lag; ++i) { + typename lagged_fibonacci_01::result_type value; + is >> value >> std::ws; + f.x[i] = value / f._modulus; + } + return is; +# endif + } +#endif + + friend bool operator==(const lagged_fibonacci_01& x, + const lagged_fibonacci_01& y) + { return x.i == y.i && std::equal(x.x, x.x+long_lag, y.x); } + friend bool operator!=(const lagged_fibonacci_01& x, + const lagged_fibonacci_01& y) + { return !(x == y); } +#else + // Use a member function; Streamable concept not supported. + bool operator==(const lagged_fibonacci_01& rhs) const + { return i == rhs.i && std::equal(x, x+long_lag, rhs.x); } + bool operator!=(const lagged_fibonacci_01& rhs) const + { return !(*this == rhs); } +#endif + +private: + void fill(); + unsigned int i; + RealType x[long_lag]; + RealType _modulus; +}; + +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION +// A definition is required even for integral static constants +template<class RealType, int w, unsigned int p, unsigned int q> +const bool lagged_fibonacci_01<RealType, w, p, q>::has_fixed_range; +template<class RealType, int w, unsigned int p, unsigned int q> +const unsigned int lagged_fibonacci_01<RealType, w, p, q>::long_lag; +template<class RealType, int w, unsigned int p, unsigned int q> +const unsigned int lagged_fibonacci_01<RealType, w, p, q>::short_lag; +template<class RealType, int w, unsigned int p, unsigned int q> +const int lagged_fibonacci_01<RealType,w,p,q>::word_size; + +#endif + +template<class RealType, int w, unsigned int p, unsigned int q> +void lagged_fibonacci_01<RealType, w, p, q>::fill() +{ + // two loops to avoid costly modulo operations + { // extra scope for MSVC brokenness w.r.t. for scope + for(unsigned int j = 0; j < short_lag; ++j) { + RealType t = x[j] + x[j+(long_lag-short_lag)]; + if(t >= RealType(1)) + t -= RealType(1); + x[j] = t; + } + } + for(unsigned int j = short_lag; j < long_lag; ++j) { + RealType t = x[j] + x[j-short_lag]; + if(t >= RealType(1)) + t -= RealType(1); + x[j] = t; + } + i = 0; +} + +} // namespace random + +typedef random::lagged_fibonacci_01<double, 48, 607, 273> lagged_fibonacci607; +typedef random::lagged_fibonacci_01<double, 48, 1279, 418> lagged_fibonacci1279; +typedef random::lagged_fibonacci_01<double, 48, 2281, 1252> lagged_fibonacci2281; +typedef random::lagged_fibonacci_01<double, 48, 3217, 576> lagged_fibonacci3217; +typedef random::lagged_fibonacci_01<double, 48, 4423, 2098> lagged_fibonacci4423; +typedef random::lagged_fibonacci_01<double, 48, 9689, 5502> lagged_fibonacci9689; +typedef random::lagged_fibonacci_01<double, 48, 19937, 9842> lagged_fibonacci19937; +typedef random::lagged_fibonacci_01<double, 48, 23209, 13470> lagged_fibonacci23209; +typedef random::lagged_fibonacci_01<double, 48, 44497, 21034> lagged_fibonacci44497; + + +// It is possible to partially specialize uniform_01<> on lagged_fibonacci_01<> +// to help the compiler generate efficient code. For GCC, this seems useless, +// because GCC optimizes (x-0)/(1-0) to (x-0). This is good enough for now. + +} // namespace boost + +#endif // BOOST_RANDOM_LAGGED_FIBONACCI_HPP diff --git a/Utilities/BGL/boost/random/linear_congruential.hpp b/Utilities/BGL/boost/random/linear_congruential.hpp new file mode 100755 index 0000000000000000000000000000000000000000..71e186b2b4ab3f661d55cd081af73673e67a5e42 --- /dev/null +++ b/Utilities/BGL/boost/random/linear_congruential.hpp @@ -0,0 +1,284 @@ +/* boost random/linear_congruential.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: linear_congruential.hpp 58649 2010-01-02 21:23:17Z steven_watanabe $ + * + * Revision history + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_LINEAR_CONGRUENTIAL_HPP +#define BOOST_RANDOM_LINEAR_CONGRUENTIAL_HPP + +#include <iostream> +#include <cassert> +#include <stdexcept> +#include <boost/config.hpp> +#include <boost/limits.hpp> +#include <boost/static_assert.hpp> +#include <boost/random/detail/config.hpp> +#include <boost/random/detail/const_mod.hpp> +#include <boost/detail/workaround.hpp> + +#include <boost/random/detail/disable_warnings.hpp> + +namespace boost { +namespace random { + +// compile-time configurable linear congruential generator +template<class IntType, IntType a, IntType c, IntType m, IntType val> +class linear_congruential +{ +public: + typedef IntType result_type; +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION + static const bool has_fixed_range = true; + static const result_type min_value = ( c == 0 ? 1 : 0 ); + static const result_type max_value = m-1; +#else + BOOST_STATIC_CONSTANT(bool, has_fixed_range = false); +#endif + BOOST_STATIC_CONSTANT(IntType, multiplier = a); + BOOST_STATIC_CONSTANT(IntType, increment = c); + BOOST_STATIC_CONSTANT(IntType, modulus = m); + + // MSVC 6 and possibly others crash when encountering complicated integral + // constant expressions. Avoid the check for now. + // BOOST_STATIC_ASSERT(m == 0 || a < m); + // BOOST_STATIC_ASSERT(m == 0 || c < m); + + explicit linear_congruential(IntType x0 = 1) + { + seed(x0); + + // MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer); +#endif + } + + template<class It> + linear_congruential(It& first, It last) + { + seed(first, last); + } + + // compiler-generated copy constructor and assignment operator are fine + void seed(IntType x0 = 1) + { + // wrap _x if it doesn't fit in the destination + if(modulus == 0) { + _x = x0; + } else { + _x = x0 % modulus; + } + // handle negative seeds + if(_x <= 0 && _x != 0) { + _x += modulus; + } + // adjust to the correct range + if(increment == 0 && _x == 0) { + _x = 1; + } + assert(_x >= (min)()); + assert(_x <= (max)()); + } + + template<class It> + void seed(It& first, It last) + { + if(first == last) + throw std::invalid_argument("linear_congruential::seed"); + seed(*first++); + } + + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return c == 0 ? 1 : 0; } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return modulus-1; } + + IntType operator()() + { + _x = const_mod<IntType, m>::mult_add(a, _x, c); + return _x; + } + + static bool validation(IntType x) { return val == x; } + +#ifdef BOOST_NO_OPERATORS_IN_NAMESPACE + + // Use a member function; Streamable concept not supported. + bool operator==(const linear_congruential& rhs) const + { return _x == rhs._x; } + bool operator!=(const linear_congruential& rhs) const + { return !(*this == rhs); } + +#else + friend bool operator==(const linear_congruential& x, + const linear_congruential& y) + { return x._x == y._x; } + friend bool operator!=(const linear_congruential& x, + const linear_congruential& y) + { return !(x == y); } + +#if !defined(BOOST_RANDOM_NO_STREAM_OPERATORS) && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, + const linear_congruential& lcg) + { + return os << lcg._x; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, + linear_congruential& lcg) + { + return is >> lcg._x; + } + +private: +#endif +#endif + + IntType _x; +}; + +// probably needs the "no native streams" caveat for STLPort +#if !defined(__SGI_STL_PORT) && BOOST_WORKAROUND(__GNUC__, == 2) +template<class IntType, IntType a, IntType c, IntType m, IntType val> +std::ostream& +operator<<(std::ostream& os, + const linear_congruential<IntType,a,c,m,val>& lcg) +{ + return os << lcg._x; +} + +template<class IntType, IntType a, IntType c, IntType m, IntType val> +std::istream& +operator>>(std::istream& is, + linear_congruential<IntType,a,c,m,val>& lcg) +{ + return is >> lcg._x; +} +#elif defined(BOOST_RANDOM_NO_STREAM_OPERATORS) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) +template<class CharT, class Traits, class IntType, IntType a, IntType c, IntType m, IntType val> +std::basic_ostream<CharT,Traits>& +operator<<(std::basic_ostream<CharT,Traits>& os, + const linear_congruential<IntType,a,c,m,val>& lcg) +{ + return os << lcg._x; +} + +template<class CharT, class Traits, class IntType, IntType a, IntType c, IntType m, IntType val> +std::basic_istream<CharT,Traits>& +operator>>(std::basic_istream<CharT,Traits>& is, + linear_congruential<IntType,a,c,m,val>& lcg) +{ + return is >> lcg._x; +} +#endif + +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION +// A definition is required even for integral static constants +template<class IntType, IntType a, IntType c, IntType m, IntType val> +const bool linear_congruential<IntType, a, c, m, val>::has_fixed_range; +template<class IntType, IntType a, IntType c, IntType m, IntType val> +const typename linear_congruential<IntType, a, c, m, val>::result_type linear_congruential<IntType, a, c, m, val>::min_value; +template<class IntType, IntType a, IntType c, IntType m, IntType val> +const typename linear_congruential<IntType, a, c, m, val>::result_type linear_congruential<IntType, a, c, m, val>::max_value; +template<class IntType, IntType a, IntType c, IntType m, IntType val> +const IntType linear_congruential<IntType,a,c,m,val>::modulus; +#endif + +} // namespace random + +// validation values from the publications +typedef random::linear_congruential<int32_t, 16807, 0, 2147483647, + 1043618065> minstd_rand0; +typedef random::linear_congruential<int32_t, 48271, 0, 2147483647, + 399268537> minstd_rand; + + +#if !defined(BOOST_NO_INT64_T) && !defined(BOOST_NO_INTEGRAL_INT64_T) +// emulate the lrand48() C library function; requires support for uint64_t +class rand48 +{ +public: + typedef int32_t result_type; +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION + static const bool has_fixed_range = true; + static const int32_t min_value = 0; + static const int32_t max_value = integer_traits<int32_t>::const_max; +#else + enum { has_fixed_range = false }; +#endif + int32_t min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 0; } + int32_t max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return std::numeric_limits<int32_t>::max BOOST_PREVENT_MACRO_SUBSTITUTION (); } + + rand48() : lcf(cnv(static_cast<int32_t>(1))) {} + template<class T> explicit rand48(T x0) : lcf(cnv(x0)) { } + template<class It> rand48(It& first, It last) : lcf(first, last) { } + // compiler-generated copy ctor and assignment operator are fine + void seed() { seed(static_cast<int32_t>(1)); } + template<class T> void seed(T x0) { lcf.seed(cnv(x0)); } + template<class It> void seed(It& first, It last) { lcf.seed(first,last); } + + int32_t operator()() { return static_cast<int32_t>(lcf() >> 17); } + // by experiment from lrand48() + static bool validation(int32_t x) { return x == 1993516219; } + +#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT,class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const rand48& r) + { os << r.lcf; return os; } + + template<class CharT,class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, rand48& r) + { is >> r.lcf; return is; } +#endif + + friend bool operator==(const rand48& x, const rand48& y) + { return x.lcf == y.lcf; } + friend bool operator!=(const rand48& x, const rand48& y) + { return !(x == y); } +#else + // Use a member function; Streamable concept not supported. + bool operator==(const rand48& rhs) const + { return lcf == rhs.lcf; } + bool operator!=(const rand48& rhs) const + { return !(*this == rhs); } +#endif +private: + random::linear_congruential<uint64_t, + uint64_t(0xDEECE66DUL) | (uint64_t(0x5) << 32), // xxxxULL is not portable + 0xB, uint64_t(1)<<48, /* unknown */ 0> lcf; + template<class T> + static uint64_t cnv(T x) + { + if(sizeof(T) < sizeof(uint64_t)) { + return (static_cast<uint64_t>(x) << 16) | 0x330e; + } else { + return(static_cast<uint64_t>(x)); + } + } + static uint64_t cnv(float x) { return(static_cast<uint64_t>(x)); } + static uint64_t cnv(double x) { return(static_cast<uint64_t>(x)); } + static uint64_t cnv(long double x) { return(static_cast<uint64_t>(x)); } +}; +#endif /* !BOOST_NO_INT64_T && !BOOST_NO_INTEGRAL_INT64_T */ + +} // namespace boost + +#include <boost/random/detail/enable_warnings.hpp> + +#endif // BOOST_RANDOM_LINEAR_CONGRUENTIAL_HPP diff --git a/Utilities/BGL/boost/random/linear_feedback_shift.hpp b/Utilities/BGL/boost/random/linear_feedback_shift.hpp new file mode 100755 index 0000000000000000000000000000000000000000..8619623e942b7a0e9e565bbf3746d3504261d31a --- /dev/null +++ b/Utilities/BGL/boost/random/linear_feedback_shift.hpp @@ -0,0 +1,151 @@ +/* boost random/tausworthe.hpp header file + * + * Copyright Jens Maurer 2002 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: linear_feedback_shift.hpp 58649 2010-01-02 21:23:17Z steven_watanabe $ + * + */ + +#ifndef BOOST_RANDOM_LINEAR_FEEDBACK_SHIFT_HPP +#define BOOST_RANDOM_LINEAR_FEEDBACK_SHIFT_HPP + +#include <iostream> +#include <cassert> +#include <stdexcept> +#include <boost/config.hpp> +#include <boost/static_assert.hpp> +#include <boost/limits.hpp> +#include <boost/random/detail/config.hpp> + +namespace boost { +namespace random { + +// Tausworte 1965 +template<class UIntType, int w, int k, int q, int s, UIntType val> +class linear_feedback_shift +{ +public: + typedef UIntType result_type; + // avoid the warning trouble when using (1<<w) on 32 bit machines + BOOST_STATIC_CONSTANT(bool, has_fixed_range = false); + BOOST_STATIC_CONSTANT(int, word_size = w); + BOOST_STATIC_CONSTANT(int, exponent1 = k); + BOOST_STATIC_CONSTANT(int, exponent2 = q); + BOOST_STATIC_CONSTANT(int, step_size = s); + + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 0; } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return wordmask; } + + // MSVC 6 and possibly others crash when encountering complicated integral + // constant expressions. Avoid the checks for now. + // BOOST_STATIC_ASSERT(w > 0); + // BOOST_STATIC_ASSERT(q > 0); + // BOOST_STATIC_ASSERT(k < w); + // BOOST_STATIC_ASSERT(0 < 2*q && 2*q < k); + // BOOST_STATIC_ASSERT(0 < s && s <= k-q); + + explicit linear_feedback_shift(UIntType s0 = 341) : wordmask(0) + { + // MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT(std::numeric_limits<UIntType>::is_integer); + BOOST_STATIC_ASSERT(!std::numeric_limits<UIntType>::is_signed); +#endif + + // avoid "left shift count >= with of type" warning + for(int i = 0; i < w; ++i) + wordmask |= (1u << i); + seed(s0); + } + + template<class It> linear_feedback_shift(It& first, It last) : wordmask(0) + { + // MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT(std::numeric_limits<UIntType>::is_integer); + BOOST_STATIC_ASSERT(!std::numeric_limits<UIntType>::is_signed); +#endif + + // avoid "left shift count >= with of type" warning + for(int i = 0; i < w; ++i) + wordmask |= (1u << i); + seed(first, last); + } + + void seed(UIntType s0 = 341) { + if(s0 < (1 << (w-k))) { + s0 += 1 << (w-k); + } + value = s0; + } + template<class It> void seed(It& first, It last) + { + if(first == last) + throw std::invalid_argument("linear_feedback_shift::seed"); + value = *first++; + assert(value >= (1 << (w-k))); + } + + result_type operator()() + { + const UIntType b = (((value << q) ^ value) & wordmask) >> (k-s); + const UIntType mask = ( (~static_cast<UIntType>(0)) << (w-k) ) & wordmask; + value = ((value & mask) << s) ^ b; + return value; + } + static bool validation(result_type x) { return val == x; } + +#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, linear_feedback_shift x) + { os << x.value; return os; } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, linear_feedback_shift& x) + { is >> x.value; return is; } +#endif + + friend bool operator==(linear_feedback_shift x, linear_feedback_shift y) + { return x.value == y.value; } + friend bool operator!=(linear_feedback_shift x, linear_feedback_shift y) + { return !(x == y); } +#else + // Use a member function; Streamable concept not supported. + bool operator==(linear_feedback_shift rhs) const + { return value == rhs.value; } + bool operator!=(linear_feedback_shift rhs) const + { return !(*this == rhs); } +#endif + +private: + UIntType wordmask; // avoid "left shift count >= width of type" warnings + UIntType value; +}; + +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION +// A definition is required even for integral static constants +template<class UIntType, int w, int k, int q, int s, UIntType val> +const bool linear_feedback_shift<UIntType, w, k, q, s, val>::has_fixed_range; +template<class UIntType, int w, int k, int q, int s, UIntType val> +const int linear_feedback_shift<UIntType, w, k, q, s, val>::word_size; +template<class UIntType, int w, int k, int q, int s, UIntType val> +const int linear_feedback_shift<UIntType, w, k, q, s, val>::exponent1; +template<class UIntType, int w, int k, int q, int s, UIntType val> +const int linear_feedback_shift<UIntType, w, k, q, s, val>::exponent2; +template<class UIntType, int w, int k, int q, int s, UIntType val> +const int linear_feedback_shift<UIntType, w, k, q, s, val>::step_size; +#endif + +} // namespace random +} // namespace boost + +#endif // BOOST_RANDOM_LINEAR_FEEDBACK_SHIFT_HPP diff --git a/Utilities/BGL/boost/random/lognormal_distribution.hpp b/Utilities/BGL/boost/random/lognormal_distribution.hpp new file mode 100755 index 0000000000000000000000000000000000000000..72932cfcb5f0147726b61659d56f355191087d3c --- /dev/null +++ b/Utilities/BGL/boost/random/lognormal_distribution.hpp @@ -0,0 +1,115 @@ +/* boost random/lognormal_distribution.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: lognormal_distribution.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $ + * + * Revision history + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_LOGNORMAL_DISTRIBUTION_HPP +#define BOOST_RANDOM_LOGNORMAL_DISTRIBUTION_HPP + +#include <boost/config/no_tr1/cmath.hpp> // std::exp, std::sqrt +#include <cassert> +#include <iostream> +#include <boost/limits.hpp> +#include <boost/static_assert.hpp> +#include <boost/random/detail/config.hpp> +#include <boost/random/normal_distribution.hpp> + +#ifdef BOOST_NO_STDC_NAMESPACE +namespace std { + using ::log; + using ::sqrt; +} +#endif + +namespace boost { + +#if defined(__GNUC__) && (__GNUC__ < 3) +// Special gcc workaround: gcc 2.95.x ignores using-declarations +// in template classes (confirmed by gcc author Martin v. Loewis) + using std::sqrt; + using std::exp; +#endif + +template<class RealType = double> +class lognormal_distribution +{ +public: + typedef typename normal_distribution<RealType>::input_type input_type; + typedef RealType result_type; + +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer); +#endif + + explicit lognormal_distribution(result_type mean_arg = result_type(1), + result_type sigma_arg = result_type(1)) + : _mean(mean_arg), _sigma(sigma_arg) + { + assert(_mean > result_type(0)); + init(); + } + + // compiler-generated copy ctor and assignment operator are fine + + RealType mean() const { return _mean; } + RealType sigma() const { return _sigma; } + void reset() { _normal.reset(); } + + template<class Engine> + result_type operator()(Engine& eng) + { +#ifndef BOOST_NO_STDC_NAMESPACE + // allow for Koenig lookup + using std::exp; +#endif + return exp(_normal(eng) * _nsigma + _nmean); + } + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const lognormal_distribution& ld) + { + os << ld._normal << " " << ld._mean << " " << ld._sigma; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, lognormal_distribution& ld) + { + is >> std::ws >> ld._normal >> std::ws >> ld._mean >> std::ws >> ld._sigma; + ld.init(); + return is; + } +#endif + +private: + void init() + { +#ifndef BOOST_NO_STDC_NAMESPACE + // allow for Koenig lookup + using std::exp; using std::log; using std::sqrt; +#endif + _nmean = log(_mean*_mean/sqrt(_sigma*_sigma + _mean*_mean)); + _nsigma = sqrt(log(_sigma*_sigma/_mean/_mean+result_type(1))); + } + + RealType _mean, _sigma; + RealType _nmean, _nsigma; + normal_distribution<result_type> _normal; +}; + +} // namespace boost + +#endif // BOOST_RANDOM_LOGNORMAL_DISTRIBUTION_HPP diff --git a/Utilities/BGL/boost/random/mersenne_twister.hpp b/Utilities/BGL/boost/random/mersenne_twister.hpp new file mode 100755 index 0000000000000000000000000000000000000000..659247c1774637a0b4826eca63aed1a9266b604e --- /dev/null +++ b/Utilities/BGL/boost/random/mersenne_twister.hpp @@ -0,0 +1,293 @@ +/* boost random/mersenne_twister.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: mersenne_twister.hpp 53871 2009-06-13 17:54:06Z steven_watanabe $ + * + * Revision history + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_MERSENNE_TWISTER_HPP +#define BOOST_RANDOM_MERSENNE_TWISTER_HPP + +#include <iostream> +#include <algorithm> // std::copy +#include <stdexcept> +#include <boost/config.hpp> +#include <boost/limits.hpp> +#include <boost/static_assert.hpp> +#include <boost/integer_traits.hpp> +#include <boost/cstdint.hpp> +#include <boost/random/linear_congruential.hpp> +#include <boost/detail/workaround.hpp> +#include <boost/random/detail/config.hpp> +#include <boost/random/detail/ptr_helper.hpp> +#include <boost/random/detail/seed.hpp> + +namespace boost { +namespace random { + +// http://www.math.keio.ac.jp/matumoto/emt.html +template<class UIntType, int w, int n, int m, int r, UIntType a, int u, + int s, UIntType b, int t, UIntType c, int l, UIntType val> +class mersenne_twister +{ +public: + typedef UIntType result_type; + BOOST_STATIC_CONSTANT(int, word_size = w); + BOOST_STATIC_CONSTANT(int, state_size = n); + BOOST_STATIC_CONSTANT(int, shift_size = m); + BOOST_STATIC_CONSTANT(int, mask_bits = r); + BOOST_STATIC_CONSTANT(UIntType, parameter_a = a); + BOOST_STATIC_CONSTANT(int, output_u = u); + BOOST_STATIC_CONSTANT(int, output_s = s); + BOOST_STATIC_CONSTANT(UIntType, output_b = b); + BOOST_STATIC_CONSTANT(int, output_t = t); + BOOST_STATIC_CONSTANT(UIntType, output_c = c); + BOOST_STATIC_CONSTANT(int, output_l = l); + + BOOST_STATIC_CONSTANT(bool, has_fixed_range = false); + + mersenne_twister() { seed(); } + + BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(mersenne_twister, UIntType, value) + { seed(value); } + template<class It> mersenne_twister(It& first, It last) { seed(first,last); } + + BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(mersenne_twister, Generator, gen) + { seed(gen); } + + // compiler-generated copy ctor and assignment operator are fine + + void seed() { seed(UIntType(5489)); } + + BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(mersenne_twister, UIntType, value) + { + // New seeding algorithm from + // http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html + // In the previous versions, MSBs of the seed affected only MSBs of the + // state x[]. + const UIntType mask = ~0u; + x[0] = value & mask; + for (i = 1; i < n; i++) { + // See Knuth "The Art of Computer Programming" Vol. 2, 3rd ed., page 106 + x[i] = (1812433253UL * (x[i-1] ^ (x[i-1] >> (w-2))) + i) & mask; + } + } + + // For GCC, moving this function out-of-line prevents inlining, which may + // reduce overall object code size. However, MSVC does not grok + // out-of-line definitions of member function templates. + BOOST_RANDOM_DETAIL_GENERATOR_SEED(mersenne_twister, Generator, gen) + { +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT(!std::numeric_limits<result_type>::is_signed); +#endif + // I could have used std::generate_n, but it takes "gen" by value + for(int j = 0; j < n; j++) + x[j] = gen(); + i = n; + } + + template<class It> + void seed(It& first, It last) + { + int j; + for(j = 0; j < n && first != last; ++j, ++first) + x[j] = *first; + i = n; + if(first == last && j < n) + throw std::invalid_argument("mersenne_twister::seed"); + } + + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 0; } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const + { + // avoid "left shift count >= with of type" warning + result_type res = 0; + for(int j = 0; j < w; ++j) + res |= (1u << j); + return res; + } + + result_type operator()(); + static bool validation(result_type v) { return val == v; } + +#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const mersenne_twister& mt) + { + for(int j = 0; j < mt.state_size; ++j) + os << mt.compute(j) << " "; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, mersenne_twister& mt) + { + for(int j = 0; j < mt.state_size; ++j) + is >> mt.x[j] >> std::ws; + // MSVC (up to 7.1) and Borland (up to 5.64) don't handle the template + // value parameter "n" available from the class template scope, so use + // the static constant with the same value + mt.i = mt.state_size; + return is; + } +#endif + + friend bool operator==(const mersenne_twister& x, const mersenne_twister& y) + { + for(int j = 0; j < state_size; ++j) + if(x.compute(j) != y.compute(j)) + return false; + return true; + } + + friend bool operator!=(const mersenne_twister& x, const mersenne_twister& y) + { return !(x == y); } +#else + // Use a member function; Streamable concept not supported. + bool operator==(const mersenne_twister& rhs) const + { + for(int j = 0; j < state_size; ++j) + if(compute(j) != rhs.compute(j)) + return false; + return true; + } + + bool operator!=(const mersenne_twister& rhs) const + { return !(*this == rhs); } +#endif + +private: + // returns x(i-n+index), where index is in 0..n-1 + UIntType compute(unsigned int index) const + { + // equivalent to (i-n+index) % 2n, but doesn't produce negative numbers + return x[ (i + n + index) % (2*n) ]; + } + void twist(int block); + + // state representation: next output is o(x(i)) + // x[0] ... x[k] x[k+1] ... x[n-1] x[n] ... x[2*n-1] represents + // x(i-k) ... x(i) x(i+1) ... x(i-k+n-1) x(i-k-n) ... x[i(i-k-1)] + // The goal is to always have x(i-n) ... x(i-1) available for + // operator== and save/restore. + + UIntType x[2*n]; + int i; +}; + +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION +// A definition is required even for integral static constants +template<class UIntType, int w, int n, int m, int r, UIntType a, int u, + int s, UIntType b, int t, UIntType c, int l, UIntType val> +const bool mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::has_fixed_range; +template<class UIntType, int w, int n, int m, int r, UIntType a, int u, + int s, UIntType b, int t, UIntType c, int l, UIntType val> +const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::state_size; +template<class UIntType, int w, int n, int m, int r, UIntType a, int u, + int s, UIntType b, int t, UIntType c, int l, UIntType val> +const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::shift_size; +template<class UIntType, int w, int n, int m, int r, UIntType a, int u, + int s, UIntType b, int t, UIntType c, int l, UIntType val> +const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::mask_bits; +template<class UIntType, int w, int n, int m, int r, UIntType a, int u, + int s, UIntType b, int t, UIntType c, int l, UIntType val> +const UIntType mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::parameter_a; +template<class UIntType, int w, int n, int m, int r, UIntType a, int u, + int s, UIntType b, int t, UIntType c, int l, UIntType val> +const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::output_u; +template<class UIntType, int w, int n, int m, int r, UIntType a, int u, + int s, UIntType b, int t, UIntType c, int l, UIntType val> +const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::output_s; +template<class UIntType, int w, int n, int m, int r, UIntType a, int u, + int s, UIntType b, int t, UIntType c, int l, UIntType val> +const UIntType mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::output_b; +template<class UIntType, int w, int n, int m, int r, UIntType a, int u, + int s, UIntType b, int t, UIntType c, int l, UIntType val> +const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::output_t; +template<class UIntType, int w, int n, int m, int r, UIntType a, int u, + int s, UIntType b, int t, UIntType c, int l, UIntType val> +const UIntType mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::output_c; +template<class UIntType, int w, int n, int m, int r, UIntType a, int u, + int s, UIntType b, int t, UIntType c, int l, UIntType val> +const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::output_l; +#endif + +template<class UIntType, int w, int n, int m, int r, UIntType a, int u, + int s, UIntType b, int t, UIntType c, int l, UIntType val> +void mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::twist(int block) +{ + const UIntType upper_mask = (~0u) << r; + const UIntType lower_mask = ~upper_mask; + + if(block == 0) { + for(int j = n; j < 2*n; j++) { + UIntType y = (x[j-n] & upper_mask) | (x[j-(n-1)] & lower_mask); + x[j] = x[j-(n-m)] ^ (y >> 1) ^ (y&1 ? a : 0); + } + } else if (block == 1) { + // split loop to avoid costly modulo operations + { // extra scope for MSVC brokenness w.r.t. for scope + for(int j = 0; j < n-m; j++) { + UIntType y = (x[j+n] & upper_mask) | (x[j+n+1] & lower_mask); + x[j] = x[j+n+m] ^ (y >> 1) ^ (y&1 ? a : 0); + } + } + + for(int j = n-m; j < n-1; j++) { + UIntType y = (x[j+n] & upper_mask) | (x[j+n+1] & lower_mask); + x[j] = x[j-(n-m)] ^ (y >> 1) ^ (y&1 ? a : 0); + } + // last iteration + UIntType y = (x[2*n-1] & upper_mask) | (x[0] & lower_mask); + x[n-1] = x[m-1] ^ (y >> 1) ^ (y&1 ? a : 0); + i = 0; + } +} + +template<class UIntType, int w, int n, int m, int r, UIntType a, int u, + int s, UIntType b, int t, UIntType c, int l, UIntType val> +inline typename mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::result_type +mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::operator()() +{ + if(i == n) + twist(0); + else if(i >= 2*n) + twist(1); + // Step 4 + UIntType z = x[i]; + ++i; + z ^= (z >> u); + z ^= ((z << s) & b); + z ^= ((z << t) & c); + z ^= (z >> l); + return z; +} + +} // namespace random + + +typedef random::mersenne_twister<uint32_t,32,351,175,19,0xccab8ee7,11, + 7,0x31b6ab00,15,0xffe50000,17, 0xa37d3c92> mt11213b; + +// validation by experiment from mt19937.c +typedef random::mersenne_twister<uint32_t,32,624,397,31,0x9908b0df,11, + 7,0x9d2c5680,15,0xefc60000,18, 3346425566U> mt19937; + +} // namespace boost + +BOOST_RANDOM_PTR_HELPER_SPEC(boost::mt19937) + +#endif // BOOST_RANDOM_MERSENNE_TWISTER_HPP diff --git a/Utilities/BGL/boost/random/normal_distribution.hpp b/Utilities/BGL/boost/random/normal_distribution.hpp new file mode 100755 index 0000000000000000000000000000000000000000..15cecec1da76dbc645432c554f3a2b71fb6809b8 --- /dev/null +++ b/Utilities/BGL/boost/random/normal_distribution.hpp @@ -0,0 +1,112 @@ +/* boost random/normal_distribution.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: normal_distribution.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $ + * + * Revision history + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_NORMAL_DISTRIBUTION_HPP +#define BOOST_RANDOM_NORMAL_DISTRIBUTION_HPP + +#include <boost/config/no_tr1/cmath.hpp> +#include <cassert> +#include <iostream> +#include <boost/limits.hpp> +#include <boost/static_assert.hpp> +#include <boost/random/detail/config.hpp> + +namespace boost { + +// deterministic Box-Muller method, uses trigonometric functions +template<class RealType = double> +class normal_distribution +{ +public: + typedef RealType input_type; + typedef RealType result_type; + +#if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300) + BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer); +#endif + + explicit normal_distribution(const result_type& mean_arg = result_type(0), + const result_type& sigma_arg = result_type(1)) + : _mean(mean_arg), _sigma(sigma_arg), _valid(false) + { + assert(_sigma >= result_type(0)); + } + + // compiler-generated copy constructor is NOT fine, need to purge cache + normal_distribution(const normal_distribution& other) + : _mean(other._mean), _sigma(other._sigma), _valid(false) + { + } + + // compiler-generated copy ctor and assignment operator are fine + + RealType mean() const { return _mean; } + RealType sigma() const { return _sigma; } + + void reset() { _valid = false; } + + template<class Engine> + result_type operator()(Engine& eng) + { +#ifndef BOOST_NO_STDC_NAMESPACE + // allow for Koenig lookup + using std::sqrt; using std::log; using std::sin; using std::cos; +#endif + if(!_valid) { + _r1 = eng(); + _r2 = eng(); + _cached_rho = sqrt(-result_type(2) * log(result_type(1)-_r2)); + _valid = true; + } else { + _valid = false; + } + // Can we have a boost::mathconst please? + const result_type pi = result_type(3.14159265358979323846); + + return _cached_rho * (_valid ? + cos(result_type(2)*pi*_r1) : + sin(result_type(2)*pi*_r1)) + * _sigma + _mean; + } + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const normal_distribution& nd) + { + os << nd._mean << " " << nd._sigma << " " + << nd._valid << " " << nd._cached_rho << " " << nd._r1; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, normal_distribution& nd) + { + is >> std::ws >> nd._mean >> std::ws >> nd._sigma + >> std::ws >> nd._valid >> std::ws >> nd._cached_rho + >> std::ws >> nd._r1; + return is; + } +#endif +private: + result_type _mean, _sigma; + result_type _r1, _r2, _cached_rho; + bool _valid; +}; + +} // namespace boost + +#endif // BOOST_RANDOM_NORMAL_DISTRIBUTION_HPP diff --git a/Utilities/BGL/boost/random/poisson_distribution.hpp b/Utilities/BGL/boost/random/poisson_distribution.hpp new file mode 100755 index 0000000000000000000000000000000000000000..bbf18a355297fd0812f8e3d387d8cf5d16a0afcd --- /dev/null +++ b/Utilities/BGL/boost/random/poisson_distribution.hpp @@ -0,0 +1,100 @@ +/* boost random/poisson_distribution.hpp header file + * + * Copyright Jens Maurer 2002 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: poisson_distribution.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $ + * + */ + +#ifndef BOOST_RANDOM_POISSON_DISTRIBUTION_HPP +#define BOOST_RANDOM_POISSON_DISTRIBUTION_HPP + +#include <boost/config/no_tr1/cmath.hpp> +#include <cassert> +#include <iostream> +#include <boost/limits.hpp> +#include <boost/static_assert.hpp> +#include <boost/random/detail/config.hpp> + +namespace boost { + +// Knuth +template<class IntType = int, class RealType = double> +class poisson_distribution +{ +public: + typedef RealType input_type; + typedef IntType result_type; + + explicit poisson_distribution(const RealType& mean_arg = RealType(1)) + : _mean(mean_arg) + { +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + // MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope + BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer); + BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer); +#endif + + assert(_mean > RealType(0)); + init(); + } + + // compiler-generated copy ctor and assignment operator are fine + + RealType mean() const { return _mean; } + void reset() { } + + template<class Engine> + result_type operator()(Engine& eng) + { + // TODO: This is O(_mean), but it should be O(log(_mean)) for large _mean + RealType product = RealType(1); + for(result_type m = 0; ; ++m) { + product *= eng(); + if(product <= _exp_mean) + return m; + } + } + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const poisson_distribution& pd) + { + os << pd._mean; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, poisson_distribution& pd) + { + is >> std::ws >> pd._mean; + pd.init(); + return is; + } +#endif + +private: + void init() + { +#ifndef BOOST_NO_STDC_NAMESPACE + // allow for Koenig lookup + using std::exp; +#endif + _exp_mean = exp(-_mean); + } + + RealType _mean; + // some precomputed data from the parameters + RealType _exp_mean; +}; + +} // namespace boost + +#endif // BOOST_RANDOM_POISSON_DISTRIBUTION_HPP diff --git a/Utilities/BGL/boost/random/random_number_generator.hpp b/Utilities/BGL/boost/random/random_number_generator.hpp new file mode 100755 index 0000000000000000000000000000000000000000..eaf32e534f284ab9335fd3a36ca63739672b96f5 --- /dev/null +++ b/Utilities/BGL/boost/random/random_number_generator.hpp @@ -0,0 +1,56 @@ +/* boost random/random_number_generator.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: random_number_generator.hpp 26164 2004-11-09 21:22:00Z jmaurer $ + * + * Revision history + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP +#define BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP + +#include <boost/config.hpp> +#include <boost/limits.hpp> +#include <boost/static_assert.hpp> +#include <boost/random/uniform_int.hpp> +#include <boost/random/variate_generator.hpp> + +namespace boost { + +// a model for RandomNumberGenerator std:25.2.11 [lib.alg.random.shuffle] +template<class UniformRandomNumberGenerator, class IntType = long> +class random_number_generator +{ +public: + typedef UniformRandomNumberGenerator base_type; + typedef IntType argument_type; + typedef IntType result_type; + random_number_generator(base_type& rng) : _rng(rng) + { +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT(std::numeric_limits<result_type>::is_integer); +#endif + } + // compiler-generated copy ctor is fine + // assignment is disallowed because there is a reference member + + result_type operator()(argument_type n) + { + typedef uniform_int<IntType> dist_type; + return variate_generator<base_type&, dist_type>(_rng, dist_type(0, n-1))(); + } + +private: + base_type& _rng; +}; + +} // namespace boost + +#endif // BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP diff --git a/Utilities/BGL/boost/random/ranlux.hpp b/Utilities/BGL/boost/random/ranlux.hpp new file mode 100755 index 0000000000000000000000000000000000000000..7334551d0b11dd85bde395d354a0a717628b958e --- /dev/null +++ b/Utilities/BGL/boost/random/ranlux.hpp @@ -0,0 +1,50 @@ +/* boost random/ranlux.hpp header file + * + * Copyright Jens Maurer 2002 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: ranlux.hpp 24096 2004-07-27 03:43:34Z dgregor $ + * + * Revision history + * 2001-02-18 created + */ + +#ifndef BOOST_RANDOM_RANLUX_HPP +#define BOOST_RANDOM_RANLUX_HPP + +#include <boost/config.hpp> +#include <boost/random/subtract_with_carry.hpp> +#include <boost/random/discard_block.hpp> + +namespace boost { + +namespace random { + typedef subtract_with_carry<int, (1<<24), 10, 24, 0> ranlux_base; + typedef subtract_with_carry_01<float, 24, 10, 24> ranlux_base_01; + typedef subtract_with_carry_01<double, 48, 10, 24> ranlux64_base_01; +} + +typedef random::discard_block<random::ranlux_base, 223, 24> ranlux3; +typedef random::discard_block<random::ranlux_base, 389, 24> ranlux4; + +typedef random::discard_block<random::ranlux_base_01, 223, 24> ranlux3_01; +typedef random::discard_block<random::ranlux_base_01, 389, 24> ranlux4_01; + +typedef random::discard_block<random::ranlux64_base_01, 223, 24> ranlux64_3_01; +typedef random::discard_block<random::ranlux64_base_01, 389, 24> ranlux64_4_01; + +#if !defined(BOOST_NO_INT64_T) && !defined(BOOST_NO_INTEGRAL_INT64_T) +namespace random { + typedef random::subtract_with_carry<int64_t, (int64_t(1)<<48), 10, 24, 0> ranlux64_base; +} +typedef random::discard_block<random::ranlux64_base, 223, 24> ranlux64_3; +typedef random::discard_block<random::ranlux64_base, 389, 24> ranlux64_4; +#endif /* !BOOST_NO_INT64_T && !BOOST_NO_INTEGRAL_INT64_T */ + +} // namespace boost + +#endif // BOOST_RANDOM_LINEAR_CONGRUENTIAL_HPP diff --git a/Utilities/BGL/boost/random/shuffle_output.hpp b/Utilities/BGL/boost/random/shuffle_output.hpp new file mode 100755 index 0000000000000000000000000000000000000000..a59c489a97f1c03b738b499ad84d6545c6b0ede9 --- /dev/null +++ b/Utilities/BGL/boost/random/shuffle_output.hpp @@ -0,0 +1,175 @@ +/* boost random/shuffle_output.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: shuffle_output.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $ + * + * Revision history + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_SHUFFLE_OUTPUT_HPP +#define BOOST_RANDOM_SHUFFLE_OUTPUT_HPP + +#include <iostream> +#include <algorithm> // std::copy +#include <cassert> +#include <boost/config.hpp> +#include <boost/limits.hpp> +#include <boost/static_assert.hpp> +#include <boost/cstdint.hpp> +#include <boost/random/linear_congruential.hpp> + +namespace boost { +namespace random { + +// Carter Bays and S.D. Durham 1979 +template<class UniformRandomNumberGenerator, int k, +#ifndef BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS + typename UniformRandomNumberGenerator::result_type +#else + uint32_t +#endif + val = 0> +class shuffle_output +{ +public: + typedef UniformRandomNumberGenerator base_type; + typedef typename base_type::result_type result_type; + + BOOST_STATIC_CONSTANT(bool, has_fixed_range = false); + BOOST_STATIC_CONSTANT(int, buffer_size = k); + + shuffle_output() : _rng() { init(); } +#if defined(BOOST_MSVC) && _MSC_VER < 1300 + // MSVC does not implicitly generate the copy constructor here + shuffle_output(const shuffle_output & x) + : _rng(x._rng), y(x.y) { std::copy(x.v, x.v+k, v); } +#endif + template<class T> + explicit shuffle_output(T s) : _rng(s) { init(); } + explicit shuffle_output(const base_type & rng) : _rng(rng) { init(); } + template<class It> shuffle_output(It& first, It last) + : _rng(first, last) { init(); } + void seed() { _rng.seed(); init(); } + template<class T> + void seed(T s) { _rng.seed(s); init(); } + template<class It> void seed(It& first, It last) + { + _rng.seed(first, last); + init(); + } + + const base_type& base() const { return _rng; } + + result_type operator()() { + // calculating the range every time may seem wasteful. However, this + // makes the information locally available for the optimizer. + result_type range = (max)()-(min)()+1; + int j = k*(y-(min)())/range; + // assert(0 <= j && j < k); + y = v[j]; + v[j] = _rng(); + return y; + } + + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_rng.min)(); } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_rng.max)(); } + static bool validation(result_type x) { return val == x; } + +#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const shuffle_output& s) + { + os << s._rng << " " << s.y << " "; + for(int i = 0; i < s.buffer_size; ++i) + os << s.v[i] << " "; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, shuffle_output& s) + { + is >> s._rng >> std::ws >> s.y >> std::ws; + for(int i = 0; i < s.buffer_size; ++i) + is >> s.v[i] >> std::ws; + return is; + } +#endif + + friend bool operator==(const shuffle_output& x, const shuffle_output& y) + { return x._rng == y._rng && x.y == y.y && std::equal(x.v, x.v+k, y.v); } + friend bool operator!=(const shuffle_output& x, const shuffle_output& y) + { return !(x == y); } +#else + // Use a member function; Streamable concept not supported. + bool operator==(const shuffle_output& rhs) const + { return _rng == rhs._rng && y == rhs.y && std::equal(v, v+k, rhs.v); } + bool operator!=(const shuffle_output& rhs) const + { return !(*this == rhs); } +#endif +private: + void init() + { +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT(std::numeric_limits<result_type>::is_integer); +#endif + result_type range = (max)()-(min)(); + assert(range > 0); // otherwise there would be little choice + if(static_cast<unsigned long>(k * range) < + static_cast<unsigned long>(range)) // not a sufficient condition + // likely overflow with bucket number computation + assert(!"overflow will occur"); + + // we cannot use std::generate, because it uses pass-by-value for _rng + for(result_type * p = v; p != v+k; ++p) + *p = _rng(); + y = _rng(); + } + + base_type _rng; + result_type v[k]; + result_type y; +}; + +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION +// A definition is required even for integral static constants +template<class UniformRandomNumberGenerator, int k, +#ifndef BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS + typename UniformRandomNumberGenerator::result_type +#else + uint32_t +#endif + val> +const bool shuffle_output<UniformRandomNumberGenerator, k, val>::has_fixed_range; + +template<class UniformRandomNumberGenerator, int k, +#ifndef BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS + typename UniformRandomNumberGenerator::result_type +#else + uint32_t +#endif + val> +const int shuffle_output<UniformRandomNumberGenerator, k, val>::buffer_size; +#endif + +} // namespace random + +// validation by experiment from Harry Erwin's generator.h (private e-mail) +typedef random::shuffle_output< + random::linear_congruential<uint32_t, 1366, 150889, 714025, 0>, + 97, 139726> kreutzer1986; + + +} // namespace boost + +#endif // BOOST_RANDOM_SHUFFLE_OUTPUT_HPP diff --git a/Utilities/BGL/boost/random/subtract_with_carry.hpp b/Utilities/BGL/boost/random/subtract_with_carry.hpp new file mode 100755 index 0000000000000000000000000000000000000000..751b8a9cc64e93007fbec22c914be6ed2f808602 --- /dev/null +++ b/Utilities/BGL/boost/random/subtract_with_carry.hpp @@ -0,0 +1,448 @@ +/* boost random/subtract_with_carry.hpp header file + * + * Copyright Jens Maurer 2002 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: subtract_with_carry.hpp 53871 2009-06-13 17:54:06Z steven_watanabe $ + * + * Revision history + * 2002-03-02 created + */ + +#ifndef BOOST_RANDOM_SUBTRACT_WITH_CARRY_HPP +#define BOOST_RANDOM_SUBTRACT_WITH_CARRY_HPP + +#include <boost/config/no_tr1/cmath.hpp> +#include <iostream> +#include <algorithm> // std::equal +#include <stdexcept> +#include <boost/config/no_tr1/cmath.hpp> // std::pow +#include <boost/config.hpp> +#include <boost/limits.hpp> +#include <boost/cstdint.hpp> +#include <boost/static_assert.hpp> +#include <boost/detail/workaround.hpp> +#include <boost/random/detail/config.hpp> +#include <boost/random/detail/seed.hpp> +#include <boost/random/linear_congruential.hpp> + + +namespace boost { +namespace random { + +#if BOOST_WORKAROUND(_MSC_FULL_VER, BOOST_TESTED_AT(13102292)) && BOOST_MSVC > 1300 +# define BOOST_RANDOM_EXTRACT_SWC_01 +#endif + +#if defined(__APPLE_CC__) && defined(__GNUC__) && (__GNUC__ == 3) && (__GNUC_MINOR__ <= 3) +# define BOOST_RANDOM_EXTRACT_SWC_01 +#endif + +# ifdef BOOST_RANDOM_EXTRACT_SWC_01 +namespace detail +{ + template <class IStream, class SubtractWithCarry, class RealType> + void extract_subtract_with_carry_01( + IStream& is + , SubtractWithCarry& f + , RealType& carry + , RealType* x + , RealType modulus) + { + RealType value; + for(unsigned int j = 0; j < f.long_lag; ++j) { + is >> value >> std::ws; + x[j] = value / modulus; + } + is >> value >> std::ws; + carry = value / modulus; + } +} +# endif +// subtract-with-carry generator +// Marsaglia and Zaman + +template<class IntType, IntType m, unsigned int s, unsigned int r, + IntType val> +class subtract_with_carry +{ +public: + typedef IntType result_type; + BOOST_STATIC_CONSTANT(bool, has_fixed_range = true); + BOOST_STATIC_CONSTANT(result_type, min_value = 0); + BOOST_STATIC_CONSTANT(result_type, max_value = m-1); + BOOST_STATIC_CONSTANT(result_type, modulus = m); + BOOST_STATIC_CONSTANT(unsigned int, long_lag = r); + BOOST_STATIC_CONSTANT(unsigned int, short_lag = s); + + subtract_with_carry() { + // MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT(std::numeric_limits<result_type>::is_signed); + BOOST_STATIC_ASSERT(std::numeric_limits<result_type>::is_integer); +#endif + seed(); + } + BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(subtract_with_carry, uint32_t, value) + { seed(value); } + BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(subtract_with_carry, Generator, gen) + { seed(gen); } + template<class It> subtract_with_carry(It& first, It last) { seed(first,last); } + + // compiler-generated copy ctor and assignment operator are fine + + void seed() { seed(19780503u); } + BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(subtract_with_carry, uint32_t, value) + { + random::linear_congruential<int32_t, 40014, 0, 2147483563, 0> intgen(value); + seed(intgen); + } + + // For GCC, moving this function out-of-line prevents inlining, which may + // reduce overall object code size. However, MSVC does not grok + // out-of-line template member functions. + BOOST_RANDOM_DETAIL_GENERATOR_SEED(subtract_with_carry, Generator, gen) + { + // I could have used std::generate_n, but it takes "gen" by value + for(unsigned int j = 0; j < long_lag; ++j) + x[j] = gen() % modulus; + carry = (x[long_lag-1] == 0); + k = 0; + } + + template<class It> + void seed(It& first, It last) + { + unsigned int j; + for(j = 0; j < long_lag && first != last; ++j, ++first) + x[j] = *first % modulus; + if(first == last && j < long_lag) + throw std::invalid_argument("subtract_with_carry::seed"); + carry = (x[long_lag-1] == 0); + k = 0; + } + + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return min_value; } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return max_value; } + + result_type operator()() + { + int short_index = k - short_lag; + if(short_index < 0) + short_index += long_lag; + IntType delta; + if (x[short_index] >= x[k] + carry) { + // x(n) >= 0 + delta = x[short_index] - (x[k] + carry); + carry = 0; + } else { + // x(n) < 0 + delta = modulus - x[k] - carry + x[short_index]; + carry = 1; + } + x[k] = delta; + ++k; + if(k >= long_lag) + k = 0; + return delta; + } + +public: + static bool validation(result_type x) { return x == val; } + +#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, + const subtract_with_carry& f) + { + for(unsigned int j = 0; j < f.long_lag; ++j) + os << f.compute(j) << " "; + os << f.carry << " "; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, subtract_with_carry& f) + { + for(unsigned int j = 0; j < f.long_lag; ++j) + is >> f.x[j] >> std::ws; + is >> f.carry >> std::ws; + f.k = 0; + return is; + } +#endif + + friend bool operator==(const subtract_with_carry& x, const subtract_with_carry& y) + { + for(unsigned int j = 0; j < r; ++j) + if(x.compute(j) != y.compute(j)) + return false; + return true; + } + + friend bool operator!=(const subtract_with_carry& x, const subtract_with_carry& y) + { return !(x == y); } +#else + // Use a member function; Streamable concept not supported. + bool operator==(const subtract_with_carry& rhs) const + { + for(unsigned int j = 0; j < r; ++j) + if(compute(j) != rhs.compute(j)) + return false; + return true; + } + + bool operator!=(const subtract_with_carry& rhs) const + { return !(*this == rhs); } +#endif + +private: + // returns x(i-r+index), where index is in 0..r-1 + IntType compute(unsigned int index) const + { + return x[(k+index) % long_lag]; + } + + // state representation; next output (state) is x(i) + // x[0] ... x[k] x[k+1] ... x[long_lag-1] represents + // x(i-k) ... x(i) x(i+1) ... x(i-k+long_lag-1) + // speed: base: 20-25 nsec + // ranlux_4: 230 nsec, ranlux_7: 430 nsec, ranlux_14: 810 nsec + // This state representation makes operator== and save/restore more + // difficult, because we've already computed "too much" and thus + // have to undo some steps to get at x(i-r) etc. + + // state representation: next output (state) is x(i) + // x[0] ... x[k] x[k+1] ... x[long_lag-1] represents + // x(i-k) ... x(i) x(i-long_lag+1) ... x(i-k-1) + // speed: base 28 nsec + // ranlux_4: 370 nsec, ranlux_7: 688 nsec, ranlux_14: 1343 nsec + IntType x[long_lag]; + unsigned int k; + int carry; +}; + +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION +// A definition is required even for integral static constants +template<class IntType, IntType m, unsigned int s, unsigned int r, IntType val> +const bool subtract_with_carry<IntType, m, s, r, val>::has_fixed_range; +template<class IntType, IntType m, unsigned int s, unsigned int r, IntType val> +const IntType subtract_with_carry<IntType, m, s, r, val>::min_value; +template<class IntType, IntType m, unsigned int s, unsigned int r, IntType val> +const IntType subtract_with_carry<IntType, m, s, r, val>::max_value; +template<class IntType, IntType m, unsigned int s, unsigned int r, IntType val> +const IntType subtract_with_carry<IntType, m, s, r, val>::modulus; +template<class IntType, IntType m, unsigned int s, unsigned int r, IntType val> +const unsigned int subtract_with_carry<IntType, m, s, r, val>::long_lag; +template<class IntType, IntType m, unsigned int s, unsigned int r, IntType val> +const unsigned int subtract_with_carry<IntType, m, s, r, val>::short_lag; +#endif + + +// use a floating-point representation to produce values in [0..1) +template<class RealType, int w, unsigned int s, unsigned int r, int val=0> +class subtract_with_carry_01 +{ +public: + typedef RealType result_type; + BOOST_STATIC_CONSTANT(bool, has_fixed_range = false); + BOOST_STATIC_CONSTANT(int, word_size = w); + BOOST_STATIC_CONSTANT(unsigned int, long_lag = r); + BOOST_STATIC_CONSTANT(unsigned int, short_lag = s); + +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT(!std::numeric_limits<result_type>::is_integer); +#endif + + subtract_with_carry_01() { init_modulus(); seed(); } + explicit subtract_with_carry_01(uint32_t value) + { init_modulus(); seed(value); } + template<class It> subtract_with_carry_01(It& first, It last) + { init_modulus(); seed(first,last); } + +private: + void init_modulus() + { +#ifndef BOOST_NO_STDC_NAMESPACE + // allow for Koenig lookup + using std::pow; +#endif + _modulus = pow(RealType(2), word_size); + } + +public: + // compiler-generated copy ctor and assignment operator are fine + + void seed(uint32_t value = 19780503u) + { +#ifndef BOOST_NO_STDC_NAMESPACE + // allow for Koenig lookup + using std::fmod; +#endif + random::linear_congruential<int32_t, 40014, 0, 2147483563, 0> gen(value); + unsigned long array[(w+31)/32 * long_lag]; + for(unsigned int j = 0; j < sizeof(array)/sizeof(unsigned long); ++j) + array[j] = gen(); + unsigned long * start = array; + seed(start, array + sizeof(array)/sizeof(unsigned long)); + } + + template<class It> + void seed(It& first, It last) + { +#ifndef BOOST_NO_STDC_NAMESPACE + // allow for Koenig lookup + using std::fmod; + using std::pow; +#endif + unsigned long mask = ~((~0u) << (w%32)); // now lowest (w%32) bits set + RealType two32 = pow(RealType(2), 32); + unsigned int j; + for(j = 0; j < long_lag && first != last; ++j) { + x[j] = RealType(0); + for(int i = 0; i < w/32 && first != last; ++i, ++first) + x[j] += *first / pow(two32,i+1); + if(first != last && mask != 0) { + x[j] += fmod((*first & mask) / _modulus, RealType(1)); + ++first; + } + } + if(first == last && j < long_lag) + throw std::invalid_argument("subtract_with_carry_01::seed"); + carry = (x[long_lag-1] ? 0 : 1 / _modulus); + k = 0; + } + + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(0); } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(1); } + + result_type operator()() + { + int short_index = k - short_lag; + if(short_index < 0) + short_index += long_lag; + RealType delta = x[short_index] - x[k] - carry; + if(delta < 0) { + delta += RealType(1); + carry = RealType(1)/_modulus; + } else { + carry = 0; + } + x[k] = delta; + ++k; + if(k >= long_lag) + k = 0; + return delta; + } + + static bool validation(result_type x) + { return x == val/pow(RealType(2), word_size); } + +#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, + const subtract_with_carry_01& f) + { +#ifndef BOOST_NO_STDC_NAMESPACE + // allow for Koenig lookup + using std::pow; +#endif + std::ios_base::fmtflags oldflags = os.flags(os.dec | os.fixed | os.left); + for(unsigned int j = 0; j < f.long_lag; ++j) + os << (f.compute(j) * f._modulus) << " "; + os << (f.carry * f._modulus); + os.flags(oldflags); + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, subtract_with_carry_01& f) + { +# ifdef BOOST_RANDOM_EXTRACT_SWC_01 + detail::extract_subtract_with_carry_01(is, f, f.carry, f.x, f._modulus); +# else + // MSVC (up to 7.1) and Borland (up to 5.64) don't handle the template type + // parameter "RealType" available from the class template scope, so use + // the member typedef + typename subtract_with_carry_01::result_type value; + for(unsigned int j = 0; j < long_lag; ++j) { + is >> value >> std::ws; + f.x[j] = value / f._modulus; + } + is >> value >> std::ws; + f.carry = value / f._modulus; +# endif + f.k = 0; + return is; + } +#endif + + friend bool operator==(const subtract_with_carry_01& x, + const subtract_with_carry_01& y) + { + for(unsigned int j = 0; j < r; ++j) + if(x.compute(j) != y.compute(j)) + return false; + return true; + } + + friend bool operator!=(const subtract_with_carry_01& x, + const subtract_with_carry_01& y) + { return !(x == y); } +#else + // Use a member function; Streamable concept not supported. + bool operator==(const subtract_with_carry_01& rhs) const + { + for(unsigned int j = 0; j < r; ++j) + if(compute(j) != rhs.compute(j)) + return false; + return true; + } + + bool operator!=(const subtract_with_carry_01& rhs) const + { return !(*this == rhs); } +#endif + +private: + RealType compute(unsigned int index) const; + unsigned int k; + RealType carry; + RealType x[long_lag]; + RealType _modulus; +}; + +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION +// A definition is required even for integral static constants +template<class RealType, int w, unsigned int s, unsigned int r, int val> +const bool subtract_with_carry_01<RealType, w, s, r, val>::has_fixed_range; +template<class RealType, int w, unsigned int s, unsigned int r, int val> +const int subtract_with_carry_01<RealType, w, s, r, val>::word_size; +template<class RealType, int w, unsigned int s, unsigned int r, int val> +const unsigned int subtract_with_carry_01<RealType, w, s, r, val>::long_lag; +template<class RealType, int w, unsigned int s, unsigned int r, int val> +const unsigned int subtract_with_carry_01<RealType, w, s, r, val>::short_lag; +#endif + +template<class RealType, int w, unsigned int s, unsigned int r, int val> +RealType subtract_with_carry_01<RealType, w, s, r, val>::compute(unsigned int index) const +{ + return x[(k+index) % long_lag]; +} + + +} // namespace random +} // namespace boost + +#endif // BOOST_RANDOM_SUBTRACT_WITH_CARRY_HPP diff --git a/Utilities/BGL/boost/random/triangle_distribution.hpp b/Utilities/BGL/boost/random/triangle_distribution.hpp new file mode 100755 index 0000000000000000000000000000000000000000..3e3828bccf6f898424e9b290c71fd14a9c4243e0 --- /dev/null +++ b/Utilities/BGL/boost/random/triangle_distribution.hpp @@ -0,0 +1,102 @@ +/* boost random/triangle_distribution.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: triangle_distribution.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $ + * + * Revision history + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_TRIANGLE_DISTRIBUTION_HPP +#define BOOST_RANDOM_TRIANGLE_DISTRIBUTION_HPP + +#include <boost/config/no_tr1/cmath.hpp> +#include <cassert> +#include <boost/random/detail/config.hpp> +#include <boost/random/uniform_01.hpp> + +namespace boost { + +// triangle distribution, with a smallest, b most probable, and c largest +// value. +template<class RealType = double> +class triangle_distribution +{ +public: + typedef RealType input_type; + typedef RealType result_type; + + explicit triangle_distribution(result_type a_arg = result_type(0), + result_type b_arg = result_type(0.5), + result_type c_arg = result_type(1)) + : _a(a_arg), _b(b_arg), _c(c_arg) + { + assert(_a <= _b && _b <= _c); + init(); + } + + // compiler-generated copy ctor and assignment operator are fine + result_type a() const { return _a; } + result_type b() const { return _b; } + result_type c() const { return _c; } + + void reset() { } + + template<class Engine> + result_type operator()(Engine& eng) + { +#ifndef BOOST_NO_STDC_NAMESPACE + using std::sqrt; +#endif + result_type u = eng(); + if( u <= q1 ) + return _a + p1*sqrt(u); + else + return _c - d3*sqrt(d2*u-d1); + } + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const triangle_distribution& td) + { + os << td._a << " " << td._b << " " << td._c; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, triangle_distribution& td) + { + is >> std::ws >> td._a >> std::ws >> td._b >> std::ws >> td._c; + td.init(); + return is; + } +#endif + +private: + void init() + { +#ifndef BOOST_NO_STDC_NAMESPACE + using std::sqrt; +#endif + d1 = _b - _a; + d2 = _c - _a; + d3 = sqrt(_c - _b); + q1 = d1 / d2; + p1 = sqrt(d1 * d2); + } + + result_type _a, _b, _c; + result_type d1, d2, d3, q1, p1; +}; + +} // namespace boost + +#endif // BOOST_RANDOM_TRIANGLE_DISTRIBUTION_HPP diff --git a/Utilities/BGL/boost/random/uniform_01.hpp b/Utilities/BGL/boost/random/uniform_01.hpp new file mode 100755 index 0000000000000000000000000000000000000000..07d6a3ea1c1d17d41eff176d585e0b5998ee81e7 --- /dev/null +++ b/Utilities/BGL/boost/random/uniform_01.hpp @@ -0,0 +1,224 @@ +/* boost random/uniform_01.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: uniform_01.hpp 58649 2010-01-02 21:23:17Z steven_watanabe $ + * + * Revision history + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_UNIFORM_01_HPP +#define BOOST_RANDOM_UNIFORM_01_HPP + +#include <iostream> +#include <boost/config.hpp> +#include <boost/limits.hpp> +#include <boost/static_assert.hpp> +#include <boost/random/detail/config.hpp> +#include <boost/random/detail/pass_through_engine.hpp> + +#include <boost/random/detail/disable_warnings.hpp> + +namespace boost { + +namespace detail { + +template<class RealType> +class new_uniform_01 +{ +public: + typedef RealType input_type; + typedef RealType result_type; + // compiler-generated copy ctor and copy assignment are fine + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(0); } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(1); } + void reset() { } + + template<class Engine> + result_type operator()(Engine& eng) { + for (;;) { + typedef typename Engine::result_type base_result; + result_type factor = result_type(1) / + (result_type((eng.max)()-(eng.min)()) + + result_type(std::numeric_limits<base_result>::is_integer ? 1 : 0)); + result_type result = result_type(eng() - (eng.min)()) * factor; + if (result < result_type(1)) + return result; + } + } + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const new_uniform_01&) + { + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, new_uniform_01&) + { + return is; + } +#endif +}; + +template<class UniformRandomNumberGenerator, class RealType> +class backward_compatible_uniform_01 +{ + typedef boost::random::detail::ptr_helper<UniformRandomNumberGenerator> traits; + typedef boost::random::detail::pass_through_engine<UniformRandomNumberGenerator> internal_engine_type; +public: + typedef UniformRandomNumberGenerator base_type; + typedef RealType result_type; + + BOOST_STATIC_CONSTANT(bool, has_fixed_range = false); + +#if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300) + BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer); +#endif + + explicit backward_compatible_uniform_01(typename traits::rvalue_type rng) + : _rng(rng), + _factor(result_type(1) / + (result_type((_rng.max)()-(_rng.min)()) + + result_type(std::numeric_limits<base_result>::is_integer ? 1 : 0))) + { + } + // compiler-generated copy ctor and copy assignment are fine + + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(0); } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(1); } + typename traits::value_type& base() { return _rng.base(); } + const typename traits::value_type& base() const { return _rng.base(); } + void reset() { } + + result_type operator()() { + for (;;) { + result_type result = result_type(_rng() - (_rng.min)()) * _factor; + if (result < result_type(1)) + return result; + } + } + +#if !defined(BOOST_NO_OPERATORS_IN_NAMESPACE) && !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const backward_compatible_uniform_01& u) + { + os << u._rng; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, backward_compatible_uniform_01& u) + { + is >> u._rng; + return is; + } +#endif + +private: + typedef typename internal_engine_type::result_type base_result; + internal_engine_type _rng; + result_type _factor; +}; + +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION +// A definition is required even for integral static constants +template<class UniformRandomNumberGenerator, class RealType> +const bool backward_compatible_uniform_01<UniformRandomNumberGenerator, RealType>::has_fixed_range; +#endif + +template<class UniformRandomNumberGenerator> +struct select_uniform_01 +{ + template<class RealType> + struct apply + { + typedef backward_compatible_uniform_01<UniformRandomNumberGenerator, RealType> type; + }; +}; + +template<> +struct select_uniform_01<float> +{ + template<class RealType> + struct apply + { + typedef new_uniform_01<float> type; + }; +}; + +template<> +struct select_uniform_01<double> +{ + template<class RealType> + struct apply + { + typedef new_uniform_01<double> type; + }; +}; + +template<> +struct select_uniform_01<long double> +{ + template<class RealType> + struct apply + { + typedef new_uniform_01<long double> type; + }; +}; + +} + +// Because it is so commonly used: uniform distribution on the real [0..1) +// range. This allows for specializations to avoid a costly int -> float +// conversion plus float multiplication +template<class UniformRandomNumberGenerator = double, class RealType = double> +class uniform_01 + : public detail::select_uniform_01<UniformRandomNumberGenerator>::BOOST_NESTED_TEMPLATE apply<RealType>::type +{ + typedef typename detail::select_uniform_01<UniformRandomNumberGenerator>::BOOST_NESTED_TEMPLATE apply<RealType>::type impl_type; + typedef boost::random::detail::ptr_helper<UniformRandomNumberGenerator> traits; +public: + + uniform_01() {} + + explicit uniform_01(typename traits::rvalue_type rng) + : impl_type(rng) + { + } + +#if !defined(BOOST_NO_OPERATORS_IN_NAMESPACE) && !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const uniform_01& u) + { + os << static_cast<const impl_type&>(u); + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, uniform_01& u) + { + is >> static_cast<impl_type&>(u); + return is; + } +#endif +}; + +} // namespace boost + +#include <boost/random/detail/enable_warnings.hpp> + +#endif // BOOST_RANDOM_UNIFORM_01_HPP diff --git a/Utilities/BGL/boost/random/uniform_int.hpp b/Utilities/BGL/boost/random/uniform_int.hpp new file mode 100755 index 0000000000000000000000000000000000000000..e8f77cbb5ccffe24be5e65875399eb69f4f31bab --- /dev/null +++ b/Utilities/BGL/boost/random/uniform_int.hpp @@ -0,0 +1,264 @@ +/* boost random/uniform_int.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: uniform_int.hpp 58649 2010-01-02 21:23:17Z steven_watanabe $ + * + * Revision history + * 2001-04-08 added min<max assertion (N. Becker) + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_UNIFORM_INT_HPP +#define BOOST_RANDOM_UNIFORM_INT_HPP + +#include <cassert> +#include <iostream> +#include <boost/config.hpp> +#include <boost/limits.hpp> +#include <boost/static_assert.hpp> +#include <boost/detail/workaround.hpp> +#include <boost/random/detail/config.hpp> +#include <boost/random/detail/signed_unsigned_tools.hpp> +#include <boost/type_traits/make_unsigned.hpp> + +namespace boost { + +// uniform integer distribution on [min, max] +template<class IntType = int> +class uniform_int +{ +public: + typedef IntType input_type; + typedef IntType result_type; + typedef typename make_unsigned<result_type>::type range_type; + + explicit uniform_int(IntType min_arg = 0, IntType max_arg = 9) + : _min(min_arg), _max(max_arg) + { +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + // MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope + BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer); +#endif + assert(min_arg <= max_arg); + init(); + } + + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; } + void reset() { } + + // can't have member function templates out-of-line due to MSVC bugs + template<class Engine> + result_type operator()(Engine& eng) + { + return generate(eng, _min, _max, _range); + } + + template<class Engine> + result_type operator()(Engine& eng, result_type n) + { + assert(n > 0); + + if (n == 1) + { + return 0; + } + + return generate(eng, 0, n - 1, n - 1); + } + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const uniform_int& ud) + { + os << ud._min << " " << ud._max; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, uniform_int& ud) + { + is >> std::ws >> ud._min >> std::ws >> ud._max; + ud.init(); + return is; + } +#endif + +private: + template<class Engine> + static result_type generate(Engine& eng, result_type min_value, result_type /*max_value*/, range_type range) + { + typedef typename Engine::result_type base_result; + // ranges are always unsigned + typedef typename make_unsigned<base_result>::type base_unsigned; + const base_result bmin = (eng.min)(); + const base_unsigned brange = + random::detail::subtract<base_result>()((eng.max)(), (eng.min)()); + + if(range == 0) { + return min_value; + } else if(brange == range) { + // this will probably never happen in real life + // basically nothing to do; just take care we don't overflow / underflow + base_unsigned v = random::detail::subtract<base_result>()(eng(), bmin); + return random::detail::add<base_unsigned, result_type>()(v, min_value); + } else if(brange < range) { + // use rejection method to handle things like 0..3 --> 0..4 + for(;;) { + // concatenate several invocations of the base RNG + // take extra care to avoid overflows + + // limit == floor((range+1)/(brange+1)) + // Therefore limit*(brange+1) <= range+1 + range_type limit; + if(range == (std::numeric_limits<range_type>::max)()) { + limit = range/(range_type(brange)+1); + if(range % (range_type(brange)+1) == range_type(brange)) + ++limit; + } else { + limit = (range+1)/(range_type(brange)+1); + } + + // We consider "result" as expressed to base (brange+1): + // For every power of (brange+1), we determine a random factor + range_type result = range_type(0); + range_type mult = range_type(1); + + // loop invariants: + // result < mult + // mult <= range + while(mult <= limit) { + // Postcondition: result <= range, thus no overflow + // + // limit*(brange+1)<=range+1 def. of limit (1) + // eng()-bmin<=brange eng() post. (2) + // and mult<=limit. loop condition (3) + // Therefore mult*(eng()-bmin+1)<=range+1 by (1),(2),(3) (4) + // Therefore mult*(eng()-bmin)+mult<=range+1 rearranging (4) (5) + // result<mult loop invariant (6) + // Therefore result+mult*(eng()-bmin)<range+1 by (5), (6) (7) + // + // Postcondition: result < mult*(brange+1) + // + // result<mult loop invariant (1) + // eng()-bmin<=brange eng() post. (2) + // Therefore result+mult*(eng()-bmin) < + // mult+mult*(eng()-bmin) by (1) (3) + // Therefore result+(eng()-bmin)*mult < + // mult+mult*brange by (2), (3) (4) + // Therefore result+(eng()-bmin)*mult < + // mult*(brange+1) by (4) + result += static_cast<range_type>(random::detail::subtract<base_result>()(eng(), bmin) * mult); + + // equivalent to (mult * (brange+1)) == range+1, but avoids overflow. + if(mult * range_type(brange) == range - mult + 1) { + // The destination range is an integer power of + // the generator's range. + return(result); + } + + // Postcondition: mult <= range + // + // limit*(brange+1)<=range+1 def. of limit (1) + // mult<=limit loop condition (2) + // Therefore mult*(brange+1)<=range+1 by (1), (2) (3) + // mult*(brange+1)!=range+1 preceding if (4) + // Therefore mult*(brange+1)<range+1 by (3), (4) (5) + // + // Postcondition: result < mult + // + // See the second postcondition on the change to result. + mult *= range_type(brange)+range_type(1); + } + // loop postcondition: range/mult < brange+1 + // + // mult > limit loop condition (1) + // Suppose range/mult >= brange+1 Assumption (2) + // range >= mult*(brange+1) by (2) (3) + // range+1 > mult*(brange+1) by (3) (4) + // range+1 > (limit+1)*(brange+1) by (1), (4) (5) + // (range+1)/(brange+1) > limit+1 by (5) (6) + // limit < floor((range+1)/(brange+1)) by (6) (7) + // limit==floor((range+1)/(brange+1)) def. of limit (8) + // not (2) reductio (9) + // + // loop postcondition: (range/mult)*mult+(mult-1) >= range + // + // (range/mult)*mult + range%mult == range identity (1) + // range%mult < mult def. of % (2) + // (range/mult)*mult+mult > range by (1), (2) (3) + // (range/mult)*mult+(mult-1) >= range by (3) (4) + // + // Note that the maximum value of result at this point is (mult-1), + // so after this final step, we generate numbers that can be + // at least as large as range. We have to really careful to avoid + // overflow in this final addition and in the rejection. Anything + // that overflows is larger than range and can thus be rejected. + + // range/mult < brange+1 -> no endless loop + range_type result_increment = uniform_int<range_type>(0, range/mult)(eng); + if((std::numeric_limits<range_type>::max)() / mult < result_increment) { + // The multiplcation would overflow. Reject immediately. + continue; + } + result_increment *= mult; + // unsigned integers are guaranteed to wrap on overflow. + result += result_increment; + if(result < result_increment) { + // The addition overflowed. Reject. + continue; + } + if(result > range) { + // Too big. Reject. + continue; + } + return random::detail::add<range_type, result_type>()(result, min_value); + } + } else { // brange > range + base_unsigned bucket_size; + // it's safe to add 1 to range, as long as we cast it first, + // because we know that it is less than brange. However, + // we do need to be careful not to cause overflow by adding 1 + // to brange. + if(brange == (std::numeric_limits<base_unsigned>::max)()) { + bucket_size = brange / (static_cast<base_unsigned>(range)+1); + if(brange % (static_cast<base_unsigned>(range)+1) == static_cast<base_unsigned>(range)) { + ++bucket_size; + } + } else { + bucket_size = (brange+1) / (static_cast<base_unsigned>(range)+1); + } + for(;;) { + base_unsigned result = + random::detail::subtract<base_result>()(eng(), bmin); + result /= bucket_size; + // result and range are non-negative, and result is possibly larger + // than range, so the cast is safe + if(result <= static_cast<base_unsigned>(range)) + return random::detail::add<base_unsigned, result_type>()(result, min_value); + } + } + } + + void init() + { + _range = random::detail::subtract<result_type>()(_max, _min); + } + + // The result_type may be signed or unsigned, but the _range is always + // unsigned. + result_type _min, _max; + range_type _range; +}; + +} // namespace boost + +#endif // BOOST_RANDOM_UNIFORM_INT_HPP diff --git a/Utilities/BGL/boost/random/uniform_on_sphere.hpp b/Utilities/BGL/boost/random/uniform_on_sphere.hpp new file mode 100755 index 0000000000000000000000000000000000000000..80c8bce75e8f5b88a83780ee295d53b97160bece --- /dev/null +++ b/Utilities/BGL/boost/random/uniform_on_sphere.hpp @@ -0,0 +1,87 @@ +/* boost random/uniform_on_sphere.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: uniform_on_sphere.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $ + * + * Revision history + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_UNIFORM_ON_SPHERE_HPP +#define BOOST_RANDOM_UNIFORM_ON_SPHERE_HPP + +#include <vector> +#include <algorithm> // std::transform +#include <functional> // std::bind2nd, std::divides +#include <boost/random/detail/config.hpp> +#include <boost/random/normal_distribution.hpp> + +namespace boost { + +template<class RealType = double, class Cont = std::vector<RealType> > +class uniform_on_sphere +{ +public: + typedef RealType input_type; + typedef Cont result_type; + + explicit uniform_on_sphere(int dim = 2) : _container(dim), _dim(dim) { } + + // compiler-generated copy ctor and assignment operator are fine + + void reset() { _normal.reset(); } + + template<class Engine> + const result_type & operator()(Engine& eng) + { + RealType sqsum = 0; + for(typename Cont::iterator it = _container.begin(); + it != _container.end(); + ++it) { + RealType val = _normal(eng); + *it = val; + sqsum += val * val; + } +#ifndef BOOST_NO_STDC_NAMESPACE + using std::sqrt; +#endif + // for all i: result[i] /= sqrt(sqsum) + std::transform(_container.begin(), _container.end(), _container.begin(), + std::bind2nd(std::divides<RealType>(), sqrt(sqsum))); + return _container; + } + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const uniform_on_sphere& sd) + { + os << sd._dim; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, uniform_on_sphere& sd) + { + is >> std::ws >> sd._dim; + sd._container.resize(sd._dim); + return is; + } +#endif + +private: + normal_distribution<RealType> _normal; + result_type _container; + int _dim; +}; + +} // namespace boost + +#endif // BOOST_RANDOM_UNIFORM_ON_SPHERE_HPP diff --git a/Utilities/BGL/boost/random/uniform_real.hpp b/Utilities/BGL/boost/random/uniform_real.hpp new file mode 100755 index 0000000000000000000000000000000000000000..83f95669699d68b58e93b634f123455e6eacb1a2 --- /dev/null +++ b/Utilities/BGL/boost/random/uniform_real.hpp @@ -0,0 +1,86 @@ +/* boost random/uniform_real.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: uniform_real.hpp 56814 2009-10-14 04:54:01Z steven_watanabe $ + * + * Revision history + * 2001-04-08 added min<max assertion (N. Becker) + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_UNIFORM_REAL_HPP +#define BOOST_RANDOM_UNIFORM_REAL_HPP + +#include <cassert> +#include <iostream> +#include <boost/config.hpp> +#include <boost/limits.hpp> +#include <boost/static_assert.hpp> +#include <boost/random/detail/config.hpp> + +namespace boost { + +// uniform distribution on a real range +template<class RealType = double> +class uniform_real +{ +public: + typedef RealType input_type; + typedef RealType result_type; + + explicit uniform_real(RealType min_arg = RealType(0), + RealType max_arg = RealType(1)) + : _min(min_arg), _max(max_arg) + { +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer); +#endif + assert(min_arg <= max_arg); + } + + // compiler-generated copy ctor and assignment operator are fine + + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; } + void reset() { } + + template<class Engine> + result_type operator()(Engine& eng) { + result_type numerator = static_cast<result_type>(eng() - eng.min BOOST_PREVENT_MACRO_SUBSTITUTION()); + result_type divisor = static_cast<result_type>(eng.max BOOST_PREVENT_MACRO_SUBSTITUTION() - eng.min BOOST_PREVENT_MACRO_SUBSTITUTION()); + assert(divisor > 0); + assert(numerator >= 0 && numerator <= divisor); + return numerator / divisor * (_max - _min) + _min; + } + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const uniform_real& ud) + { + os << ud._min << " " << ud._max; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, uniform_real& ud) + { + is >> std::ws >> ud._min >> std::ws >> ud._max; + return is; + } +#endif + +private: + RealType _min, _max; +}; + +} // namespace boost + +#endif // BOOST_RANDOM_UNIFORM_REAL_HPP diff --git a/Utilities/BGL/boost/random/uniform_smallint.hpp b/Utilities/BGL/boost/random/uniform_smallint.hpp new file mode 100755 index 0000000000000000000000000000000000000000..3308bcafe4f6e5548e12b81c0be4688f3c8ff7db --- /dev/null +++ b/Utilities/BGL/boost/random/uniform_smallint.hpp @@ -0,0 +1,108 @@ +/* boost random/uniform_smallint.hpp header file + * + * Copyright Jens Maurer 2000-2001 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: uniform_smallint.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $ + * + * Revision history + * 2001-04-08 added min<max assertion (N. Becker) + * 2001-02-18 moved to individual header files + */ + +#ifndef BOOST_RANDOM_UNIFORM_SMALLINT_HPP +#define BOOST_RANDOM_UNIFORM_SMALLINT_HPP + +#include <cassert> +#include <iostream> +#include <boost/config.hpp> +#include <boost/limits.hpp> +#include <boost/static_assert.hpp> +#include <boost/random/detail/config.hpp> +#include <boost/random/uniform_01.hpp> +#include <boost/detail/workaround.hpp> + +namespace boost { + +// uniform integer distribution on a small range [min, max] + +template<class IntType = int> +class uniform_smallint +{ +public: + typedef IntType input_type; + typedef IntType result_type; + + explicit uniform_smallint(IntType min_arg = 0, IntType max_arg = 9) + : _min(min_arg), _max(max_arg) + { +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + // MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope + BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer); +#endif + } + + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; } + void reset() { } + + template<class Engine> + result_type operator()(Engine& eng) + { + typedef typename Engine::result_type base_result; + base_result _range = static_cast<base_result>(_max-_min)+1; + base_result _factor = 1; + + // LCGs get bad when only taking the low bits. + // (probably put this logic into a partial template specialization) + // Check how many low bits we can ignore before we get too much + // quantization error. + base_result r_base = (eng.max)() - (eng.min)(); + if(r_base == (std::numeric_limits<base_result>::max)()) { + _factor = 2; + r_base /= 2; + } + r_base += 1; + if(r_base % _range == 0) { + // No quantization effects, good + _factor = r_base / _range; + } else { + // carefully avoid overflow; pessimizing here + for( ; r_base/_range/32 >= _range; _factor *= 2) + r_base /= 2; + } + + return ((eng() - (eng.min)()) / _factor) % _range + _min; + } + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const uniform_smallint& ud) + { + os << ud._min << " " << ud._max; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, uniform_smallint& ud) + { + is >> std::ws >> ud._min >> std::ws >> ud._max; + return is; + } +#endif + +private: + + result_type _min; + result_type _max; +}; + +} // namespace boost + +#endif // BOOST_RANDOM_UNIFORM_SMALLINT_HPP diff --git a/Utilities/BGL/boost/random/variate_generator.hpp b/Utilities/BGL/boost/random/variate_generator.hpp new file mode 100755 index 0000000000000000000000000000000000000000..691af20136998ef17cad9488223eb47c6e9f92e9 --- /dev/null +++ b/Utilities/BGL/boost/random/variate_generator.hpp @@ -0,0 +1,137 @@ +/* boost random/variate_generator.hpp header file + * + * Copyright Jens Maurer 2002 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: variate_generator.hpp 58649 2010-01-02 21:23:17Z steven_watanabe $ + * + */ + +#ifndef BOOST_RANDOM_RANDOM_GENERATOR_HPP +#define BOOST_RANDOM_RANDOM_GENERATOR_HPP + +#include <boost/config.hpp> + +// implementation details +#include <boost/detail/workaround.hpp> +#include <boost/random/uniform_01.hpp> +#include <boost/random/detail/pass_through_engine.hpp> +#include <boost/random/detail/uniform_int_float.hpp> +#include <boost/random/detail/ptr_helper.hpp> + +// Borland C++ 5.6.0 has problems using its numeric_limits traits as +// template parameters +#if BOOST_WORKAROUND(__BORLANDC__, <= 0x564) +#include <boost/type_traits/is_integral.hpp> +#endif + +#include <boost/random/detail/disable_warnings.hpp> + +namespace boost { + +namespace random { +namespace detail { + +template<bool have_int, bool want_int> +struct engine_helper; + +// for consistency, always have two levels of decorations +template<> +struct engine_helper<true, true> +{ + template<class Engine, class DistInputType> + struct impl + { + typedef pass_through_engine<Engine> type; + }; +}; + +template<> +struct engine_helper<false, false> +{ + template<class Engine, class DistInputType> + struct impl + { + typedef uniform_01<Engine, DistInputType> type; + }; +}; + +template<> +struct engine_helper<true, false> +{ + template<class Engine, class DistInputType> + struct impl + { + typedef uniform_01<Engine, DistInputType> type; + }; +}; + +template<> +struct engine_helper<false, true> +{ + template<class Engine, class DistInputType> + struct impl + { + typedef uniform_int_float<Engine, unsigned long> type; + }; +}; + +} // namespace detail +} // namespace random + + +template<class Engine, class Distribution> +class variate_generator +{ +private: + typedef random::detail::pass_through_engine<Engine> decorated_engine; + +public: + typedef typename decorated_engine::base_type engine_value_type; + typedef Engine engine_type; + typedef Distribution distribution_type; + typedef typename Distribution::result_type result_type; + + variate_generator(Engine e, Distribution d) + : _eng(decorated_engine(e)), _dist(d) { } + + result_type operator()() { return _dist(_eng); } + template<class T> + result_type operator()(T value) { return _dist(_eng, value); } + + engine_value_type& engine() { return _eng.base().base(); } + const engine_value_type& engine() const { return _eng.base().base(); } + + distribution_type& distribution() { return _dist; } + const distribution_type& distribution() const { return _dist; } + + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().min)(); } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().max)(); } + +private: +#if BOOST_WORKAROUND(__BORLANDC__, <= 0x564) + typedef typename random::detail::engine_helper< + boost::is_integral<typename decorated_engine::result_type>::value, + boost::is_integral<typename Distribution::input_type>::value + >::BOOST_NESTED_TEMPLATE impl<decorated_engine, typename Distribution::input_type>::type internal_engine_type; +#else + enum { + have_int = std::numeric_limits<typename decorated_engine::result_type>::is_integer, + want_int = std::numeric_limits<typename Distribution::input_type>::is_integer + }; + typedef typename random::detail::engine_helper<have_int, want_int>::BOOST_NESTED_TEMPLATE impl<decorated_engine, typename Distribution::input_type>::type internal_engine_type; +#endif + + internal_engine_type _eng; + distribution_type _dist; +}; + +} // namespace boost + +#include <boost/random/detail/disable_warnings.hpp> + +#endif // BOOST_RANDOM_RANDOM_GENERATOR_HPP diff --git a/Utilities/BGL/boost/random/xor_combine.hpp b/Utilities/BGL/boost/random/xor_combine.hpp new file mode 100755 index 0000000000000000000000000000000000000000..c962be085a4f23cc085d12106649facc3340489b --- /dev/null +++ b/Utilities/BGL/boost/random/xor_combine.hpp @@ -0,0 +1,134 @@ +/* boost random/xor_combine.hpp header file + * + * Copyright Jens Maurer 2002 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: xor_combine.hpp 53871 2009-06-13 17:54:06Z steven_watanabe $ + * + */ + +#ifndef BOOST_RANDOM_XOR_COMBINE_HPP +#define BOOST_RANDOM_XOR_COMBINE_HPP + +#include <iostream> +#include <cassert> +#include <algorithm> // for std::min and std::max +#include <boost/config.hpp> +#include <boost/limits.hpp> +#include <boost/static_assert.hpp> +#include <boost/cstdint.hpp> // uint32_t +#include <boost/random/detail/config.hpp> + + +namespace boost { +namespace random { + +#ifndef BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS + #define BOOST_RANDOM_VAL_TYPE typename URNG1::result_type +#else + #define BOOST_RANDOM_VAL_TYPE uint32_t +#endif + +template<class URNG1, int s1, class URNG2, int s2, BOOST_RANDOM_VAL_TYPE val = 0> +class xor_combine +{ +public: + typedef URNG1 base1_type; + typedef URNG2 base2_type; + typedef typename base1_type::result_type result_type; + + BOOST_STATIC_CONSTANT(bool, has_fixed_range = false); + BOOST_STATIC_CONSTANT(int, shift1 = s1); + BOOST_STATIC_CONSTANT(int, shift2 = s2); + + xor_combine() : _rng1(), _rng2() + { } + xor_combine(const base1_type & rng1, const base2_type & rng2) + : _rng1(rng1), _rng2(rng2) { } + xor_combine(const result_type & v) + : _rng1(v), _rng2(v) { } + template<class It> xor_combine(It& first, It last) + : _rng1(first, last), _rng2( /* advanced by other call */ first, last) { } + void seed() { _rng1.seed(); _rng2.seed(); } + void seed(const result_type & v) { _rng1.seed(v); _rng2.seed(v); } + template<class It> void seed(It& first, It last) + { + _rng1.seed(first, last); + _rng2.seed(first, last); + } + + const base1_type& base1() { return _rng1; } + const base2_type& base2() { return _rng2; } + + result_type operator()() + { + // MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope +#if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300) + BOOST_STATIC_ASSERT(std::numeric_limits<typename base1_type::result_type>::is_integer); + BOOST_STATIC_ASSERT(std::numeric_limits<typename base2_type::result_type>::is_integer); + BOOST_STATIC_ASSERT(std::numeric_limits<typename base1_type::result_type>::digits >= std::numeric_limits<typename base2_type::result_type>::digits); +#endif + return (_rng1() << s1) ^ (_rng2() << s2); + } + + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return std::min BOOST_PREVENT_MACRO_SUBSTITUTION((_rng1.min)(), (_rng2.min)()); } + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return std::max BOOST_PREVENT_MACRO_SUBSTITUTION((_rng1.min)(), (_rng2.max)()); } + static bool validation(result_type x) { return val == x; } + +#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE + +#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS + template<class CharT, class Traits> + friend std::basic_ostream<CharT,Traits>& + operator<<(std::basic_ostream<CharT,Traits>& os, const xor_combine& s) + { + os << s._rng1 << " " << s._rng2 << " "; + return os; + } + + template<class CharT, class Traits> + friend std::basic_istream<CharT,Traits>& + operator>>(std::basic_istream<CharT,Traits>& is, xor_combine& s) + { + is >> s._rng1 >> std::ws >> s._rng2 >> std::ws; + return is; + } +#endif + + friend bool operator==(const xor_combine& x, const xor_combine& y) + { return x._rng1 == y._rng1 && x._rng2 == y._rng2; } + friend bool operator!=(const xor_combine& x, const xor_combine& y) + { return !(x == y); } +#else + // Use a member function; Streamable concept not supported. + bool operator==(const xor_combine& rhs) const + { return _rng1 == rhs._rng1 && _rng2 == rhs._rng2; } + bool operator!=(const xor_combine& rhs) const + { return !(*this == rhs); } +#endif + +private: + base1_type _rng1; + base2_type _rng2; +}; + +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION +// A definition is required even for integral static constants +template<class URNG1, int s1, class URNG2, int s2, BOOST_RANDOM_VAL_TYPE val> +const bool xor_combine<URNG1, s1, URNG2, s2, val>::has_fixed_range; +template<class URNG1, int s1, class URNG2, int s2, BOOST_RANDOM_VAL_TYPE val> +const int xor_combine<URNG1, s1, URNG2, s2, val>::shift1; +template<class URNG1, int s1, class URNG2, int s2, BOOST_RANDOM_VAL_TYPE val> +const int xor_combine<URNG1, s1, URNG2, s2, val>::shift2; +#endif + +#undef BOOST_RANDOM_VAL_TYPE + +} // namespace random +} // namespace boost + +#endif // BOOST_RANDOM_XOR_COMBINE_HPP diff --git a/Utilities/BGL/boost/token_functions.hpp b/Utilities/BGL/boost/token_functions.hpp new file mode 100755 index 0000000000000000000000000000000000000000..6c931851ae5c460b8ce0db7d4b0fd793d1154633 --- /dev/null +++ b/Utilities/BGL/boost/token_functions.hpp @@ -0,0 +1,621 @@ +// Boost token_functions.hpp ------------------------------------------------// + +// Copyright John R. Bandela 2001. + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/libs/tokenizer/ for documentation. + +// Revision History: +// 01 Oct 2004 Joaquin M Lopez Munoz +// Workaround for a problem with string::assign in msvc-stlport +// 06 Apr 2004 John Bandela +// Fixed a bug involving using char_delimiter with a true input iterator +// 28 Nov 2003 Robert Zeh and John Bandela +// Converted into "fast" functions that avoid using += when +// the supplied iterator isn't an input_iterator; based on +// some work done at Archelon and a version that was checked into +// the boost CVS for a short period of time. +// 20 Feb 2002 John Maddock +// Removed using namespace std declarations and added +// workaround for BOOST_NO_STDC_NAMESPACE (the library +// can be safely mixed with regex). +// 06 Feb 2002 Jeremy Siek +// Added char_separator. +// 02 Feb 2002 Jeremy Siek +// Removed tabs and a little cleanup. + + +#ifndef BOOST_TOKEN_FUNCTIONS_JRB120303_HPP_ +#define BOOST_TOKEN_FUNCTIONS_JRB120303_HPP_ + +#include <vector> +#include <stdexcept> +#include <string> +#include <cctype> +#include <algorithm> // for find_if +#include <boost/config.hpp> +#include <boost/assert.hpp> +#include <boost/detail/workaround.hpp> +#include <boost/mpl/if.hpp> + +// +// the following must not be macros if we are to prefix them +// with std:: (they shouldn't be macros anyway...) +// +#ifdef ispunct +# undef ispunct +#endif +#ifdef isspace +# undef isspace +#endif +// +// fix namespace problems: +// +#ifdef BOOST_NO_STDC_NAMESPACE +namespace std{ + using ::ispunct; + using ::isspace; +} +#endif + +namespace boost{ + + //=========================================================================== + // The escaped_list_separator class. Which is a model of TokenizerFunction + // An escaped list is a super-set of what is commonly known as a comma + // separated value (csv) list.It is separated into fields by a comma or + // other character. If the delimiting character is inside quotes, then it is + // counted as a regular character.To allow for embedded quotes in a field, + // there can be escape sequences using the \ much like C. + // The role of the comma, the quotation mark, and the escape + // character (backslash \), can be assigned to other characters. + + struct escaped_list_error : public std::runtime_error{ + escaped_list_error(const std::string& what_arg):std::runtime_error(what_arg) { } + }; + + +// The out of the box GCC 2.95 on cygwin does not have a char_traits class. +// MSVC does not like the following typename +#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 + template <class Char, + class Traits = typename std::basic_string<Char>::traits_type > +#else + template <class Char, + class Traits = std::basic_string<Char>::traits_type > +#endif + class escaped_list_separator { + + private: + typedef std::basic_string<Char,Traits> string_type; + struct char_eq { + Char e_; + char_eq(Char e):e_(e) { } + bool operator()(Char c) { + return Traits::eq(e_,c); + } + }; + string_type escape_; + string_type c_; + string_type quote_; + bool last_; + + bool is_escape(Char e) { + char_eq f(e); + return std::find_if(escape_.begin(),escape_.end(),f)!=escape_.end(); + } + bool is_c(Char e) { + char_eq f(e); + return std::find_if(c_.begin(),c_.end(),f)!=c_.end(); + } + bool is_quote(Char e) { + char_eq f(e); + return std::find_if(quote_.begin(),quote_.end(),f)!=quote_.end(); + } + template <typename iterator, typename Token> + void do_escape(iterator& next,iterator end,Token& tok) { + if (++next == end) + throw escaped_list_error(std::string("cannot end with escape")); + if (Traits::eq(*next,'n')) { + tok+='\n'; + return; + } + else if (is_quote(*next)) { + tok+=*next; + return; + } + else if (is_c(*next)) { + tok+=*next; + return; + } + else if (is_escape(*next)) { + tok+=*next; + return; + } + else + throw escaped_list_error(std::string("unknown escape sequence")); + } + + public: + + explicit escaped_list_separator(Char e = '\\', + Char c = ',',Char q = '\"') + : escape_(1,e), c_(1,c), quote_(1,q), last_(false) { } + + escaped_list_separator(string_type e, string_type c, string_type q) + : escape_(e), c_(c), quote_(q), last_(false) { } + + void reset() {last_=false;} + + template <typename InputIterator, typename Token> + bool operator()(InputIterator& next,InputIterator end,Token& tok) { + bool bInQuote = false; + tok = Token(); + + if (next == end) { + if (last_) { + last_ = false; + return true; + } + else + return false; + } + last_ = false; + for (;next != end;++next) { + if (is_escape(*next)) { + do_escape(next,end,tok); + } + else if (is_c(*next)) { + if (!bInQuote) { + // If we are not in quote, then we are done + ++next; + // The last character was a c, that means there is + // 1 more blank field + last_ = true; + return true; + } + else tok+=*next; + } + else if (is_quote(*next)) { + bInQuote=!bInQuote; + } + else { + tok += *next; + } + } + return true; + } + }; + + //=========================================================================== + // The classes here are used by offset_separator and char_separator to implement + // faster assigning of tokens using assign instead of += + + namespace tokenizer_detail { + + // The assign_or_plus_equal struct contains functions that implement + // assign, +=, and clearing based on the iterator type. The + // generic case does nothing for plus_equal and clearing, while + // passing through the call for assign. + // + // When an input iterator is being used, the situation is reversed. + // The assign method does nothing, plus_equal invokes operator +=, + // and the clearing method sets the supplied token to the default + // token constructor's result. + // + + template<class IteratorTag> + struct assign_or_plus_equal { + template<class Iterator, class Token> + static void assign(Iterator b, Iterator e, Token &t) { + +#if BOOST_WORKAROUND(BOOST_MSVC, < 1300) &&\ + BOOST_WORKAROUND(__SGI_STL_PORT, < 0x500) &&\ + defined(_STLP_DEBUG) &&\ + (defined(_STLP_USE_DYNAMIC_LIB) || defined(_DLL)) + // Problem with string::assign for msvc-stlport in debug mode: the + // linker tries to import the templatized version of this memfun, + // which is obviously not exported. + // See http://www.stlport.com/dcforum/DCForumID6/1763.html for details. + + t = Token(); + while(b != e) t += *b++; +#else + t.assign(b, e); +#endif + + } + + template<class Token, class Value> + static void plus_equal(Token &, const Value &) { + + } + + // If we are doing an assign, there is no need for the + // the clear. + // + template<class Token> + static void clear(Token &) { + + } + }; + + template <> + struct assign_or_plus_equal<std::input_iterator_tag> { + template<class Iterator, class Token> + static void assign(Iterator b, Iterator e, Token &t) { + + } + template<class Token, class Value> + static void plus_equal(Token &t, const Value &v) { + t += v; + } + template<class Token> + static void clear(Token &t) { + t = Token(); + } + }; + + + template<class Iterator> + struct pointer_iterator_category{ + typedef std::random_access_iterator_tag type; + }; + + + template<class Iterator> + struct class_iterator_category{ + typedef typename Iterator::iterator_category type; + }; + + + + // This portably gets the iterator_tag without partial template specialization + template<class Iterator> + struct get_iterator_category{ + typedef typename mpl::if_<is_pointer<Iterator>, + pointer_iterator_category<Iterator>, + class_iterator_category<Iterator> + >::type cat; + + typedef typename cat::type iterator_category; + }; + + +} + + + //=========================================================================== + // The offset_separator class, which is a model of TokenizerFunction. + // Offset breaks a string into tokens based on a range of offsets + + class offset_separator { + private: + + std::vector<int> offsets_; + unsigned int current_offset_; + bool wrap_offsets_; + bool return_partial_last_; + + public: + template <typename Iter> + offset_separator(Iter begin, Iter end, bool wrap_offsets = true, + bool return_partial_last = true) + : offsets_(begin,end), current_offset_(0), + wrap_offsets_(wrap_offsets), + return_partial_last_(return_partial_last) { } + + offset_separator() + : offsets_(1,1), current_offset_(), + wrap_offsets_(true), return_partial_last_(true) { } + + void reset() { + current_offset_ = 0; + } + + template <typename InputIterator, typename Token> + bool operator()(InputIterator& next, InputIterator end, Token& tok) + { + typedef tokenizer_detail::assign_or_plus_equal< +#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 + typename +#endif + tokenizer_detail::get_iterator_category< + InputIterator>::iterator_category> assigner; + + + BOOST_ASSERT(!offsets_.empty()); + + assigner::clear(tok); + InputIterator start(next); + + if (next == end) + return false; + + if (current_offset_ == offsets_.size()) + { + if (wrap_offsets_) + current_offset_=0; + else + return false; + } + + int c = offsets_[current_offset_]; + int i = 0; + for (; i < c; ++i) { + if (next == end)break; + assigner::plus_equal(tok,*next++); + } + assigner::assign(start,next,tok); + + if (!return_partial_last_) + if (i < (c-1) ) + return false; + + ++current_offset_; + return true; + } + }; + + + //=========================================================================== + // The char_separator class breaks a sequence of characters into + // tokens based on the character delimiters (very much like bad old + // strtok). A delimiter character can either be kept or dropped. A + // kept delimiter shows up as an output token, whereas a dropped + // delimiter does not. + + // This class replaces the char_delimiters_separator class. The + // constructor for the char_delimiters_separator class was too + // confusing and needed to be deprecated. However, because of the + // default arguments to the constructor, adding the new constructor + // would cause ambiguity, so instead I deprecated the whole class. + // The implementation of the class was also simplified considerably. + + enum empty_token_policy { drop_empty_tokens, keep_empty_tokens }; + + // The out of the box GCC 2.95 on cygwin does not have a char_traits class. +#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 + template <typename Char, + typename Traits = typename std::basic_string<Char>::traits_type > +#else + template <typename Char, + typename Traits = std::basic_string<Char>::traits_type > +#endif + class char_separator + { + typedef std::basic_string<Char,Traits> string_type; + public: + explicit + char_separator(const Char* dropped_delims, + const Char* kept_delims = 0, + empty_token_policy empty_tokens = drop_empty_tokens) + : m_dropped_delims(dropped_delims), + m_use_ispunct(false), + m_use_isspace(false), + m_empty_tokens(empty_tokens), + m_output_done(false) + { + // Borland workaround + if (kept_delims) + m_kept_delims = kept_delims; + } + + // use ispunct() for kept delimiters and isspace for dropped. + explicit + char_separator() + : m_use_ispunct(true), + m_use_isspace(true), + m_empty_tokens(drop_empty_tokens) { } + + void reset() { } + + template <typename InputIterator, typename Token> + bool operator()(InputIterator& next, InputIterator end, Token& tok) + { + typedef tokenizer_detail::assign_or_plus_equal< +#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 + typename +#endif + tokenizer_detail::get_iterator_category< + InputIterator>::iterator_category> assigner; + + assigner::clear(tok); + + // skip past all dropped_delims + if (m_empty_tokens == drop_empty_tokens) + for (; next != end && is_dropped(*next); ++next) + { } + + InputIterator start(next); + + if (m_empty_tokens == drop_empty_tokens) { + + if (next == end) + return false; + + + // if we are on a kept_delims move past it and stop + if (is_kept(*next)) { + assigner::plus_equal(tok,*next); + ++next; + } else + // append all the non delim characters + for (; next != end && !is_dropped(*next) && !is_kept(*next); ++next) + assigner::plus_equal(tok,*next); + } + else { // m_empty_tokens == keep_empty_tokens + + // Handle empty token at the end + if (next == end) + { + if (m_output_done == false) + { + m_output_done = true; + assigner::assign(start,next,tok); + return true; + } + else + return false; + } + + if (is_kept(*next)) { + if (m_output_done == false) + m_output_done = true; + else { + assigner::plus_equal(tok,*next); + ++next; + m_output_done = false; + } + } + else if (m_output_done == false && is_dropped(*next)) { + m_output_done = true; + } + else { + if (is_dropped(*next)) + start=++next; + for (; next != end && !is_dropped(*next) && !is_kept(*next); ++next) + assigner::plus_equal(tok,*next); + m_output_done = true; + } + } + assigner::assign(start,next,tok); + return true; + } + + private: + string_type m_kept_delims; + string_type m_dropped_delims; + bool m_use_ispunct; + bool m_use_isspace; + empty_token_policy m_empty_tokens; + bool m_output_done; + + bool is_kept(Char E) const + { + if (m_kept_delims.length()) + return m_kept_delims.find(E) != string_type::npos; + else if (m_use_ispunct) { + return std::ispunct(E) != 0; + } else + return false; + } + bool is_dropped(Char E) const + { + if (m_dropped_delims.length()) + return m_dropped_delims.find(E) != string_type::npos; + else if (m_use_isspace) { + return std::isspace(E) != 0; + } else + return false; + } + }; + + //=========================================================================== + // The following class is DEPRECATED, use class char_separators instead. + // + // The char_delimiters_separator class, which is a model of + // TokenizerFunction. char_delimiters_separator breaks a string + // into tokens based on character delimiters. There are 2 types of + // delimiters. returnable delimiters can be returned as + // tokens. These are often punctuation. nonreturnable delimiters + // cannot be returned as tokens. These are often whitespace + + // The out of the box GCC 2.95 on cygwin does not have a char_traits class. +#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 + template <class Char, + class Traits = typename std::basic_string<Char>::traits_type > +#else + template <class Char, + class Traits = std::basic_string<Char>::traits_type > +#endif + class char_delimiters_separator { + private: + + typedef std::basic_string<Char,Traits> string_type; + string_type returnable_; + string_type nonreturnable_; + bool return_delims_; + bool no_ispunct_; + bool no_isspace_; + + bool is_ret(Char E)const + { + if (returnable_.length()) + return returnable_.find(E) != string_type::npos; + else{ + if (no_ispunct_) {return false;} + else{ + int r = std::ispunct(E); + return r != 0; + } + } + } + bool is_nonret(Char E)const + { + if (nonreturnable_.length()) + return nonreturnable_.find(E) != string_type::npos; + else{ + if (no_isspace_) {return false;} + else{ + int r = std::isspace(E); + return r != 0; + } + } + } + + public: + explicit char_delimiters_separator(bool return_delims = false, + const Char* returnable = 0, + const Char* nonreturnable = 0) + : returnable_(returnable ? returnable : string_type().c_str()), + nonreturnable_(nonreturnable ? nonreturnable:string_type().c_str()), + return_delims_(return_delims), no_ispunct_(returnable!=0), + no_isspace_(nonreturnable!=0) { } + + void reset() { } + + public: + + template <typename InputIterator, typename Token> + bool operator()(InputIterator& next, InputIterator end,Token& tok) { + tok = Token(); + + // skip past all nonreturnable delims + // skip past the returnable only if we are not returning delims + for (;next!=end && ( is_nonret(*next) || (is_ret(*next) + && !return_delims_ ) );++next) { } + + if (next == end) { + return false; + } + + // if we are to return delims and we are one a returnable one + // move past it and stop + if (is_ret(*next) && return_delims_) { + tok+=*next; + ++next; + } + else + // append all the non delim characters + for (;next!=end && !is_nonret(*next) && !is_ret(*next);++next) + tok+=*next; + + + return true; + } + }; + + +} //namespace boost + + +#endif + + + + + diff --git a/Utilities/BGL/boost/token_iterator.hpp b/Utilities/BGL/boost/token_iterator.hpp new file mode 100755 index 0000000000000000000000000000000000000000..b8fe8497381ad073e1d7b7a48c58896705f8cfee --- /dev/null +++ b/Utilities/BGL/boost/token_iterator.hpp @@ -0,0 +1,128 @@ +// Boost token_iterator.hpp -------------------------------------------------// + +// Copyright John R. Bandela 2001 +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/libs/tokenizer for documentation. + +// Revision History: +// 16 Jul 2003 John Bandela +// Allowed conversions from convertible base iterators +// 03 Jul 2003 John Bandela +// Converted to new iterator adapter + + + +#ifndef BOOST_TOKENIZER_POLICY_JRB070303_HPP_ +#define BOOST_TOKENIZER_POLICY_JRB070303_HPP_ + +#include<boost/assert.hpp> +#include<boost/iterator/iterator_adaptor.hpp> +#include<boost/iterator/detail/minimum_category.hpp> +#include<boost/token_functions.hpp> +#include<utility> + +namespace boost +{ + template <class TokenizerFunc, class Iterator, class Type> + class token_iterator + : public iterator_facade< + token_iterator<TokenizerFunc, Iterator, Type> + , Type + , typename detail::minimum_category< + forward_traversal_tag + , typename iterator_traversal<Iterator>::type + >::type + , const Type& + > + { + + friend class iterator_core_access; + + TokenizerFunc f_; + Iterator begin_; + Iterator end_; + bool valid_; + Type tok_; + + void increment(){ + BOOST_ASSERT(valid_); + valid_ = f_(begin_,end_,tok_); + } + + const Type& dereference() const { + BOOST_ASSERT(valid_); + return tok_; + } + template<class Other> + bool equal(const Other& a) const{ + return (a.valid_ && valid_) + ?( (a.begin_==begin_) && (a.end_ == end_) ) + :(a.valid_==valid_); + + } + + void initialize(){ + if(valid_) return; + f_.reset(); + valid_ = (begin_ != end_)? + f_(begin_,end_,tok_):false; + } + public: + token_iterator():begin_(),end_(),valid_(false),tok_() { } + + token_iterator(TokenizerFunc f, Iterator begin, Iterator e = Iterator()) + : f_(f),begin_(begin),end_(e),valid_(false),tok_(){ initialize(); } + + token_iterator(Iterator begin, Iterator e = Iterator()) + : f_(),begin_(begin),end_(e),valid_(false),tok_() {initialize();} + + template<class OtherIter> + token_iterator( + token_iterator<TokenizerFunc, OtherIter,Type> const& t + , typename enable_if_convertible<OtherIter, Iterator>::type* = 0) + : f_(t.tokenizer_function()),begin_(t.base()) + ,end_(t.end()),valid_(!t.at_end()),tok_(t.current_token()) {} + + Iterator base()const{return begin_;} + + Iterator end()const{return end_;}; + + TokenizerFunc tokenizer_function()const{return f_;} + + Type current_token()const{return tok_;} + + bool at_end()const{return !valid_;} + + + + + }; + template < + class TokenizerFunc = char_delimiters_separator<char>, + class Iterator = std::string::const_iterator, + class Type = std::string + > + class token_iterator_generator { + + private: + public: + typedef token_iterator<TokenizerFunc,Iterator,Type> type; + }; + + + // Type has to be first because it needs to be explicitly specified + // because there is no way the function can deduce it. + template<class Type, class Iterator, class TokenizerFunc> + typename token_iterator_generator<TokenizerFunc,Iterator,Type>::type + make_token_iterator(Iterator begin, Iterator end,const TokenizerFunc& fun){ + typedef typename + token_iterator_generator<TokenizerFunc,Iterator,Type>::type ret_type; + return ret_type(fun,begin,end); + } + +} // namespace boost + +#endif diff --git a/Utilities/BGL/boost/tokenizer.hpp b/Utilities/BGL/boost/tokenizer.hpp new file mode 100755 index 0000000000000000000000000000000000000000..5164b2a9fb025e61cdd27daa87990e3c136d637e --- /dev/null +++ b/Utilities/BGL/boost/tokenizer.hpp @@ -0,0 +1,98 @@ +// Boost tokenizer.hpp -----------------------------------------------------// + +// (c) Copyright Jeremy Siek and John R. Bandela 2001. + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/libs/tokenizer for documenation + +// Revision History: +// 03 Jul 2003 John Bandela +// Converted to new iterator adapter +// 02 Feb 2002 Jeremy Siek +// Removed tabs and a little cleanup. + +#ifndef BOOST_TOKENIZER_JRB070303_HPP_ +#define BOOST_TOKENIZER_JRB070303_HPP_ + +#include <boost/token_iterator.hpp> + +namespace boost { + + + //=========================================================================== + // A container-view of a tokenized "sequence" + template < + typename TokenizerFunc = char_delimiters_separator<char>, + typename Iterator = std::string::const_iterator, + typename Type = std::string + > + class tokenizer { + private: + typedef token_iterator_generator<TokenizerFunc,Iterator,Type> TGen; + + // It seems that MSVC does not like the unqualified use of iterator, + // Thus we use iter internally when it is used unqualified and + // the users of this class will always qualify iterator. + typedef typename TGen::type iter; + + public: + + typedef iter iterator; + typedef iter const_iterator; + typedef Type value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* pointer; + typedef const pointer const_pointer; + typedef void size_type; + typedef void difference_type; + + tokenizer(Iterator first, Iterator last, + const TokenizerFunc& f = TokenizerFunc()) + : first_(first), last_(last), f_(f) { } + + template <typename Container> + tokenizer(const Container& c) + : first_(c.begin()), last_(c.end()), f_() { } + + template <typename Container> + tokenizer(const Container& c,const TokenizerFunc& f) + : first_(c.begin()), last_(c.end()), f_(f) { } + + void assign(Iterator first, Iterator last){ + first_ = first; + last_ = last; + } + + void assign(Iterator first, Iterator last, const TokenizerFunc& f){ + assign(first,last); + f_ = f; + } + + template <typename Container> + void assign(const Container& c){ + assign(c.begin(),c.end()); + } + + + template <typename Container> + void assign(const Container& c, const TokenizerFunc& f){ + assign(c.begin(),c.end(),f); + } + + iter begin() const { return iter(f_,first_,last_); } + iter end() const { return iter(f_,last_,last_); } + + private: + Iterator first_; + Iterator last_; + TokenizerFunc f_; + }; + + +} // namespace boost + +#endif