Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61366 - in sandbox/geometry: boost/geometry/util libs/geometry/test/iterators libs/geometry/test/util
From: barend.gehrels_at_[hidden]
Date: 2010-04-18 13:41:34


Author: barendgehrels
Date: 2010-04-18 13:41:33 EDT (Sun, 18 Apr 2010)
New Revision: 61366
URL: http://svn.boost.org/trac/boost/changeset/61366

Log:
Added "reversible_view" to allow iterating forward/backward through a range based on a template parameter
Added:
   sandbox/geometry/boost/geometry/util/reversible_view.hpp (contents, props changed)
   sandbox/geometry/libs/geometry/test/util/reversible_view.cpp (contents, props changed)
   sandbox/geometry/libs/geometry/test/util/reversible_view.vcproj (contents, props changed)
Text files modified:
   sandbox/geometry/boost/geometry/util/range_iterator_const_if_c.hpp | 4 ++--
   sandbox/geometry/libs/geometry/test/iterators/iterators.sln | 2 +-
   2 files changed, 3 insertions(+), 3 deletions(-)

Modified: sandbox/geometry/boost/geometry/util/range_iterator_const_if_c.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/util/range_iterator_const_if_c.hpp (original)
+++ sandbox/geometry/boost/geometry/util/range_iterator_const_if_c.hpp 2010-04-18 13:41:33 EDT (Sun, 18 Apr 2010)
@@ -23,8 +23,8 @@
     \ingroup utility
     \details Is used to have one implementation for both const and non const
         range iterators
- \note This traits class is completely independant from GGL and might be a
- separate addition to Boost
+ \note This traits class is completely independant from Boost.Geometry and
+ might be a separate addition to Boost
     \note Used in for_each
 */
 template <bool IsConst, typename Range>

Added: sandbox/geometry/boost/geometry/util/reversible_view.hpp
==============================================================================
--- (empty file)
+++ sandbox/geometry/boost/geometry/util/reversible_view.hpp 2010-04-18 13:41:33 EDT (Sun, 18 Apr 2010)
@@ -0,0 +1,87 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Copyright Barend Gehrels 2010, Geodan, Amsterdam, the Netherlands.
+// Use, modification and distribution is subject to 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)
+
+#ifndef BOOST_GEOMETRY_UTIL_REVERSIBLE_VIEW_HPP
+#define BOOST_GEOMETRY_UTIL_REVERSIBLE_VIEW_HPP
+
+#include <boost/type_traits.hpp>
+#include <boost/type_traits/remove_const.hpp>
+
+#include <boost/geometry/core/ring_type.hpp>
+#include <boost/geometry/core/tag.hpp>
+#include <boost/geometry/core/tags.hpp>
+
+
+namespace boost { namespace geometry {
+
+
+#ifndef DOXYGEN_NO_DETAIL
+namespace detail
+{
+
+template <typename Range>
+struct reversible_base_view
+{
+ Range& m_range;
+ reversible_base_view(Range& r)
+ : m_range(r)
+ {}
+};
+
+}
+#endif
+
+
+enum iterate_direction { iterate_forward, iterate_reverse };
+
+
+template <typename Range, iterate_direction Direction>
+struct reversible_view {};
+
+
+
+template <typename Range>
+struct reversible_view<Range, iterate_forward> : detail::reversible_base_view<Range>
+{
+ reversible_view(Range& r)
+ : reversible_base_view(r)
+ {}
+
+ typedef typename boost::range_iterator<const Range>::type const_iterator;
+ typedef typename boost::range_iterator<Range>::type iterator;
+
+ const_iterator begin() const { return boost::begin(m_range); }
+ const_iterator end() const { return boost::end(m_range); }
+
+ iterator begin() { return boost::begin(m_range); }
+ iterator end() { return boost::end(m_range); }
+};
+
+
+template <typename Range>
+struct reversible_view<Range, iterate_reverse> : detail::reversible_base_view<Range>
+{
+ reversible_view(Range& r)
+ : reversible_base_view(r)
+ {}
+
+ typedef typename boost::range_reverse_iterator<Range const>::type const_iterator;
+ typedef typename boost::range_reverse_iterator<Range>::type iterator;
+
+ const_iterator begin() const { return boost::rbegin(m_range); }
+ const_iterator end() const { return boost::rend(m_range); }
+
+ iterator begin() { return boost::rbegin(m_range); }
+ iterator end() { return boost::rend(m_range); }
+};
+
+
+
+}} // namespace boost::geometry
+
+
+#endif // BOOST_GEOMETRY_UTIL_REVERSIBLE_VIEW_HPP

Modified: sandbox/geometry/libs/geometry/test/iterators/iterators.sln
==============================================================================
--- sandbox/geometry/libs/geometry/test/iterators/iterators.sln (original)
+++ sandbox/geometry/libs/geometry/test/iterators/iterators.sln 2010-04-18 13:41:33 EDT (Sun, 18 Apr 2010)
@@ -1,5 +1,5 @@
 Microsoft Visual Studio Solution File, Format Version 9.00
-# Visual Studio 2005
+# Visual C++ Express 2005
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ever_circling_iterator", "ever_circling_iterator.vcproj", "{73F8C969-FA1E-4D9D-81F9-35B1206F0C14}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "circular_iterator", "circular_iterator.vcproj", "{46571A34-B68D-4854-90C0-56D29EE63FFE}"

Added: sandbox/geometry/libs/geometry/test/util/reversible_view.cpp
==============================================================================
--- (empty file)
+++ sandbox/geometry/libs/geometry/test/util/reversible_view.cpp 2010-04-18 13:41:33 EDT (Sun, 18 Apr 2010)
@@ -0,0 +1,79 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library) test file
+//
+// Copyright Barend Gehrels 2010, Geodan, Amsterdam, the Netherlands
+// Use, modification and distribution is subject to 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)
+
+#include <algorithm>
+#include <iterator>
+#include <sstream>
+#include <string>
+
+#include <geometry_test_common.hpp>
+
+#include <boost/geometry/util/reversible_view.hpp>
+
+#include <boost/geometry/extensions/gis/io/wkt/read_wkt.hpp>
+#include <boost/geometry/util/write_dsv.hpp>
+#include <boost/geometry/geometries/cartesian2d.hpp>
+#include <boost/geometry/geometries/adapted/tuple_cartesian.hpp>
+
+
+template <boost::geometry::iterate_direction Direction, typename Range>
+void test_forward_or_reverse(Range const& range, std::string const& expected)
+{
+ typedef boost::geometry::reversible_view
+ <
+ Range const,
+ Direction
+ > view_type;
+
+ view_type view(range);
+
+ bool first = true;
+ std::ostringstream out;
+ for (typename boost::range_iterator<view_type const>::type
+ it = boost::begin(view);
+ it != boost::end(view);
+ ++it, first = false)
+ {
+ out << (first ? "" : " ") << boost::geometry::dsv(*it);
+ }
+ BOOST_CHECK_EQUAL(out.str(), expected);
+}
+
+
+
+template <typename Geometry>
+void test_geometry(std::string const& wkt,
+ std::string const& expected_forward, std::string const& expected_reverse)
+{
+ namespace bg = boost::geometry;
+ Geometry geo;
+ bg::read_wkt(wkt, geo);
+
+ test_forward_or_reverse<bg::iterate_forward>(geo, expected_forward);
+ test_forward_or_reverse<bg::iterate_reverse>(geo, expected_reverse);
+}
+
+
+template <typename P>
+void test_all()
+{
+ test_geometry<boost::geometry::linestring<P> >(
+ "linestring(1 1,2 2,3 3)",
+ "(1, 1) (2, 2) (3, 3)",
+ "(3, 3) (2, 2) (1, 1)");
+}
+
+
+int test_main(int, char* [])
+{
+ namespace bg = boost::geometry;
+ test_all<bg::point_2d>();
+ test_all<bg::point<int, 2, bg::cs::cartesian> >();
+ test_all<boost::tuple<double, double> >();
+
+ return 0;
+}

Added: sandbox/geometry/libs/geometry/test/util/reversible_view.vcproj
==============================================================================
--- (empty file)
+++ sandbox/geometry/libs/geometry/test/util/reversible_view.vcproj 2010-04-18 13:41:33 EDT (Sun, 18 Apr 2010)
@@ -0,0 +1,184 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="reversible_view"
+ ProjectGUID="{BFB08FEE-76D6-4F3D-9184-BE03CC3F7968}"
+ RootNamespace="reversible_view"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)\reversible_view"
+ ConfigurationType="1"
+ InheritedPropertySheets="..\boost.vsprops"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="../../../..;.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="true"
+ ExceptionHandling="2"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="kernel32.lib $(NoInherit)"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)\reversible_view"
+ ConfigurationType="1"
+ InheritedPropertySheets="..\boost.vsprops"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories="../../../..;.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ ExceptionHandling="2"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="kernel32.lib $(NoInherit)"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <File
+ RelativePath=".\reversible_view.cpp"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk