From 555c99156d53196e9bc332c3e49c5a41698d5709 Mon Sep 17 00:00:00 2001 From: Raoul Gough Date: Thu, 11 Sep 2003 22:36:18 +0000 Subject: [PATCH] Split algorithms portion into seperate header algorithms.hpp [SVN r1535] --- .../python/suite/indexing/suite_utils.hpp | 249 +----------------- 1 file changed, 2 insertions(+), 247 deletions(-) diff --git a/include/boost/python/suite/indexing/suite_utils.hpp b/include/boost/python/suite/indexing/suite_utils.hpp index 4b05b9da..a44eeb7b 100755 --- a/include/boost/python/suite/indexing/suite_utils.hpp +++ b/include/boost/python/suite/indexing/suite_utils.hpp @@ -2,6 +2,8 @@ // // Header file suite_utils.hpp // +// Shared utilities for the indexing suite. +// // Copyright (c) 2003 Raoul M. Gough // // This material is provided "as is", with absolutely no warranty expressed @@ -25,10 +27,6 @@ #define suite_utils_rmg_20030823_included #include -#include -#include -#include -#include namespace indexing { template @@ -39,249 +37,6 @@ namespace indexing { public: static bool const value = ! boost::is_const::value; }; - - template - struct container_algorithms - { - typedef typename ContainerTraits::container container; - typedef typename ContainerTraits::iterator iterator; - typedef typename ContainerTraits::reference reference; - typedef typename ContainerTraits::key_type key_type; - typedef typename ContainerTraits::size_type size_type; - typedef typename ContainerTraits::index_type index_type; - typedef typename ContainerTraits::value_type value_type; - - typedef typename boost::call_traits::param_type value_param; - typedef typename boost::call_traits::param_type key_param; - typedef typename boost::call_traits::param_type index_param; - - static size_type size (container &); - static iterator find (container &, key_param); - static size_type count (container &, key_param); - static void reverse (container &); - static reference get (container &, index_param); - static void assign (container &, index_param, value_param); - static void push_back (container &, value_param); - static void sort (container &); - // static void sort (container &, PyObject *); - - static iterator begin (container &c) { return c.begin(); } - static iterator end (container &c) { return c.end(); } - }; - - ///////////////////////////////////////////////////////////////////////// - // Get the size of a container - ///////////////////////////////////////////////////////////////////////// - - template - typename container_algorithms::size_type - container_algorithms::size (container &c) - { - return c.size(); - } - - ///////////////////////////////////////////////////////////////////////// - // Find an element in a container (std algorithm version) - ///////////////////////////////////////////////////////////////////////// - - template - typename container_algorithms::iterator - container_algorithms::find (container &c - , key_param key) - { - return std::find (begin(c), end(c), key); - } - - ///////////////////////////////////////////////////////////////////////// - // Count occurances of an element in a container (std algorithm version) - ///////////////////////////////////////////////////////////////////////// - - template - typename container_algorithms::size_type - container_algorithms::count (container &c - , key_param key) - { - return std::count (begin(c), end(c), key); - } - - ///////////////////////////////////////////////////////////////////////// - // Index into a container (generic version) - ///////////////////////////////////////////////////////////////////////// - - template - typename container_algorithms::reference - container_algorithms::get (container &c, index_param ix) - { - return c.at (ix); - } - - ///////////////////////////////////////////////////////////////////////// - // Assign a value at a particular index (generic version) - ///////////////////////////////////////////////////////////////////////// - - template - void - container_algorithms::assign (container &c - , index_param ix - , value_param val) - { - c.at(ix) = val; - } - - ///////////////////////////////////////////////////////////////////////// - // Insert at end of a container (generic version) - ///////////////////////////////////////////////////////////////////////// - - template - void - container_algorithms::push_back (container &c - , value_param v) - { - c.push_back (v); - } - - ///////////////////////////////////////////////////////////////////////// - // Reverse the contents of a container (std algorithm version) - ///////////////////////////////////////////////////////////////////////// - - template - void container_algorithms::reverse (container &c) - { - std::reverse (begin(c), end(c)); - } - - ///////////////////////////////////////////////////////////////////////// - // Sort the contents of a container (std algorithm version) - ///////////////////////////////////////////////////////////////////////// - - template - void container_algorithms::sort (container &c) - { - std::sort (begin(c), end(c)); - } - - ///////////////////////////////////////////////////////////////////////// - // Special cases for std::list - ///////////////////////////////////////////////////////////////////////// - - template - struct list_algorithms : public container_algorithms - { - private: - typedef container_algorithms Parent; - - public: - typedef typename Parent::container container; - - // Use member functions for the following (hiding base class versions) - static void reverse (container &); - static void sort (container &); - // static void sort (container &, PyObject *); - }; - - ///////////////////////////////////////////////////////////////////////// - // Reverse the contents of a list (member function version) - ///////////////////////////////////////////////////////////////////////// - - template - void list_algorithms::reverse (container &c) - { - c.reverse(); - } - - ///////////////////////////////////////////////////////////////////////// - // Sort the contents of a container (std algorithm version) - ///////////////////////////////////////////////////////////////////////// - - template - void list_algorithms::sort (container &c) - { - c.sort(); - } - - ///////////////////////////////////////////////////////////////////////// - // Special cases for associative containers - ///////////////////////////////////////////////////////////////////////// - - template - struct assoc_algorithms : public container_algorithms - { - private: - typedef container_algorithms Parent; - - public: - typedef typename Parent::iterator iterator; - typedef typename Parent::size_type size_type; - typedef typename Parent::container container; - typedef typename Parent::reference reference; - typedef typename Parent::key_param key_param; - typedef typename Parent::index_param index_param; - typedef typename Parent::value_param value_param; - - static reference get (container &, index_param); - static void assign (container &, index_param, value_param); - - // Use member functions for the following (hiding base class versions) - static iterator find (container &, key_param); - static size_type count (container &, key_param); - }; - - ///////////////////////////////////////////////////////////////////////// - // Index into a container (associative version) - ///////////////////////////////////////////////////////////////////////// - - template - typename assoc_algorithms::reference - assoc_algorithms::get (container &c, index_param ix) - { - iterator iter = find (c, ix); - - if (iter == end(c)) - { - throw std::domain_error - (std::string ("associative container: key not found")); - } - - else - { - return iter->second; - } - } - - ///////////////////////////////////////////////////////////////////////// - // Assign a value at a particular index (associative version) - ///////////////////////////////////////////////////////////////////////// - - template - void - assoc_algorithms::assign (container &c - , index_param ix - , value_param val) - { - c[ix] = val; - } - - ///////////////////////////////////////////////////////////////////////// - // Find an element in an associative container - ///////////////////////////////////////////////////////////////////////// - - template - typename assoc_algorithms::iterator - assoc_algorithms::find (container &c, key_param key) - { - return c.find (key); - } - - ///////////////////////////////////////////////////////////////////////// - // Count occurances of an element in a container (associative version) - ///////////////////////////////////////////////////////////////////////// - - template - typename assoc_algorithms::size_type - assoc_algorithms::count (container &c, key_param key) - { - return c.count (key); - } } #endif // suite_utils_rmg_20030823_included