[Opentrep-svn] SF.net SVN: opentrep:[127] trunk/opentrep
Status: Beta
Brought to you by:
denis_arnaud
From: <den...@us...> - 2009-07-14 14:07:33
|
Revision: 127 http://opentrep.svn.sourceforge.net/opentrep/?rev=127&view=rev Author: denis_arnaud Date: 2009-07-14 14:07:29 +0000 (Tue, 14 Jul 2009) Log Message: ----------- [TST] Updated the Ternary Structure Tree (TST). It still does not compile. Modified Paths: -------------- trunk/opentrep/configure.ac trunk/opentrep/opentrep/Makefile.am trunk/opentrep/ternary_tree/examples.cpp trunk/opentrep/ternary_tree/iterator_compile_test.cpp trunk/opentrep/ternary_tree/iterator_wrapper.hpp trunk/opentrep/ternary_tree/readme.txt trunk/opentrep/ternary_tree/structured_map.hpp trunk/opentrep/ternary_tree/structured_set.hpp trunk/opentrep/ternary_tree/ternary_tree.hpp trunk/opentrep/ternary_tree/tst_concept_checks.cpp trunk/opentrep/ternary_tree/tst_detail/iteration_impl.hpp trunk/opentrep/ternary_tree/tst_detail/new_iterator_base.ipp trunk/opentrep/ternary_tree/tst_detail/tst_implementation.ipp trunk/opentrep/ternary_tree/tst_detail/tst_iterator_base.ipp trunk/opentrep/ternary_tree/tst_detail/tst_iterator_facade.hpp trunk/opentrep/ternary_tree/tst_detail/tst_node.hpp trunk/opentrep/ternary_tree/tst_detail/tst_search_results.ipp Added Paths: ----------- trunk/opentrep/ternary_tree/Makefile.am trunk/opentrep/ternary_tree/fill_dictionary.hpp trunk/opentrep/ternary_tree/simple_tst.cpp trunk/opentrep/ternary_tree/sources.mk Removed Paths: ------------- trunk/opentrep/ternary_tree/fill_dictionary.cpp Property Changed: ---------------- trunk/opentrep/ternary_tree/ Modified: trunk/opentrep/configure.ac =================================================================== --- trunk/opentrep/configure.ac 2009-07-14 10:45:19 UTC (rev 126) +++ trunk/opentrep/configure.ac 2009-07-14 14:07:29 UTC (rev 127) @@ -211,6 +211,7 @@ opentrep.pc opentrep.spec opentrep.m4 + ternary_tree/Makefile opentrep/Makefile opentrep/basic/Makefile opentrep/bom/Makefile Modified: trunk/opentrep/opentrep/Makefile.am =================================================================== --- trunk/opentrep/opentrep/Makefile.am 2009-07-14 10:45:19 UTC (rev 126) +++ trunk/opentrep/opentrep/Makefile.am 2009-07-14 14:07:29 UTC (rev 127) @@ -3,8 +3,6 @@ ## Source directory -DISTCLEANFILES = @PACKAGE@-paths.h - MAINTAINERCLEANFILES = Makefile.in SUBDIRS = basic bom factory dbadaptor command service core config batches Property changes on: trunk/opentrep/ternary_tree ___________________________________________________________________ Added: svn:ignore + .libs .deps Makefile Makefile.in Added: trunk/opentrep/ternary_tree/Makefile.am =================================================================== --- trunk/opentrep/ternary_tree/Makefile.am (rev 0) +++ trunk/opentrep/ternary_tree/Makefile.am 2009-07-14 14:07:29 UTC (rev 127) @@ -0,0 +1,46 @@ +include $(top_srcdir)/Makefile.common +include $(srcdir)/sources.mk + +## +# Source directory + +DISTCLEANFILES = + +MAINTAINERCLEANFILES = Makefile.in + +SUBDIRS = + +EXTRA_DIST = + + +## +# Library +lib_LTLIBRARIES = libtst.la + +libtst_la_SOURCES = $(tst_h_sources) $(tst_cc_sources) +#libtst_la_LIBADD = +libtst_la_LDFLAGS = -version-info $(GENERIC_LIBRARY_VERSION) + +# Header files +nobase_pkginclude_HEADERS = $(ttree_h_sources) +#nobase_nodist_pkginclude_HEADERS = $(top_builddir)/@PACKAGE@/config.h + + +## +# Binaries (batches) +bin_PROGRAMS = simple_tst + +simple_tst_SOURCES = simple_tst.cpp +#simple_tst_CXXFLAGS = +#simple_tst_LDADD = +#simple_tst_LDFLAGS = + +## +# Test binaries +#check_PROGRAMS = iterator_compile_test tst_concept_checks + +#iterator_compile_test_SOURCES = iterator_compile_test.cpp +#iterator_compile_test_LDFLAGS = + +#tst_concept_checks_SOURCES = tst_concept_checks.cpp +#tst_concept_checks_LDFLAGS = Modified: trunk/opentrep/ternary_tree/examples.cpp =================================================================== --- trunk/opentrep/ternary_tree/examples.cpp 2009-07-14 10:45:19 UTC (rev 126) +++ trunk/opentrep/ternary_tree/examples.cpp 2009-07-14 14:07:29 UTC (rev 127) @@ -1,231 +1,231 @@ -/** \file - * Usage examples for Structured Containers. - */ - -#include <iostream> -#include "structured_set.hpp" -#include "structured_map.hpp" - -#include <iostream> -#include <string> -#include <set> -#include <functional> -//#include <boost/scoped_ptr.hpp> - -// -// Basic use of structured_set -// - -void basic() -{ - typedef containers::structured_set<std::string> Set; - typedef Set::iterator SetIter; - typedef std::pair<SetIter, SetIter> IterPair; - - Set names; - names.insert("apps"); - names.insert("applets"); - names.insert("banana"); - - std::cout << "The set contains\n\t"; - for (SetIter it = names.begin(); it != names.end(); ++it) - std::cout << *it << ", "; - - IterPair p = names.prefix_range("app"); - std::cout << "\nprefix_range(\"app\") returns:\n\t"; - while (p.first != p.second) { - std::cout << *p.first++ << ", "; - } - std::cout << "\np.second points to " << *p.second; - - std::cout << "\nequal_range(\"app\") returns:\n\t"; - p = names.equal_range("app"); - if (p.first == p.second) - std::cout << "empty range"; - std::cout << "\np.second points to " << *p.second; -} - - -//############################################################################# -// -// prefix_range example (compile-only, does not run as is) -// -typedef containers::structured_set<std::string> SymbolSet; -SymbolSet symbols; -bool is_defined_in_scope(std::string scope, std::string name) -{ - typedef std::pair<SymbolSet::iterator, SymbolSet::iterator> Range; - Range r = symbols.prefix_range(scope + "::"); - SymbolSet::iterator n = symbols.find(name); - return n != symbols.end() && *n >= *r.first && *n < *r.second; -} - - -//############################################################################# -// -// Case-insensitive structured containers -// -template<class CharT> -struct nocase_less : public std::binary_function<CharT, CharT, bool> -{ - bool operator()(CharT a, CharT b) const { return tolower(a) < tolower(b); } -}; - -void caseless_set() -{ - typedef containers::structured_multiset<std::string, nocase_less<char> > CaselessSet; - typedef containers::structured_multimap<std::string, double, nocase_less<char> > CaselessMap; - - CaselessMap uncased; - uncased.insert(std::make_pair("NoCase", 0.1)); - CaselessSet caseless; - caseless.insert("NoCase"); - caseless.insert("nocase"); - caseless.insert("noCase"); - caseless.insert("NOCASE"); - - std::cout << "nocase = " << (int)caseless.count("nocase"); - - CaselessSet::const_iterator endit = caseless.end(); - for(CaselessSet::const_iterator it = caseless.begin(); it != endit; ++it) { - std::cout << ", " << *it; - } - -} - -//############################################################################# -// -// Localization comparator -// - -#include "examples/locale_less.hpp" - -void localized_comparator() -{ - typedef containers::structured_set<std::string, utility::locale_less<char> > LocalSet; - - typedef containers::structured_set<std::string> DefaultSet; - - if (utility::swedish_locale_name == "C") - std::cout << "No locale to test\n"; - else - std::cout << "Attempt to set Swedish locale \"" << utility::swedish_locale_name << "\"\n"; - - try { - // use comparator constructor, create Swedish locale - LocalSet se_names(utility::locale_less<char>::locale_less(utility::swedish_locale_name)); - DefaultSet anynames; - - se_names.insert("\xC4ska"); - se_names.insert("\xC5m\xE5l"); - se_names.insert("\xD6dla"); - se_names.insert("Adam"); - - anynames.insert("\xC4ska"); - anynames.insert("\xC5m\xE5l"); - anynames.insert("\xD6dla"); - anynames.insert("Adam"); - - - for(LocalSet::iterator sit = se_names.begin(); sit != se_names.end(); ++sit) { - std::cout << *sit << ", "; - } - std::cout << "not:\n"; - for(DefaultSet::iterator dit = anynames.begin(); dit != anynames.end(); ++dit) { - std::cout << *dit << ", "; - } - } catch(std::exception& x) { - std::cout << "...failed - skip test\n" << x.what() << "\n"; - } -} - -//############################################################################# -// -// longest_match example -// -#include <fstream> - -typedef containers::structured_map<std::string, int, nocase_less<char> > Vocabulary; - -void fill_wordlist(const char* filename, Vocabulary& wordlist) -{ - std::ifstream wordstream(filename); - if (!wordstream.is_open()) { - std::cerr << "Could not open dictionary " << filename << "\n"; - return; - } - char buf[300]; - int linecount = 0; - while(wordstream.getline(buf, 300, '\n').good()) - wordlist[buf] = ++linecount; -} - -std::streamsize get_filesize(std::ifstream& str) -{ - std::streamsize pos = str.tellg(); - str.seekg(0, std::ios_base::end); - std::streamsize result = str.tellg(); - str.seekg(pos, std::ios_base::beg); - return result; -} - -namespace { - template<class T> - struct scoped_array - { - scoped_array(size_t count) : buf(new T[count]) {} - ~scoped_array() { delete[] buf; } - T* get() { return buf; } - private: - T* buf; - }; -} - -void longest_match_example(const char* dictfile, const char* parsefile) -{ - Vocabulary english; - // Read dictionary from disk - fill_wordlist(dictfile, english); - if (english.empty()) - return; - - std::ifstream infile(parsefile); - if (!infile.is_open()) - return; - - // longest_match does not work with istream_iterator, so must fill buffer - size_t filesize = (size_t)get_filesize(infile); - // instead of boost::scoped_array - scoped_array<char> bytes(filesize); - infile.read(bytes.get(), filesize); - - const char *first = bytes.get(); - const char *last = first + infile.gcount(); - - while (first != last) - { - Vocabulary::iterator word = english.longest_match(first, last); - if (word != english.end()) - std::cout << (*word).first << " "; //= " << (*word).second << "\n"; - else { - // No key; try next char - ++first; - } - } -} - -//############################################################################# - -int main() -{ - std::cout << "*** basic usage ***\n"; - basic(); - std::cout << "\n\n*** custom comparator ***\n"; - caseless_set(); - std::cout << "\n\n*** locale comparator ***\n"; - localized_comparator(); - std::cout << "\n\n*** longest_match ***\n"; - // You need to supply files, not included in ternary_tree distribution - longest_match_example("../english-150k.txt", "../shakequotes.txt"); - return 0; -} +/** \file + * Usage examples for Structured Containers. + */ + +#include <iostream> +#include "structured_set.hpp" +#include "structured_map.hpp" + +#include <iostream> +#include <string> +#include <set> +#include <functional> +//#include <boost/scoped_ptr.hpp> + +// +// Basic use of structured_set +// + +void basic() +{ + typedef containers::structured_set<std::string> Set; + typedef Set::iterator SetIter; + typedef std::pair<SetIter, SetIter> IterPair; + + Set names; + names.insert("apps"); + names.insert("applets"); + names.insert("banana"); + + std::cout << "The set contains\n\t"; + for (SetIter it = names.begin(); it != names.end(); ++it) + std::cout << *it << ", "; + + IterPair p = names.prefix_range("app"); + std::cout << "\nprefix_range(\"app\") returns:\n\t"; + while (p.first != p.second) { + std::cout << *p.first++ << ", "; + } + std::cout << "\np.second points to " << *p.second; + + std::cout << "\nequal_range(\"app\") returns:\n\t"; + p = names.equal_range("app"); + if (p.first == p.second) + std::cout << "empty range"; + std::cout << "\np.second points to " << *p.second; +} + + +//############################################################################# +// +// prefix_range example (compile-only, does not run as is) +// +typedef containers::structured_set<std::string> SymbolSet; +SymbolSet symbols; +bool is_defined_in_scope(std::string scope, std::string name) +{ + typedef std::pair<SymbolSet::iterator, SymbolSet::iterator> Range; + Range r = symbols.prefix_range(scope + "::"); + SymbolSet::iterator n = symbols.find(name); + return n != symbols.end() && *n >= *r.first && *n < *r.second; +} + + +//############################################################################# +// +// Case-insensitive structured containers +// +template<class CharT> +struct nocase_less : public std::binary_function<CharT, CharT, bool> +{ + bool operator()(CharT a, CharT b) const { return tolower(a) < tolower(b); } +}; + +void caseless_set() +{ + typedef containers::structured_multiset<std::string, nocase_less<char> > CaselessSet; + typedef containers::structured_multimap<std::string, double, nocase_less<char> > CaselessMap; + + CaselessMap uncased; + uncased.insert(std::make_pair("NoCase", 0.1)); + CaselessSet caseless; + caseless.insert("NoCase"); + caseless.insert("nocase"); + caseless.insert("noCase"); + caseless.insert("NOCASE"); + + std::cout << "nocase = " << (int)caseless.count("nocase"); + + CaselessSet::const_iterator endit = caseless.end(); + for(CaselessSet::const_iterator it = caseless.begin(); it != endit; ++it) { + std::cout << ", " << *it; + } + +} + +//############################################################################# +// +// Localization comparator +// + +#include "examples/locale_less.hpp" + +void localized_comparator() +{ + typedef containers::structured_set<std::string, utility::locale_less<char> > LocalSet; + + typedef containers::structured_set<std::string> DefaultSet; + + if (utility::swedish_locale_name == "C") + std::cout << "No locale to test\n"; + else + std::cout << "Attempt to set Swedish locale \"" << utility::swedish_locale_name << "\"\n"; + + try { + // use comparator constructor, create Swedish locale + LocalSet se_names(utility::locale_less<char>::locale_less(utility::swedish_locale_name)); + DefaultSet anynames; + + se_names.insert("\xC4ska"); + se_names.insert("\xC5m\xE5l"); + se_names.insert("\xD6dla"); + se_names.insert("Adam"); + + anynames.insert("\xC4ska"); + anynames.insert("\xC5m\xE5l"); + anynames.insert("\xD6dla"); + anynames.insert("Adam"); + + + for(LocalSet::iterator sit = se_names.begin(); sit != se_names.end(); ++sit) { + std::cout << *sit << ", "; + } + std::cout << "not:\n"; + for(DefaultSet::iterator dit = anynames.begin(); dit != anynames.end(); ++dit) { + std::cout << *dit << ", "; + } + } catch(std::exception& x) { + std::cout << "...failed - skip test\n" << x.what() << "\n"; + } +} + +//############################################################################# +// +// longest_match example +// +#include <fstream> + +typedef containers::structured_map<std::string, int, nocase_less<char> > Vocabulary; + +void fill_wordlist(const char* filename, Vocabulary& wordlist) +{ + std::ifstream wordstream(filename); + if (!wordstream.is_open()) { + std::cerr << "Could not open dictionary " << filename << "\n"; + return; + } + char buf[300]; + int linecount = 0; + while(wordstream.getline(buf, 300, '\n').good()) + wordlist[buf] = ++linecount; +} + +std::streamsize get_filesize(std::ifstream& str) +{ + std::streamsize pos = str.tellg(); + str.seekg(0, std::ios_base::end); + std::streamsize result = str.tellg(); + str.seekg(pos, std::ios_base::beg); + return result; +} + +namespace { + template<class T> + struct scoped_array + { + scoped_array(size_t count) : buf(new T[count]) {} + ~scoped_array() { delete[] buf; } + T* get() { return buf; } + private: + T* buf; + }; +} + +void longest_match_example(const char* dictfile, const char* parsefile) +{ + Vocabulary english; + // Read dictionary from disk + fill_wordlist(dictfile, english); + if (english.empty()) + return; + + std::ifstream infile(parsefile); + if (!infile.is_open()) + return; + + // longest_match does not work with istream_iterator, so must fill buffer + size_t filesize = (size_t)get_filesize(infile); + // instead of boost::scoped_array + scoped_array<char> bytes(filesize); + infile.read(bytes.get(), filesize); + + const char *first = bytes.get(); + const char *last = first + infile.gcount(); + + while (first != last) + { + Vocabulary::iterator word = english.longest_match(first, last); + if (word != english.end()) + std::cout << (*word).first << " "; //= " << (*word).second << "\n"; + else { + // No key; try next char + ++first; + } + } +} + +//############################################################################# + +int main() +{ + std::cout << "*** basic usage ***\n"; + basic(); + std::cout << "\n\n*** custom comparator ***\n"; + caseless_set(); + std::cout << "\n\n*** locale comparator ***\n"; + localized_comparator(); + std::cout << "\n\n*** longest_match ***\n"; + // You need to supply files, not included in ternary_tree distribution + longest_match_example("../english-150k.txt", "../shakequotes.txt"); + return 0; +} Deleted: trunk/opentrep/ternary_tree/fill_dictionary.cpp =================================================================== --- trunk/opentrep/ternary_tree/fill_dictionary.cpp 2009-07-14 10:45:19 UTC (rev 126) +++ trunk/opentrep/ternary_tree/fill_dictionary.cpp 2009-07-14 14:07:29 UTC (rev 127) @@ -1,66 +0,0 @@ -#include <vector> -#include <string> -#include <iostream> -#include <fstream> -#include <algorithm> -#include <stdexcept> - -typedef std::vector<std::string> Dictionary; - -//template<class Container> -size_t fill_dictionary(const char* filename, Dictionary& dictionary, size_t maxsize, size_t line_length = 0) -{ - std::ifstream input(filename); - size_t longest_in_file = 0; - size_t linecount = 0; - if (!input.is_open()) { - std::cerr << filename << ": file open fail\n"; - throw std::runtime_error("fill_dictionary failed"); - } - if (input.is_open() && !line_length) - { - std::vector<char> next; - next.resize(std::max(line_length, size_t(300))); - while(input.good() && linecount < maxsize) { - input.getline(&next[0], next.capacity()); - std::string s(next.begin(), next.begin() + (size_t)input.gcount()); - if (!s.empty()) { - dictionary.push_back(s.c_str()); - ++linecount; - if (s.size() > longest_in_file) - longest_in_file = s.size(); - //std::cerr << s.c_str() << "\n"; - } - //next.clear(); - } - //std::cerr << "Read " << dictionary.size() << " lines from wordlist.txt\n"; - } - - // If file not long enough, fill up with some random alphabetic strings - if (line_length || (dictionary.size() < maxsize && (maxsize < size_t(-1)) ) ) - { - std::string next; - if (!line_length) { - line_length = linecount? longest_in_file : 10; - std::cerr << "zero-length line, we'll have trouble"; - } - next.reserve(line_length + 1); - for (size_t i = dictionary.size(); i < maxsize; ++i) - { - size_t length = 1 + (rand() % line_length); - next.resize(length--); - while(length--) { - next[length] = rand() % (127-' ') + ' '; - } - //std::cerr << next << '\n'; - dictionary.push_back(next.c_str()); - } - if (line_length > longest_in_file) - longest_in_file = line_length; - } - return longest_in_file; -} - - - - Copied: trunk/opentrep/ternary_tree/fill_dictionary.hpp (from rev 126, trunk/opentrep/ternary_tree/fill_dictionary.cpp) =================================================================== --- trunk/opentrep/ternary_tree/fill_dictionary.hpp (rev 0) +++ trunk/opentrep/ternary_tree/fill_dictionary.hpp 2009-07-14 14:07:29 UTC (rev 127) @@ -0,0 +1,66 @@ +#include <vector> +#include <string> +#include <iostream> +#include <fstream> +#include <algorithm> +#include <stdexcept> + +typedef std::vector<std::string> Dictionary; + +//template<class Container> +size_t fill_dictionary(const char* filename, Dictionary& dictionary, size_t maxsize, size_t line_length = 0) +{ + std::ifstream input(filename); + size_t longest_in_file = 0; + size_t linecount = 0; + if (!input.is_open()) { + std::cerr << filename << ": file open fail\n"; + throw std::runtime_error("fill_dictionary failed"); + } + if (input.is_open() && !line_length) + { + std::vector<char> next; + next.resize(std::max(line_length, size_t(300))); + while(input.good() && linecount < maxsize) { + input.getline(&next[0], next.capacity()); + std::string s(next.begin(), next.begin() + (size_t)input.gcount()); + if (!s.empty()) { + dictionary.push_back(s.c_str()); + ++linecount; + if (s.size() > longest_in_file) + longest_in_file = s.size(); + //std::cerr << s.c_str() << "\n"; + } + //next.clear(); + } + //std::cerr << "Read " << dictionary.size() << " lines from wordlist.txt\n"; + } + + // If file not long enough, fill up with some random alphabetic strings + if (line_length || (dictionary.size() < maxsize && (maxsize < size_t(-1)) ) ) + { + std::string next; + if (!line_length) { + line_length = linecount? longest_in_file : 10; + std::cerr << "zero-length line, we'll have trouble"; + } + next.reserve(line_length + 1); + for (size_t i = dictionary.size(); i < maxsize; ++i) + { + size_t length = 1 + (rand() % line_length); + next.resize(length--); + while(length--) { + next[length] = rand() % (127-' ') + ' '; + } + //std::cerr << next << '\n'; + dictionary.push_back(next.c_str()); + } + if (line_length > longest_in_file) + longest_in_file = line_length; + } + return longest_in_file; +} + + + + Modified: trunk/opentrep/ternary_tree/iterator_compile_test.cpp =================================================================== --- trunk/opentrep/ternary_tree/iterator_compile_test.cpp 2009-07-14 10:45:19 UTC (rev 126) +++ trunk/opentrep/ternary_tree/iterator_compile_test.cpp 2009-07-14 14:07:29 UTC (rev 127) @@ -1,163 +1,163 @@ -/** Pure compilation/header test - * \file - * This file checks interoperability requirements for iterator_wrapper.hpp - * The problem cases are those that should fail: they cannot be checked - * automatically by compiler. - * So to use, you must define TEST_COMPILATION_FAILURE or - * CHECK_SPECIAL_COMP_FAILURE below, and then inspect compiler warnings - * to see that you get an error for every SHOULD_FAIL line (#1-F, #20-21). - * To simplify this, uncomment one statement at a time in the function - * iterator_interop_checks_main() - * at the end of this file, then try to compile. - * - * Construction/assignment to reverse_iterator from const_reverse_iterator - * generates more complicated error messages from compilers, - * so were broken out to allow separate runs. - * Define the macro CHECK_SPECIAL_COMP_FAILURE and look for - * SPECIAL_FAIL_1 and _2 in the compiler output. - * - * This (un)works as required with MSVC and Comeau online tryitout compiler. - */ - -#ifdef _MSC_VER -# pragma warning(disable: 4245 4127 4189 4700) -#endif - - -//#define TEST_COMPILATION_FAILURE -// Two cases must be inspected in references on MSVC -//#define CHECK_SPECIAL_COMP_FAILURE - -#ifdef TEST_COMPILATION_FAILURE -# define SHOULD_FAIL( Pred ) Pred -#else -# define SHOULD_FAIL( Pred ) -#endif - -#ifdef CHECK_SPECIAL_COMP_FAILURE -# define SPECIAL_FAIL_1( Pred ) Pred -# define SPECIAL_FAIL_2( Pred ) Pred -#else -# define SPECIAL_FAIL_1( Pred ) -# define SPECIAL_FAIL_2( Pred ) -#endif - - - -template<class Container> -void iterator_interop_checks() -{ - typedef Container C; - typedef typename C::const_iterator c_t; - typedef typename C::iterator i_t; - typedef typename C::const_reverse_iterator cr_t; - typedef typename C::reverse_iterator r_t; - c_t c; - i_t i; - cr_t cr; - r_t r; -///// COPY-CONSTRUCTORS - // Should work - c_t i1( i ); - c_t i2( cr.base() ); - c_t i3( r.base() ); - i_t i4( r.base() ); - cr_t i5( r ); - cr_t i6( c ); - cr_t i7( i ); - r_t i8( i ); - - SHOULD_FAIL( c_t i101( cr ); ) // #1 - SHOULD_FAIL( c_t i102( r ); ) // #2 - SHOULD_FAIL( i_t i103( c ); ) // #3 - SHOULD_FAIL( i_t i104( cr ); ) // #4 - SHOULD_FAIL( i_t i105( r ); ) // #5 - SHOULD_FAIL( r_t i106( c ); ) // #6 - -///// ASSIGNMENT - // Should work - c = i; - c = cr.base(); - c = r.base(); - i = r.base(); - cr = r; - - SHOULD_FAIL( c = cr; ) // #7 - SHOULD_FAIL( c = r; ) // #8 - SHOULD_FAIL( i = c; ) // #9 - SHOULD_FAIL( i = cr; ) // #A - SHOULD_FAIL( i = r; ) // #B - SHOULD_FAIL( cr = c; ) // #C - SHOULD_FAIL( cr = i; ) // #D - SHOULD_FAIL( r = c; ) // #E - SHOULD_FAIL( r = i; ) // #F - -// these fail in 2nd pass or something, compile separately - SPECIAL_FAIL_1( r_t i107( cr ); ) // #10 - SPECIAL_FAIL_2( r = cr; ) // #11 - -///// ADVANCE - ++c; --c; - ++i; --i; - ++cr; --cr; - ++r; --r; - c++; c--; - i++; i--; - cr++; cr--; - r++; r--; - -///// COMPARE - if (c == i && i == c) c = c; - if (c == cr.base() && cr.base() == c) c = c; - if (i == r.base() && r.base() == i) c = c; - // Should this fail? - Dinkum nor StlPort don't seem to prevent it - //if (r == cr && cr == r) c = c; - if (r.base() == cr.base() && cr.base() == r.base()) c = c; - -///// DEREFERENCE - typedef typename C::value_type val_t; - typedef typename C::pointer ptr_t; - typedef typename C::reference ref_t; - typedef typename C::const_reference cref_t; - - val_t val1 = *c; - val_t val2 = *i; - val_t val3 = *cr; - val_t val4 = *r; - - ref_t ref2 = *i; - ref_t ref4 = *r; - - cref_t cref1 = *c; - cref_t cref2 = *i; - cref_t cref3 = *cr; - cref_t cref4 = *r; - - SHOULD_FAIL( ref_t ref1 = *c ); // #20 - SHOULD_FAIL( ref_t ref3 = *cr ); // #21 - -} - -#include <vector> -#include "ternary_tree.hpp" -#include "structured_set.hpp" -#include "structured_map.hpp" - -void iterator_interop_checks_main() -{ - typedef std::vector<int> Cont; -// iterator_interop_checks<Cont>(); -/* typedef containers::ternary_tree<std::string, int> Tst; - iterator_interop_checks<Tst>(); - typedef containers::structured_set<std::string> StrucSet; - iterator_interop_checks<StrucSet>(); -*/ typedef containers::structured_multiset<std::string> MStrucSet; - iterator_interop_checks<MStrucSet>(); -/* typedef containers::structured_map<std::string, int> StrucMap; - iterator_interop_checks<StrucMap>(); - typedef containers::structured_multimap<std::string, int> MStrucMap; - iterator_interop_checks<MStrucMap>(); */ -} - - - +/** Pure compilation/header test + * \file + * This file checks interoperability requirements for iterator_wrapper.hpp + * The problem cases are those that should fail: they cannot be checked + * automatically by compiler. + * So to use, you must define TEST_COMPILATION_FAILURE or + * CHECK_SPECIAL_COMP_FAILURE below, and then inspect compiler warnings + * to see that you get an error for every SHOULD_FAIL line (#1-F, #20-21). + * To simplify this, uncomment one statement at a time in the function + * iterator_interop_checks_main() + * at the end of this file, then try to compile. + * + * Construction/assignment to reverse_iterator from const_reverse_iterator + * generates more complicated error messages from compilers, + * so were broken out to allow separate runs. + * Define the macro CHECK_SPECIAL_COMP_FAILURE and look for + * SPECIAL_FAIL_1 and _2 in the compiler output. + * + * This (un)works as required with MSVC and Comeau online tryitout compiler. + */ + +#ifdef _MSC_VER +# pragma warning(disable: 4245 4127 4189 4700) +#endif + + +//#define TEST_COMPILATION_FAILURE +// Two cases must be inspected in references on MSVC +//#define CHECK_SPECIAL_COMP_FAILURE + +#ifdef TEST_COMPILATION_FAILURE +# define SHOULD_FAIL( Pred ) Pred +#else +# define SHOULD_FAIL( Pred ) +#endif + +#ifdef CHECK_SPECIAL_COMP_FAILURE +# define SPECIAL_FAIL_1( Pred ) Pred +# define SPECIAL_FAIL_2( Pred ) Pred +#else +# define SPECIAL_FAIL_1( Pred ) +# define SPECIAL_FAIL_2( Pred ) +#endif + + + +template<class Container> +void iterator_interop_checks() +{ + typedef Container C; + typedef typename C::const_iterator c_t; + typedef typename C::iterator i_t; + typedef typename C::const_reverse_iterator cr_t; + typedef typename C::reverse_iterator r_t; + c_t c; + i_t i; + cr_t cr; + r_t r; +///// COPY-CONSTRUCTORS + // Should work + c_t i1( i ); + c_t i2( cr.base() ); + c_t i3( r.base() ); + i_t i4( r.base() ); + cr_t i5( r ); + cr_t i6( c ); + cr_t i7( i ); + r_t i8( i ); + + SHOULD_FAIL( c_t i101( cr ); ) // #1 + SHOULD_FAIL( c_t i102( r ); ) // #2 + SHOULD_FAIL( i_t i103( c ); ) // #3 + SHOULD_FAIL( i_t i104( cr ); ) // #4 + SHOULD_FAIL( i_t i105( r ); ) // #5 + SHOULD_FAIL( r_t i106( c ); ) // #6 + +///// ASSIGNMENT + // Should work + c = i; + c = cr.base(); + c = r.base(); + i = r.base(); + cr = r; + + SHOULD_FAIL( c = cr; ) // #7 + SHOULD_FAIL( c = r; ) // #8 + SHOULD_FAIL( i = c; ) // #9 + SHOULD_FAIL( i = cr; ) // #A + SHOULD_FAIL( i = r; ) // #B + SHOULD_FAIL( cr = c; ) // #C + SHOULD_FAIL( cr = i; ) // #D + SHOULD_FAIL( r = c; ) // #E + SHOULD_FAIL( r = i; ) // #F + +// these fail in 2nd pass or something, compile separately + SPECIAL_FAIL_1( r_t i107( cr ); ) // #10 + SPECIAL_FAIL_2( r = cr; ) // #11 + +///// ADVANCE + ++c; --c; + ++i; --i; + ++cr; --cr; + ++r; --r; + c++; c--; + i++; i--; + cr++; cr--; + r++; r--; + +///// COMPARE + if (c == i && i == c) c = c; + if (c == cr.base() && cr.base() == c) c = c; + if (i == r.base() && r.base() == i) c = c; + // Should this fail? - Dinkum nor StlPort don't seem to prevent it + //if (r == cr && cr == r) c = c; + if (r.base() == cr.base() && cr.base() == r.base()) c = c; + +///// DEREFERENCE + typedef typename C::value_type val_t; + typedef typename C::pointer ptr_t; + typedef typename C::reference ref_t; + typedef typename C::const_reference cref_t; + + val_t val1 = *c; + val_t val2 = *i; + val_t val3 = *cr; + val_t val4 = *r; + + ref_t ref2 = *i; + ref_t ref4 = *r; + + cref_t cref1 = *c; + cref_t cref2 = *i; + cref_t cref3 = *cr; + cref_t cref4 = *r; + + SHOULD_FAIL( ref_t ref1 = *c ); // #20 + SHOULD_FAIL( ref_t ref3 = *cr ); // #21 + +} + +#include <vector> +#include "ternary_tree.hpp" +#include "structured_set.hpp" +#include "structured_map.hpp" + +void iterator_interop_checks_main() +{ + typedef std::vector<int> Cont; +// iterator_interop_checks<Cont>(); +/* typedef containers::ternary_tree<std::string, int> Tst; + iterator_interop_checks<Tst>(); + typedef containers::structured_set<std::string> StrucSet; + iterator_interop_checks<StrucSet>(); +*/ typedef containers::structured_multiset<std::string> MStrucSet; + iterator_interop_checks<MStrucSet>(); +/* typedef containers::structured_map<std::string, int> StrucMap; + iterator_interop_checks<StrucMap>(); + typedef containers::structured_multimap<std::string, int> MStrucMap; + iterator_interop_checks<MStrucMap>(); */ +} + + + Modified: trunk/opentrep/ternary_tree/iterator_wrapper.hpp =================================================================== --- trunk/opentrep/ternary_tree/iterator_wrapper.hpp 2009-07-14 10:45:19 UTC (rev 126) +++ trunk/opentrep/ternary_tree/iterator_wrapper.hpp 2009-07-14 14:07:29 UTC (rev 127) @@ -1,233 +1,233 @@ -// Created Mon Feb 06 13:20:01 2006 -#ifndef ITERATOR_WRAPPER_HPP_INCLUDED -#define ITERATOR_WRAPPER_HPP_INCLUDED - -#include <iterator> - -namespace iterators { - - // This is mostly a lame ripoff from Boost.Iterator, to avoid the dependency... - - //! Standard type traits for const_iterators. \see iterator_wrapper - template <class T> - struct const_traits { - typedef T value_type; - typedef const T* pointer; - typedef const T* const_pointer; - typedef const T& reference; - typedef const T& const_reference; - }; - - //! Standard type traits for (non-const) iterators. \see iterator_wrapper - template <class T> - struct nonconst_traits { - typedef T value_type; - typedef T* pointer; - typedef const T* const_pointer; - typedef T& reference; - typedef const T& const_reference; - }; - - /** Creates a bidirectional iterator from a base implementation, - * which is required to supply the interface \code - * struct iter_impl_sample - * { - * typedef /impl-defined/ reference; - * iter_impl_sample(); - * iter_impl_sample(/args/); - * void increment(); - * void decrement(); - * reference dereference() const; - * template<class OtherIter> bool equal(const OtherIter& rhs); - * void swap(this_type& rhs); - * }; \endcode - * (This class is meant for iterators you control - if you need to adapt an existing iterator - * with different interface, something like boost::iterator_facade is needed.) - * - * The first template parameter is the iterator implementation class. - * iterator_wrapper does not inherit from this. The second parameter is either const_traits <T> - * or nonconst_traits <T>, which provide the basic value_type related definitions. - * - * Note that Boost.Iterator will do the same job better, this was provided to avoid the dependency. - * Future versions may move to Boost instead. - * - * \ingroup utilities - */ - template< class BaseIterT - , class TraitsT - , class IterCatT = std::bidirectional_iterator_tag - > - struct iterator_wrapper - { - typedef BaseIterT base_iter; - typedef TraitsT traits_type; - typedef iterator_wrapper<BaseIterT, TraitsT, IterCatT> this_type; - - typedef typename TraitsT::value_type value_type; - typedef typename TraitsT::pointer pointer; - typedef typename TraitsT::reference reference; - typedef typename TraitsT::const_reference const_reference; - - typedef IterCatT iterator_category; - typedef ptrdiff_t difference_type; - typedef size_t size_type; - - iterator_wrapper() {} - - //! Copy constructor for iterator and constructor from (non-const) iterator for const_iterator - template<class SameBase> - iterator_wrapper(const iterator_wrapper<SameBase, nonconst_traits<value_type>, IterCatT>& it) - : m_iter(it.iter_base()) - {} - - iterator_wrapper(const iterator_wrapper& it) : m_iter(it.iter_base()) {} - - iterator_wrapper(const base_iter& it) : m_iter(it) {} - - reference operator*() const { return m_iter.dereference(); } - - pointer operator->() const { return &m_iter.dereference(); } - - this_type& operator++() { m_iter.increment(); return *this; } - - this_type operator++(int) { - this_type tmp(*this); - this->operator++(); - return tmp; - } - - this_type& operator--() { m_iter.decrement(); return *this; } - - this_type operator--(int) { - this_type tmp(*this); - this->operator--(); - return tmp; - } - - //! Assignment from non-const to const_iterator - template<class SameBase> - this_type& operator=(const iterator_wrapper<SameBase, nonconst_traits<value_type> >& rhs) { - this_type(rhs).swap(*this); - return *this; - } - - this_type& operator=(const iterator_wrapper<BaseIterT, TraitsT>& rhs) { - this_type(rhs).swap(*this); - return *this; - } - - template<class Base, class Constness> - void swap(iterator_wrapper<Base, Constness>& other) { - iter_base().swap(other.iter_base()); - } - - base_iter& iter_base() { return m_iter; } - const base_iter& iter_base() const { return m_iter; } - - private: - base_iter m_iter; - }; - - // \relates iterator_wrapper - template<class Base, class Val, class Val2, class Cat> - bool operator== (const iterator_wrapper<Base, Val, Cat>& lhs, const iterator_wrapper<Base, Val2, Cat>& rhs) { - return lhs.iter_base().equal(rhs.iter_base()); - } - - // \relates iterator_wrapper - template<class Base, class Val, class Val2, class Cat> - bool operator!= (const iterator_wrapper<Base, Val, Cat>& lhs, const iterator_wrapper<Base, Val2, Cat>& rhs) { - return ! (lhs == rhs); - } - -//! \def provide equality operator for reverse const/nonconst iterators \relates iterator_wrapper -#define INTEROPERABLE_REVERSE_ITERATOR_WRAPPERS(ConstTraits, NonConstTraits) \ - template<class Base, class Val, class Cat> \ - bool operator== (const std::reverse_iterator<iterator_wrapper<Base, ConstTraits<Val>, Cat> >& lhs, \ - const std::reverse_iterator<iterator_wrapper<Base, NonConstTraits<Val>, Cat> >& rhs) { \ - return lhs.base() == rhs.base(); \ - } \ - template<class Base, class Val, class Cat> \ - bool operator!= (const std::reverse_iterator<iterator_wrapper<Base, NonConstTraits<Val>, Cat> >& lhs, \ - const std::reverse_iterator<iterator_wrapper<Base, ConstTraits<Val>, Cat> >& rhs) { \ - return !(lhs.base() == rhs.base()); \ - } - -INTEROPERABLE_REVERSE_ITERATOR_WRAPPERS(const_traits, nonconst_traits) -INTEROPERABLE_REVERSE_ITERATOR_WRAPPERS(nonconst_traits, const_traits) - -#undef INTEROPERABLE_REVERSE_ITERATOR_WRAPPERS - - -/** \relates iterator_wrapper - * @{ - */ -template<class Base, class Val, class Val2, class Cat> -bool operator< (const iterator_wrapper<Base, Val, Cat>& lhs, const iterator_wrapper<Base, Val2, Cat>& rhs) { - return lhs.iter_base().less(rhs.iter_base()); -} - - -template<class Base, class Val, class Val2, class Cat> -bool operator> (const iterator_wrapper<Base, Val, Cat>& lhs, const iterator_wrapper<Base, Val2, Cat>& rhs) { - return rhs < lhs; -} - - -template<class Base, class Val, class Val2, class Cat> -bool operator>= (const iterator_wrapper<Base, Val, Cat>& lhs, const iterator_wrapper<Base, Val2, Cat>& rhs) { - return ! (lhs < rhs); -} - -template<class Base, class Val, class Val2, class Cat> -bool operator<= (const iterator_wrapper<Base, Val, Cat>& lhs, const iterator_wrapper<Base, Val2, Cat>& rhs) { - return ! (rhs > lhs); -} - -// random access iter operations (+= -= etc) - -template<class Base, class Val, class Dist> -iterator_wrapper<Base, Val, std::random_access_iterator_tag>& -operator+= (iterator_wrapper<Base, Val, std::random_access_iterator_tag>& it, Dist n) { - it.iter_base().advance(n); - return it; -} - -template<class Base, class Val, class Dist> -iterator_wrapper<Base, Val, std::random_access_iterator_tag>& -operator-= (iterator_wrapper<Base, Val, std::random_access_iterator_tag>& it, Dist n) { - it.iter_base().advance(-n); - return it; -} - -template<class Base, class Val, class Dist> -iterator_wrapper<Base, Val, std::random_access_iterator_tag> -operator+ (const iterator_wrapper<Base, Val, std::random_access_iterator_tag>& it, Dist n) { - iterator_wrapper<Base, Val, std::random_access_iterator_tag> tmp(it); - tmp += n; - return tmp; -} - -template<class Base, class Val, class Dist> -iterator_wrapper<Base, Val, std::random_access_iterator_tag> -operator- (const iterator_wrapper<Base, Val, std::random_access_iterator_tag>& it, Dist n) { - iterator_wrapper<Base, Val, std::random_access_iterator_tag> tmp(it); - tmp -= n; - return tmp; -} - -template<class Base, class Val, class Dist> -Dist -operator- (const iterator_wrapper<Base, Val, std::random_access_iterator_tag>& lhs, - const iterator_wrapper<Base, Val, std::random_access_iterator_tag>& rhs) { - return lhs - rhs; -} - - -/*@}*/ - -} // namespace iterators - - - -#endif // ITERATOR_WRAPPER_HPP_INCLUDED +// Created Mon Feb 06 13:20:01 2006 +#ifndef ITERATOR_WRAPPER_HPP_INCLUDED +#define ITERATOR_WRAPPER_HPP_INCLUDED + +#include <iterator> + +namespace iterators { + + // This is mostly a lame ripoff from Boost.Iterator, to avoid the dependency... + + //! Standard type traits for const_iterators. \see iterator_wrapper + template <class T> + struct const_traits { + typedef T value_type; + typedef const T* pointer; + typedef const T* const_pointer; + typedef const T& reference; + typedef const T& const_reference; + }; + + //! Standard type traits for (non-const) iterators. \see iterator_wrapper + template <class T> + struct nonconst_traits { + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef T& reference; + typedef const T& const_reference; + }; + + /** Creates a bidirectional iterator from a base implementation, + * which is required to supply the interface \code + * struct iter_impl_sample + * { + * typedef /impl-defined/ reference; + * iter_impl_sample(); + * iter_impl_sample(/args/); + * void increment(); + * void decrement(); + * reference dereference() const; + * template<class OtherIter> bool equal(const OtherIter& rhs); + * void swap(this_type& rhs); + * }; \endcode + * (This class is meant for iterators you control - if you need to adapt an existing iterator + * with different interface, something like boost::iterator_facade is needed.) + * + * The first template parameter is the iterator implementation class. + * iterator_wrapper does not inherit from this. The second parameter is either const_traits <T> + * or nonconst_traits <T>, which provide the basic value_type related definitions. + * + * Note that Boost.Iterator will do the same job better, this was provided to avoid the dependency. + * Future versions may move to Boost instead. + * + * \ingroup utilities + */ + template< class BaseIterT + , class TraitsT + , class IterCatT = std::bidirectional_iterator_tag + > + struct iterator_wrapper + { + typedef BaseIterT base_iter; + typedef TraitsT traits_type; + typedef iterator_wrapper<BaseIterT, TraitsT, IterCatT> this_type; + + typedef typename TraitsT::value_type value_type; + typedef typename TraitsT::pointer pointer; + typedef typename TraitsT::reference reference; + typedef typename TraitsT::const_reference const_reference; + + typedef IterCatT iterator_category; + typedef ptrdiff_t difference_type; + typedef size_t size_type; + + iterator_wrapper() {} + + //! Copy constructor for iterator and constructor from (non-const) iterator for const_iterator + template<class SameBase> + iterator_wrapper(const iterator_wrapper<SameBase, nonconst_traits<value_type>, IterCatT>& it) + : m_iter(it.iter_base()) + {} + + iterator_wrapper(const iterator_wrapper& it) : m_iter(it.iter_base()) {} + + iterator_wrapper(const base_iter& it) : m_iter(it) {} + + reference operator*() const { return m_iter.dereference(); } + + pointer operator->() const { return &m_iter.dereference(); } + + this_type& operator++() { m_iter.increment(); return *this; } + + this_type operator++(int) { + this_type tmp(*this); + this->operator++(); + return tmp; + } + + this_type& operator--() { m_iter.decrement(); return *this; } + + this_type operator--(int) { + this_type tmp(*this); + this->operator--(); + return tmp; + } + + //! Assignment from non-const to const_iterator + template<class SameBase> + this_type& operator=(const iterator_wrapper<SameBase, nonconst_traits<value_type> >& rhs) { + this_type(rhs).swap(*this); + return *this; + } + + this_type& operator=(const iterator_wrapper<BaseIterT, TraitsT>& rhs) { + this_type(rhs).swap(*this); + return *this; + } + + template<class Base, class Constness> + void swap(iterator_wrapper<Base, Constness>& other) { + iter_base().swap(other.iter_base()); + } + + base_iter& iter_base() { return m_iter; } + const base_iter& iter_base() const { return m_iter; } + + private: + base_iter m_iter; + }; + + // \relates iterator_wrapper + template<class Base, class Val, class Val2, class Cat> + bool operator== (const iterator_wrapper<Base, Val, Cat>& lhs, const iterator_wrapper<Base, Val2, Cat>& rhs) { + return lhs.iter_base().equal(rhs.iter_base()); + } + + // \relates iterator_wrapper + template<class Base, class Val, class Val2, class Cat> + bool operator!= (const iterator_wrapper<Base, Val, Cat>& lhs, const iterator_wrapper<Base, Val2, Cat>& rhs) { + return ! (lhs == rhs); + } + +//! \def provide equality operator for reverse const/nonconst iterators \relates iterator_wrapper +#define INTEROPERABLE_REVERSE_ITERATOR_WRAPPERS(ConstTraits, NonConstTraits) \ + template<class Base, class Val, class Cat> \ + bool operator== (const std::reverse_iterator<iterator_wrapper<Base, ConstTraits<Val>, Cat> >& lhs, \ + const std::reverse_iterator<iterator_wrapper<Base, NonConstTraits<Val>, Cat> >& rhs) { \ + return lhs.base() == rhs.base(); \ + } \ + template<class Base, class Val, class Cat> \ + bool operator!= (const std::reverse_iterator<iterator_wrapper<Base, NonConstTraits<Val>, Cat> >& lhs, \ + const std::reverse_iterator<iterator_wrapper<Base, ConstTraits<Val>, Cat> >& rhs) { \ + return !(lhs.base() == rhs.base()); \ + } + +INTEROPERABLE_REVERSE_ITERATOR_WRAPPERS(const_traits, nonconst_traits) +INTEROPERABLE_REVERSE_ITERATOR_WRAPPERS(nonconst_traits, const_traits) + +#undef INTEROPERABLE_REVERSE_ITERATOR_WRAPPERS + + +/** \relates iterator_wrapper + * @{ + */ +template<class Base, class Val, class Val2, class Cat> +bool operator< (const iterator_wrapper<Base, Val, Cat>& lhs, const iterator_wrapper<Base, Val2, Cat>& rhs) { + return lhs.iter_base().less(rhs.iter_base()); +} + + +template<class Base, class Val, class Val2, class Cat> +bool operator> (const iterator_wrapper<Base, Val, Cat>& lhs, const iterator_wrapper<Base, Val2, Cat>& rhs) { + return rhs < lhs; +} + + +template<class Base, class Val, class Val2, class Cat> +bool operator>= (const iterator_wrapper<Base, Val, Cat>& lhs, const iterator_wrapper<Base, Val2, Cat>& rhs) { + return ! (lhs < rhs); +} + +template<class Base, class Val, class Val2, class Cat> +bool operator<= (const iterator_wrapper<Base, Val, Cat>& lhs, const iterator_wrapper<Base, Val2, Cat>& rhs) { + return ! (rhs > lhs); +} + +// random access iter operations (+= -= etc) + +template<class Base, class Val, class Dist> +iterator_wrapper<Base, Val, std::random_access_iterator_tag>& +operator+= (iterator_wrapper<Base, Val, std::random_access_iterator_tag>& it, Dist n) { + it.iter_base().advance(n); + return it; +} + +template<class Base, class Val, class Dist> +iterator_wrapper<Base, Val, std::random_access_iterator_tag>& +operator-= (iterator_wrapper<Base, Val, std::random_access_iterator_tag>& it, Dist n) { + it.iter_base().advance(-n); + return it; +} + +template<class Base, class Val, class Dist> +iterator_wrapper<Base, Val, std::random_access_iterator_tag> +operator+ (const iterator_wrapper<Base, Val, std::random_access_iterator_tag>& it, Dist n) { + iterator_wrapper<Base, Val, std::random_access_iterator_tag> tmp(it); + tmp += n; + return tmp; +} + +template<class Base, class Val, class Dist> +iterator_wrapper<Base, Val, std::random_access_iterator_tag> +operator- (const iterator_wrapper<Base, Val, std::random_access_iterator_tag>& it, Dist n) { + iterator_wrapper<Base, Val, std::random_access_iterator_tag> tmp(it); + tmp -= n; + return tmp; +} + +template<class Base, class Val, class Dist> +Dist +operator- (const iterator_wrapper<Base, Val, std::random_access_iterator_tag>& lhs, + const iterator_wrapper<Base, Val, std::random_access_iterator_tag>& rhs) { + return lhs - rhs; +} + + +/*@}*/ + +} // namespace iterators + + + +#endif // ITERATOR_WRAPPER_HPP_INCLUDED Modified: trunk/opentrep/ternary_tree/readme.txt =================================================================== --- trunk/opentrep/ternary_tree/readme.txt 2009-07-14 10:45:19 UTC (rev 126) +++ trunk/opentrep/ternary_tree/readme.txt 2009-07-14 14:07:29 UTC (rev 127) @@ -1,71 +1,71 @@ -LIBRARY -Ternary Search Tree C++ implementation by rasmus ekman -A header-only library of fast string containers with advanced search features. - -version 0.67, 14 May 2006 - -Please send bug reports, suggestions or questions to ras...@ab... -Get latest version at http://abc.se/~re/code/tst/ - -REQUIREMENTS -Library files tested with g++ 3.4.3 and MSVC 7.1 (Visual Studio 2003). -Visual Studio 6 will not work, but may only need moving the template -methods of ternary_tree and structured_* classes inline. -To generate documentation, you need Doxygen. See http://doxygen.org. - - -USAGE -Container classes: - structured_set<Key [, Comp, Alloc]> - structured_multiset<Key [, Comp, Alloc]> - structured_map<Key, Value [, Comp, Alloc]> - structured_multimap<Key, Value [, Comp, Alloc]> -- Key is a std::string-like type (a Forward Container), -- Value is any type, -- Comp is a less-like sort operation on Key::value_type (eg char/wchar_t) -- Alloc is std::allocator<Key [, Value]> or has same interface. - -These containers can be used as nearly drop-in replacments for std::set, -multiset, map, multimap or unordered_* containers on string-like types. - -There is one difference in interface: -If you used non-default comparator template argument with a set or map type, -it must be changed to operate on character type, not string. - -To use standard set, map features: See documentation of these classes. -See included documentation for information about the advanced key search -facilities in all structured_* containers. - - -FILES ---- l i b r a r y c o d e --- -structured_map.hpp - classes structured_map and -multimap. -structured_set.hpp - classes structured_set and multiset. -ternary_tree.hpp - implementation backend class. -./tst_detail/.* ternary_tree implementation files -iterator_wrapper.hpp - iterator interface, included by all containers. - ---- d o c s --- -tst_public.doxy - doxygen config file, generates public interface of library. -tst.doxy - doxygen config file, generates public and private interface docs. -./doxygen_input/* - extra documentation sources used by Doxygen. - -./html/* - generated public and private documentation -full-docs-index.html - redirects to html directory -index.html - redirects to tst_docs directory, only useful if doxygen is used - with tst_public.doxy - ---- t e s t s --- -tst_concept_checks.cpp - requires Boost concept_check header, portable. -iterator_compile_test.cpp - checks iterator_wrapper interoperability, portable. - -test_tst.cpp - test suite; relies on non-portable wstring.hpp (but see below) -fill_dictionary.cpp - (sloppy old support file for test_tst) - fills a vector with strings from file. -wstring.hpp - string/wstring conversion, uses Windows API - if the MultiByteToWideChar and WideCharToMultiByte API calls are replaced, - test_tst may run on your platform... - ---- -rasmus ekman -May 14, 2006 +LIBRARY +Ternary Search Tree C++ implementation by rasmus ekman +A header-only library of fast string containers with advanced search features. + +version 0.67, 14 May 2006 + +Please send bug reports, suggestions or questions to ras...@ab... +Get latest version at http://abc.se/~re/code/tst/ + +REQUIREMENTS +Library files tested with g++ 3.4.3 and MSVC 7.1 (Visual Studio 2003). +Visual Studio 6 will not work, but may only need moving the template +methods of ternary_tree and structured_* classes inline. +To generate documentation, you need Doxygen. See http://doxygen.org. + + +USAGE +Container classes: + structured_set<Key [, Comp, Alloc]> + structured_multiset<Key [, Comp, Alloc]> + structured_map<Key, Value [, Comp, Alloc]> + structured_multimap<Key, Value [, Comp, Alloc]> +- Key is a std::string-like type (a Forward Container), +- Value is any type, +- Comp is a less-like sort operation on Key::value_type (eg char/wchar_t) +- Alloc is std::allocator<Key [, Value]> or has same interface. + +These containers can be used as nearly drop-in replacments for std::set, +multiset, map, multimap or unordered_* containers on string-like types. + +There is one difference in interface: +If you used non-default comparator template argument with a set or map type, +it must be changed to operate on character type, not string. + +To use standard set, map features: See documentation of these classes. +See included documentation for information about the advanced key search +facilities in all structured_* containers. + + +FILES +--- l i b r a r y c o d e --- +structured_map.hpp - classes structured_map and -multimap. +structured_set.hpp - classes structured_set and multiset. +ternary_tree.hpp - implementation backend class. +./tst_detail/.* ternary_tree implementation files +iterator_wrapper.hpp - iterator interface, included by all containers. + +--- d o c s --- +tst_public.doxy - doxygen config file, generates public interface of library. +tst.doxy - doxygen config file, generates public and private interface docs. +./doxygen_input/* - extra documentation sources used by Doxygen. + +./html/* - generated public and private documentation +full-docs-index.html - redirects to html directory +index.html - redirects to tst_docs directory, only useful if doxygen is used + with tst_public.doxy + +--- t e s t s --- +tst_concept_checks.cpp - requires Boost concept_check header, portable. +iterator_compile_test.cpp - checks iterator_wrapper interoperability, portable. + +test_tst.cpp - test suite; relies on non-portable wstring.hpp (but see below) +fill_dictionary.cpp - (sloppy old support file for test_tst) + fills a vector with strings from file. +wstring.hpp - string/wstring conversion, uses Windows API + if the MultiByteToWideChar and WideCharToMultiByte API calls are replaced, + test_tst may run on your platform... + +--- +rasmus ekman +May 14, 2006 Added: trunk/opentrep/ternary_tree/simple_tst.cpp =================================================================== --- trunk/opentrep/ternary_tree/simple_tst.cpp (rev 0) +++ trunk/opentrep/ternary_tree/simple_tst.cpp 2009-07-14 14:07:29 UTC (rev 127) @@ -0,0 +1,15 @@ +// C +#include <cassert> +// STL +#include <iostream> +// Ternary Tree Structure (TST) +//#include <structured_set.hpp> + +// /////////////// M A I N /////////////// +int main (int argc, char* argv[]) { + + std::cout << "Hello TST!" << std::endl; + + return 0; +} + Added: trunk/opentrep/ternary_tree/sources.mk =================================================================== --- trunk/opentrep/ternary_tree/sources.mk (rev 0) +++ trunk/opentrep/ternary_tree/sources.mk 2009-07-14 14:07:29 UTC (rev 127) @@ -0,0 +1,6 @@ +tst_h_sources = \ + $(top_srcdir)/ternary_tree/ternary_tree.hpp \ + $(top_srcdir)/ternary_tree/structured_set.hpp \ + $(top_srcdir)/ternary_tree/structured_map.hpp \ + $(top_srcdir)/ternary_tree/iterator_wrapper.hpp +tst_cc_sources = Modified: trunk/opentrep/ternary_tree/structured_map.hpp =================================================================== --- trunk/opentrep/ternary_tree/structured_map.hpp 2009-07-14 10:45:19 UTC (rev 126) +++ trunk/opentrep/ternary_tree/structured_map.hpp 2009-07-14 14:07:29 UTC (rev 127) @@ -1,938 +1,938 @@ -#ifndef STRUCTURED_MAP_HPP_INCLUDED -#define STRUCTURED_MAP_HPP_INCLUDED - -#define TST_NO_STANDALONE_ITERATOR_FACADE -#include "ternary_tree.hpp" -#undef TST_NO_STANDALONE_ITERATOR_FACADE -// note: also #include <list> in structured_multimap section - -namespace containers { - - -/** Structured Map is a Sorted Associative Container that stores objects of type pair<Key, Data>. - * Structured Map is a Structured Container, meaning that its key type is required to be - * a Forward Container, and that the map uses a comparator to establish - * a strict weak ordering among key::value_type elements (rather than on whole keys). - * This allows searches in the set involving parts of keys, ie with shared prefix - * or with shared middle parts. - * - * Structured Map is a Pair Associative Container, meaning that its value type - * is pair<const Key, T>. - * It is also a Unique Associative Container, meaning that no two elements are the same. - * - * A std::map is normally backed by a binary tree. A structured map is instead backed - * by a ternary_tree, which manages structured ordering of keys. - * For string-like keys, a ternary tree is typically as fast as an unordered_map, - * and several times faster than most std::map implementations. - * \ingroup containers - */ -template<class KeyT, class DataT, class CompT = std::less<typename KeyT::value_type>, - class AllocT = std::allocator<std::pair<const KeyT, DataT> > > -class structured_map -{ -public: - typedef KeyT key_type; - typedef DataT mapped_type; - typedef std::pair<const KeyT, DataT> value_type; - typedef typename KeyT::value_type char_type; - typedef CompT char_compare; - - typedef AllocT allocator_type; - typedef typename AllocT::difference_type difference_type; - typedef typename AllocT::size_type size_type; - typedef typename AllocT::pointer pointer; - typedef typename AllocT::const_pointer const_pointer; - typedef typename AllocT::reference reference; - typedef typename AllocT::const_reference const_reference; - -private: - // Internal value type is pair<Key, Value> (non-const Key). - typedef ternary_tree< KeyT, value_type, CompT, - typename AllocT::template rebind<value_type>::other - > ternary_tree; - typedef typename ternary_tree::iterator tst_iterator; - typedef typename ternary_tree::iterator::base_iter tst_iterator_base; - typedef typename ternary_tree::const_iterator tst_const_iterator; - - enum { invalid_index = size_type(-1) }; - -public: - - typedef typename ternary_tree::key_compare key_compare; - - - typedef iterators::iterator_wrapper < tst_iterator_base - , iterators::nonconst_traits<value_type> - > iterator; - - typedef iterators::iterator_wrapper < tst_iterator_base - , iterators::const_traits<value_type> - > const_iterator; - - typedef std::reverse_iterator<iterator> reverse_iterator; - typedef std::reverse_iterator<const_iterator> const_reverse_iterator; - - - /** \name Construct, copy, destroy - * @{ - */ - structured_map() : m_tree(char_compare(), allocator_type()) {} - - explicit structured_map(const char_compare& comp) - : m_tree(comp, allocator_type()) - {} - - structured_map(const char_compare& comp, const allocator_type& alloc) - : m_tree(comp, alloc) - {} - - template<class InputIterator> - structured_map( InputIterator first, InputIterator last, - const char_compare& comp = char_compare(), - const allocator_type& alloc = allocator_type()) - : m_tree(comp, alloc) - { - insert(first, last); - } - - structured_map(const structured_map& other) - : m_tree(other.m_tree) - {} - - ~structured_map() {} - - structured_map& operator= (const structured_map& other) { - structured_map(other).swap(*this); - return *this; - } - - allocator_type get_allocator() const { return m_tree.get_allocator(); } - /* @} */ - - /** \name Iterators - * Includes C++0x methods cbegin, cend, crbegin, crend to make it easier - * to access const iterators. - * @{ - */ - iterator begin() { return iterator(m_tree.begin()); } - const_iterator begin() const { return const_iterator(m_tree.begin()); } - iterator end() { return iterator(m_tree.end()); } - const_iterator end() const { return const_iterator(m_tree.end()); } - - reverse_iterator rbegin() { return reverse_iterator(end()); } - const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } - reverse_iterator rend() { return reverse_iterator(begin()); } - const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } - - // C++0x additions - const_iterator cbegin() const { return const_iterator(m_tree.begin()); } - const_iterator cend() const { return const_iterator(m_... [truncated message content] |