Update of /cvsroot/adobe-source/sandbox/visual_refactor/adobe In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27679/adobe Added Files: adam.hpp adam_evaluate.hpp adam_parser.hpp algorithm.hpp array.hpp array_fwd.hpp circular_queue.hpp cmath.hpp config.hpp conversion.hpp copy_on_write.hpp counter.hpp dictionary.hpp dictionary_fwd.hpp empty.hpp eve.hpp eve_evaluate.hpp eve_parser.hpp final.hpp forest.hpp functional.hpp istream.hpp istream_fwd.hpp iterator.hpp name.hpp name_fwd.hpp numeric.hpp once.hpp rectangle.hpp static_table.hpp string.hpp table_index.hpp typeinfo.hpp value.hpp value_fwd.hpp virtual_machine.hpp xstr.hpp Log Message: SO SORRY for the large qty of emails -- creating a branch for Adobe Begin refactoring. --- NEW FILE: copy_on_write.hpp --- /* Copyright 2005 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /*************************************************************************************************/ #ifndef ADOBE_COPY_ON_WRITE_HPP #define ADOBE_COPY_ON_WRITE_HPP /*************************************************************************************************/ #include <algorithm> #include <adobe/algorithm.hpp> #include <adobe/counter.hpp> #include <boost/operators.hpp> /*************************************************************************************************/ namespace adobe { /*************************************************************************************************/ template <typename T> class copy_on_write; template <typename T> bool operator == (const copy_on_write<T>&, const copy_on_write<T>&); template <typename T> bool operator < (const copy_on_write<T>&, const copy_on_write<T>&); /*************************************************************************************************/ } // namespace adobe /*************************************************************************************************/ template <typename T> void swap(adobe::copy_on_write<T>&, adobe::copy_on_write<T>&); /*************************************************************************************************/ namespace adobe { /*************************************************************************************************/ template <typename T> class copy_on_write : boost::totally_ordered<copy_on_write<T> > { public: typedef T value_type; explicit copy_on_write(const value_type& x = value_type()) : object_m(new implementation_t(x)) { } copy_on_write(const copy_on_write& x) : object_m(x.object_m) { object_m->ref_count_m.increment(); } ~copy_on_write() { if (object_m->ref_count_m.decrement()) delete object_m; } copy_on_write& operator = (const copy_on_write& x) { x.object_m->ref_count_m.increment(); if (object_m->ref_count_m.decrement()) delete object_m; object_m = x.object_m; return *this; } value_type& write() { if (!object_m->ref_count_m.is_one()) { implementation_t* temp = new implementation_t(object_m->value_m); object_m->ref_count_m.decrement(); object_m = temp; } return object_m->value_m; } operator const value_type& () const { return object_m->value_m; } const value_type& operator * () const { return object_m->value_m; } const value_type* operator -> () const { return &object_m->value_m; } bool unique_instance() const { return object_m->ref_count_m.is_one(); } bool identity(const copy_on_write<T>& x) const { return object_m == x.object_m; } private: #ifdef BOOST_MSVC friend void ::swap<T>(adobe::copy_on_write<T>&, adobe::copy_on_write<T>&); #else friend void ::swap<>(adobe::copy_on_write<T>&, adobe::copy_on_write<T>&); #endif #if !defined(ADOBE_NO_DOCUMENTATION) friend bool operator == <>(const copy_on_write<T>& x, const copy_on_write<T>& y); friend bool operator < <>(const copy_on_write<T>& x, const copy_on_write<T>& y); #endif #if !defined(ADOBE_NO_DOCUMENTATION) struct implementation_t; implementation_t* object_m; #endif }; /*************************************************************************************************/ #if !defined(ADOBE_NO_DOCUMENTATION) template <typename T> struct copy_on_write<T>::implementation_t { implementation_t(const value_type& x) : value_m(x) { } value_type value_m; adobe::counter_t ref_count_m; }; #endif /*************************************************************************************************/ template <typename T> bool operator == (const copy_on_write<T>& x, const copy_on_write<T>& y) { return x.object_m == y.object_m || x.object_m->value_m == y.object_m->value_m; } template <typename T> bool operator < (const copy_on_write<T>& x, const copy_on_write<T>& y) { return x.object_m != y.object_m && x.object_m->value_m < y.object_m->value_m; } /*************************************************************************************************/ } // namespace adobe /*************************************************************************************************/ template <typename T> inline void swap(adobe::copy_on_write<T>& x, adobe::copy_on_write<T>& y) { std::swap(x.object_m, y.object_m); } /*************************************************************************************************/ #endif /*************************************************************************************************/ --- NEW FILE: eve.hpp --- /* Copyright 2005 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /*************************************************************************************************/ #ifndef ADOBE_EVE_HPP #define ADOBE_EVE_HPP #include <utility> #include <vector> #include <boost/array.hpp> #include <boost/function.hpp> #include <boost/utility.hpp> #include <adobe/forest.hpp> #include <adobe/algorithm.hpp> #include <adobe/name_fwd.hpp> #include <adobe/virtual_machine.hpp> #include <adobe/rectangle.hpp> #include <adobe/source/expression_parser.hpp> /*************************************************************************************************/ namespace adobe { /*************************************************************************************************/ class eve_t #if !defined(ADOBE_NO_DOCUMENTATION) : boost::noncopyable, public rectangle_slices_t #endif { public: struct signal_suite_t; struct calculate_data_t; struct place_data_t; #if !defined(ADOBE_NO_DOCUMENTATION) struct view_proxy_t; typedef forest<view_proxy_t> proxy_tree_t; typedef proxy_tree_t::iterator iterator; typedef proxy_tree_t::child_iterator child_iterator; typedef proxy_tree_t::reverse_child_iterator reverse_child_iterator; #endif typedef boost::function<void (const place_data_t&)> debug_frame_proc_t; enum alignment_t { align_default, align_forward, align_reverse, align_center, align_proportional, align_fill, align_left = align_forward, align_right = align_reverse, align_top = align_forward, align_bottom = align_reverse }; enum placement_t { place_leaf, place_column, place_row, place_overlay, place_row_forced_left_to_right // REVISIT (sparent) : Unimplemented }; enum evaluate_options_t { evaluate_nested, // coordinate space is relative to container evaluate_flat // flatten the cooridnate space }; struct insert_element_t { #if !defined(ADOBE_NO_DOCUMENTATION) explicit insert_element_t(bool c, const dictionary_t& p, const signal_suite_t& s); #endif bool is_container_type_m; // is the element a container? const dictionary_t& parameters_m; // parameters to shape the element const signal_suite_t& signals_m; // signals to call for the element private: insert_element_t(); // not defined }; #if !defined(ADOBE_NO_DOCUMENTATION) explicit eve_t(); ~eve_t(); #endif iterator add_view_element(const iterator& parent, const insert_element_t& element); void evaluate(evaluate_options_t); void adjust(long width, long height, evaluate_options_t); void set_debug_frame_proc(const debug_frame_proc_t& proc); void do_framing(); private: class implementation_t; implementation_t* object_m; }; /*************************************************************************************************/ typedef points_of_interest_t guides_t; struct eve_t::calculate_data_t #if !defined(ADOBE_NO_DOCUMENTATION) : rectangle_slices_t #endif { calculate_data_t(); typedef std::vector<long> spacing_t; struct slice_t { slice_t(); long length_m; pair_long_t outset_m; eve_t::alignment_t alignment_m; guides_t guides_m; bool suppress_m; bool balance_m; // containers only pair_long_t margin_m; pair_long_t frame_m; pair_long_t inset_m; eve_t::alignment_t child_alignment_m; }; long indent_m; bool create_m; spacing_t spacing_m; boost::array<slice_t, 2> slice_m; // containers only eve_t::placement_t placement_m; }; /*************************************************************************************************/ struct eve_t::place_data_t #if !defined(ADOBE_NO_DOCUMENTATION) : rectangle_slices_t #endif { #if !defined(ADOBE_NO_DOCUMENTATION) place_data_t& operator=(const eve_t::calculate_data_t&); #endif struct slice_t { #if !defined(ADOBE_NO_DOCUMENTATION) slice_t(); slice_t& operator=(const eve_t::calculate_data_t::slice_t&); #endif long length_m; long position_m; pair_long_t outset_m; guides_t guides_m; }; boost::array<slice_t, 2> slice_m; }; /*************************************************************************************************/ struct eve_t::signal_suite_t { typedef boost::function<void (eve_t::calculate_data_t&)> eve_container_defaults_proc_t; typedef boost::function<void (eve_t::calculate_data_t&)> eve_calculate_proc_t; typedef boost::function<void (eve_t::calculate_data_t&, const eve_t::place_data_t&)> eve_calculate_vertical_proc_t; typedef boost::function<void (const eve_t::calculate_data_t&, const eve_t::place_data_t&)> eve_place_proc_t; eve_container_defaults_proc_t eve_container_defaults_proc_m; eve_calculate_proc_t eve_calculate_proc_m; eve_calculate_vertical_proc_t eve_calculate_vertical_proc_m; eve_place_proc_t eve_place_proc_m; }; /*************************************************************************************************/ void set_margin(eve_t::calculate_data_t& container, long x); /*************************************************************************************************/ } // namespace adobe /*************************************************************************************************/ #endif /*************************************************************************************************/ --- NEW FILE: numeric.hpp --- /* Copyright 2005 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /*************************************************************************************************/ #ifndef ADOBE_NUMERIC_HPP #define ADOBE_NUMERIC_HPP #include <iterator> #include <numeric> #include <boost/bind.hpp> // REVISIT (sparent): dissable warnings for unused arguments in boost 1.32.0 #if defined(__MWERKS__) #pragma warn_unusedarg off #endif #include <boost/range.hpp> #if defined(__MWERKS__) #pragma warn_unusedarg reset #endif namespace adobe { /*************************************************************************************************/ #if !defined(ADOBE_NO_DOCUMENTATION) namespace fn { } using namespace fn; namespace fn { #endif /*************************************************************************************************/ template <typename ForwardIterator> ForwardIterator max_adjacent_difference(ForwardIterator first, ForwardIterator last) { typedef typename std::iterator_traits<ForwardIterator>::value_type value_type; ForwardIterator result(first); if (first == last) return result; ForwardIterator previous(first); ++first; if (first == last) return result; value_type result_difference(*first - *previous); previous = first; ++first; while (first != last) { value_type difference(*first - *previous); if (result_difference < difference) { result_difference = difference; result = previous; } previous = first; ++first; } return result; } template <typename ForwardRange> inline typename boost::range_iterator<ForwardRange>::type max_adjacent_difference(ForwardRange& range) { return adobe::max_adjacent_difference(boost::begin(range), boost::end(range)); } template <typename ForwardRange> inline typename boost::range_const_iterator<ForwardRange>::type max_adjacent_difference(const ForwardRange& range) { return adobe::max_adjacent_difference(boost::begin(range), boost::end(range)); } /*************************************************************************************************/ #if !defined(ADOBE_NO_DOCUMENTATION) } // namespace fn #endif } // namespace adobe /*************************************************************************************************/ #endif /*************************************************************************************************/ --- NEW FILE: dictionary.hpp --- /* Copyright 2005 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /*************************************************************************************************/ #ifndef ADOBE_DICTIONARY_HPP #define ADOBE_DICTIONARY_HPP /*************************************************************************************************/ #include <cstddef> #include <functional> #include <iterator> #include <utility> #include <boost/operators.hpp> #include <adobe/array_fwd.hpp> #include <adobe/copy_on_write.hpp> #include <adobe/dictionary_fwd.hpp> #include <adobe/name_fwd.hpp> #include <adobe/value.hpp> #include <adobe/conversion.hpp> /*************************************************************************************************/ namespace adobe { /*************************************************************************************************/ /* REVISIT (fbrereto) : See the comment in array.hpp for the related explanation of array_get's struct */ template <typename T> struct dictionary_get; /*************************************************************************************************/ template <class T> dictionary_t& dictionary_set(dictionary_t& object, name_t key, const T& value); /*************************************************************************************************/ bool operator == (const dictionary_t& x, const dictionary_t& y); /*************************************************************************************************/ class dictionary_t : boost::equality_comparable<dictionary_t> { public: #if !defined(ADOBE_NO_DOCUMENTATION) struct implementation_t; #endif // !defined(ADOBE_NO_DOCUMENTATION) typedef name_t key_type; typedef value_t mapped_type; /* REVISIT: Shouldn't name_t be const in pair? look at map. */ typedef std::pair<name_t, value_t> value_type; typedef std::less<name_t> key_compare; typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; typedef value_type& reference; typedef const value_type& const_reference; typedef value_type* pointer; typedef const value_type* const_pointer; class insert_iterator; #if !defined(ADOBE_NO_DOCUMENTATION) friend class insert_iterator; #endif // !defined(ADOBE_NO_DOCUMENTATION) class const_iterator; #if !defined(ADOBE_NO_DOCUMENTATION) friend class const_iterator; #endif // !defined(ADOBE_NO_DOCUMENTATION) #if defined(__GNUC__) || defined(BOOST_MSVC) // GCC won't compile without this: typedef const_iterator iterator; // ../../third_party/boost_tp/boost/boost/range/iterator.hpp:37: error: no type // named `iterator' in `const class adobe::dictionary_t' #endif struct value_compare : public std::binary_function<value_type, value_type, bool> { bool operator()(const value_type& x, const value_type& y) const; }; typedef std::reverse_iterator<const_iterator> const_reverse_iterator; // basic methods #if !defined(ADOBE_NO_DOCUMENTATION) dictionary_t(); dictionary_t(const dictionary_t&); ~dictionary_t(); dictionary_t& operator = (const dictionary_t&); #endif // !defined(ADOBE_NO_DOCUMENTATION) // read interface const value_t& at (name_t key) const; const value_t& operator[] (name_t key) const; template <typename T> const typename promote<T>::type& get(name_t key) const; template <typename T> void get(name_t key, T& value) const; // write interface class write_reference; write_reference write(); template <class T> dictionary_t& set (name_t key, const T& x) { return dictionary_set(*this, key, x); } class insert_iterator : public std::iterator <std::output_iterator_tag, void, void, void, void> { public: typedef std::pair<const name_t, value_t> value_type; insert_iterator& operator = (const value_type& value); insert_iterator& operator * () throw() { return *this; } insert_iterator& operator ++ () throw() { return *this; } insert_iterator& operator ++ (int) throw() { return *this;} protected: friend class dictionary_t; insert_iterator (dictionary_t& r); private: implementation_t& fReference; }; bool empty() const; size_type size() const; size_type max_size() const; size_type erase(name_t x); void clear(); value_compare value_comp() const { return value_compare(); } key_compare key_comp() const { return key_compare(); } const_iterator find (name_t x) const; size_type count (name_t x) const; const_iterator begin() const; const_iterator end() const; const_reverse_iterator rbegin() const; const_reverse_iterator rend() const; bool insert(const value_type& value); template <class InputIterator> inline void insert(InputIterator first, InputIterator last) { std::copy(first, last, inserter()); } insert_iterator inserter() { return insert_iterator(*this); } // cow specific methods bool identity(const dictionary_t& x) const { return object_m.identity(x.object_m); } bool unique_instance() const; protected: #if !defined(ADOBE_NO_DOCUMENTATION) friend struct dictionary_get<value_t>; friend dictionary_t& dictionary_set<>(dictionary_t&, name_t, const value_t&); friend class write_reference; value_t& get_value_reference(name_t x); private: adobe::copy_on_write<implementation_t> object_m; #endif // !defined(ADOBE_NO_DOCUMENTATION) }; /*************************************************************************************************/ class dictionary_t::write_reference { public: value_t& operator[] (name_t key); protected: friend class dictionary_t; write_reference(dictionary_t& x) : fDictionary(x) { } private: dictionary_t& fDictionary; }; /*************************************************************************************************/ inline dictionary_t::write_reference dictionary_t::write() { return write_reference(*this); } /*************************************************************************************************/ template <> dictionary_t& dictionary_set(dictionary_t&, name_t, const value_t&); template <class T> dictionary_t& dictionary_set(dictionary_t& object, name_t key, const T& x) { return dictionary_set(object, key, value_t(x)); } /*************************************************************************************************/ template <> struct dictionary_get<value_t> { const promote<value_t>::type& operator () (const dictionary_t& object, name_t key, select<value_t>); void operator () (const dictionary_t& object, name_t key, value_t& value); }; template <typename T> struct dictionary_get { const typename promote<T>::type& operator () (const dictionary_t& object, name_t key, select<T>) { return dictionary_get<value_t>()(object, key, select<value_t>()).template get<T>(); } void operator () (const dictionary_t& object, name_t key, T& value) { value_t result; dictionary_get<value_t>()(object, key, result); result.get(value); } }; /*************************************************************************************************/ template <typename T> inline const typename promote<T>::type& dictionary_t::get(name_t key) const { return dictionary_get<T>()(*this, key, select<T>()); } template <typename T> inline void dictionary_t::get(name_t key, T& value) const { dictionary_get<T>()(*this, key, value); } /*************************************************************************************************/ template <class InputIterator> dictionary_t dictionary_ctor(InputIterator first, InputIterator last) { dictionary_t result; std::copy(first, last, result.inserter()); return result; } /*************************************************************************************************/ template <typename T> dictionary_t dictionary_ctor(const char* k0, const T& v0) { dictionary_t result; result.set(name_t(k0), v0); return result; } template <typename K0, typename V0, typename K1, typename V1> dictionary_t dictionary_ctor( const K0& k0, const V0& v0, const K1& k1, const V1& v1 ) { dictionary_t result; result.set(name_t(k0), v0); result.set(name_t(k1), v1); return result; } /*************************************************************************************************/ class dictionary_t::const_iterator : public std::iterator<std::bidirectional_iterator_tag, dictionary_t::value_type, dictionary_t::difference_type, dictionary_t::const_pointer, dictionary_t::const_reference> { public: typedef dictionary_t::const_reference const_reference; typedef dictionary_t::const_pointer const_pointer; const_iterator(const const_iterator& x); ~const_iterator() throw(); const_iterator& operator= (const const_iterator& x); const_reference operator* () const throw(); const_pointer operator -> () const throw(); const_iterator& operator++ () throw(); const_iterator operator++ (int); const_iterator& operator-- () throw(); const_iterator operator-- (int); bool operator== (const const_iterator& rhs) const throw(); bool operator!= (const const_iterator& rhs) const throw(); protected: friend class dictionary_t; class begin { }; class end { }; const_iterator(const dictionary_t&, begin); const_iterator(const dictionary_t&, end); const_iterator(const dictionary_t&, name_t x); // Find form private: class implementation; const_iterator::implementation* object; }; /*************************************************************************************************/ inline dictionary_t::const_iterator dictionary_t::begin() const { return const_iterator(*this, const_iterator::begin()); } inline dictionary_t::const_iterator dictionary_t::end() const { return const_iterator(*this, const_iterator::end()); } inline dictionary_t::const_reverse_iterator dictionary_t::rbegin() const { return const_reverse_iterator(end()); } inline dictionary_t::const_reverse_iterator dictionary_t::rend() const { return const_reverse_iterator(begin()); } /*************************************************************************************************/ } // namespace adobe /*************************************************************************************************/ #endif /*************************************************************************************************/ --- NEW FILE: static_table.hpp --- /* Copyright 2005 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /*************************************************************************************************/ #ifndef ADOBE_STATIC_TABLE_HPP #define ADOBE_STATIC_TABLE_HPP /*************************************************************************************************/ #include <utility> #include <adobe/algorithm.hpp> /*************************************************************************************************/ namespace adobe { /*************************************************************************************************/ template <typename KeyType, typename ValueType> struct static_table_traits { typedef bool result_type; typedef KeyType key_type; typedef ValueType value_type; typedef std::pair<key_type, value_type> entry_type; result_type operator()(const entry_type& x, const entry_type& y) const { return (*this)(x, y.first); } result_type operator()(const entry_type& x, const key_type& y) const { return x.first < y; } result_type equal(const key_type& x, const key_type& y) const { return x == y; } }; /*************************************************************************************************/ template <typename KeyType, typename ValueType, std::size_t Size, typename Traits = static_table_traits<KeyType, ValueType> > struct static_table { typedef Traits traits_type; typedef typename traits_type::key_type key_type; typedef typename traits_type::value_type value_type; typedef typename traits_type::entry_type entry_type; const value_type& operator()(const key_type& key) const { const entry_type* iter(adobe::lower_bound(table_m, key, traits_type())); if (iter == boost::end(table_m) || !traits_type().equal(iter->first, key)) throw std::logic_error("static_table key not found"); return iter->second; } bool operator()(const key_type& key, value_type& result) const { const entry_type* iter(adobe::lower_bound(table_m, key, traits_type())); if (iter == boost::end(table_m) || !traits_type().equal(iter->first, key)) return false; result = iter->second; return true; } void sort() { adobe::sort(table_m, traits_type()); } public: entry_type table_m[Size]; }; /*************************************************************************************************/ } // namespace adobe /*************************************************************************************************/ #endif // ADOBE_STATIC_TABLE_HPP /*************************************************************************************************/ --- NEW FILE: typeinfo.hpp --- /* Copyright 2005 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /*************************************************************************************************/ #include <string> #include <typeinfo> /*************************************************************************************************/ namespace adobe { /*************************************************************************************************/ class bad_cast : public std::bad_cast { public: bad_cast(); bad_cast(const std::type_info& from, const std::type_info& to); bad_cast(const bad_cast&); bad_cast& operator=(const bad_cast&); virtual ~bad_cast() throw(); virtual const char* what() const throw(); private: std::string what_m; }; /*************************************************************************************************/ } // namespace adobe /*************************************************************************************************/ --- NEW FILE: eve_parser.hpp --- /* Copyright 2005 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /*************************************************************************************************/ #ifndef ADOBE_EVE_PARSER_HPP #define ADOBE_EVE_PARSER_HPP #include <string> #include <boost/any.hpp> #include <boost/function.hpp> #include <adobe/array_fwd.hpp> #include <adobe/istream.hpp> #include <adobe/name_fwd.hpp> /*************************************************************************************************/ /* Eve Grammer: ---------------------------------------- view_definition = [lead_comment] view_class_decl ((";" [trail_comment]) | ([trail_comment] view_statement_list). view_statment_sequence = { view_definition }. view_class_decl = ident "(" [ named_argument_list ] ")". view_statment_list = "{" view_statement_sequence "}". */ /*************************************************************************************************/ namespace adobe { namespace eve { /*************************************************************************************************/ typedef boost::any position_t; typedef boost::function<position_t ( const position_t& parent, const line_position_t& parse_location, adobe::name_t name, const adobe::array_t& parameters, const std::string& brief, const std::string& detailed)> assemble_t; line_position_t parse(std::istream& in, const line_position_t&, const position_t&, const assemble_t&); /*************************************************************************************************/ } // namespace eve } // namespace adobe /*************************************************************************************************/ #endif // ADOBE_EVE_PARSER_HPP /*************************************************************************************************/ --- NEW FILE: cmath.hpp --- /* Copyright 2005 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /*************************************************************************************************/ /*! \file <adobe/cmath.hpp> provides typedef's based on the 1999 C Standard header \<math.h\>, wrapped in namespace adobe. The implementation may #include \<math.h\>. */ /* REVISIT (sparent) : Need to replicate the boost configuration tests to figure out when to fall back to include math.h. This also needs to add any other C99 math.h extensions. */ #ifndef ADOBE_CMATH_HPP #define ADOBE_CMATH_HPP #include <adobe/config.hpp> #include <cmath> #if ADOBE_PLATFORM_MAC && defined(__MWERKS__) namespace adobe { using std::float_t; using std::double_t; using std::round; } // namespace adobe #elif defined(ADOBE_PLATFORM_WIN) || \ defined(ADOBE_PLATFORM_UNIX) || \ defined(ADOBE_PLATFORM_LINUX) namespace adobe { typedef float float_t; typedef double double_t; template <typename T> inline T round(const T& x) { return std::floor(x + .5f); } } // namespace adobe #else #include <math.h> namespace adobe { using ::float_t; using ::double_t; using ::round; } // namespace adobe #endif /*************************************************************************************************/ #endif /*************************************************************************************************/ --- NEW FILE: functional.hpp --- /* Copyright 2005 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /*************************************************************************************************/ #ifndef ADOBE_FUNCTIONAL_HPP #define ADOBE_FUNCTIONAL_HPP #include <cassert> #include <functional> /*************************************************************************************************/ namespace adobe { /*************************************************************************************************/ template <typename T> struct delete_ptr; template <typename T> struct delete_ptr<T*> : std::unary_function<T*, void> { void operator () (T* x) const throw() { delete x; } }; template <typename T> struct delete_ptr<T* const> : std::unary_function<T*, void> { void operator () (T* x) const throw() { delete x; } }; template <typename T> struct delete_ptr<T(*)[]> : std::unary_function<T*, void> { void operator () (T* x) const throw() { delete [] x; } }; template <typename T> struct delete_ptr<T(* const)[]> : std::unary_function<T*, void> { void operator () (T* x) const throw() { delete [] x; } }; /*************************************************************************************************/ template<class T> struct constructor { typedef T result_type; T operator()() const { return T(); } template<class A1> T operator()(const A1& a1) const { return T(a1); } template<class A1, class A2> T operator()(const A1& a1, const A2& a2) const { return T(a1, a2); } template<class A1, class A2, class A3> T operator()(const A1& a1, const A2& a2, const A3& a3) const { return T(a1, a2, a3); } template<class A1, class A2, class A3, class A4> T operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) const { return T(a1, a2, a3, a4); } template<class A1, class A2, class A3, class A4, class A5> T operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) const { return T(a1, a2, a3, a4, a5); } }; /*************************************************************************************************/ template <class Result> struct generator_t { typedef Result result_type; }; /*************************************************************************************************/ template <typename T> struct sequence_t #if !defined(ADOBE_NO_DOCUMENTATION) : generator_t<T> #endif { explicit sequence_t(const T& x) : data_m(x) { } const T& operator () () { return data_m++; } private: T data_m; }; /*************************************************************************************************/ template <class T, typename R, class Compare> struct compare_members_t : std::binary_function<T, T, bool> { compare_members_t(R T::* member, Compare compare) : compare_m(compare), member_m(member) { } bool operator () (const T& x, const T& y) const { return compare_m(x.*member_m, y.*member_m); } bool operator () (const T& x, const R& y) const { return compare_m(x.*member_m, y); } bool operator () (const R& x, const T& y) const { return compare_m(x, y.*member_m); } private: /* REVISIT (sparent) : This could probably use an empty member optimization. */ Compare compare_m; R T::* member_m; }; template <class T, typename R> compare_members_t<T, R, std::less<R> > compare_members(R T::* member) { return compare_members_t<T, R, std::less<R> >(member, std::less<R>() ); } template <class T, typename R, class Compare> compare_members_t<T, R, Compare> compare_members(R T::* member, Compare compare) { return compare_members_t<T, R, Compare>(member, compare); } /*************************************************************************************************/ /* REVISIT (sparent) : This work is to be part of table indexes. A table index is a container of pointers to objects with a transformation. Getting to the key in a table is an indirect transformation Getting to a row in a table is an indirection Note indirection is a transformation - so it is two levels of transformation. To sort a table by the key I want to be able to do: adobe::sort(index.base(), index.transform_compare()); */ /*************************************************************************************************/ template <class T, typename R> struct transform_member_t : std::unary_function<T, R&> { explicit transform_member_t(R T::* member) : member_m(member) { } R& operator () (T& x) const { return x.*member_m; } const R& operator () (const T& x) const { return x.*member_m; } private: R T::* member_m; }; template <class T, typename R> transform_member_t<T, R> make_transform(R T::* member) { return transform_member_t<T, R>(member); } /*************************************************************************************************/ template <typename Pointer, typename Reference> struct indirect_t : std::unary_function<Pointer, Reference> { Reference& operator () (Pointer& x) const { return *x; } const Reference& operator () (const Pointer& x) const { return *x; } }; /*************************************************************************************************/ template <class T> struct bitwise_or : std::binary_function<T, T, T> { T operator()(const T& x, const T& y) const {return x | y;} }; /*************************************************************************************************/ template <class T> struct bitwise_and : std::binary_function<T, T, T> { T operator()(const T& x, const T& y) const {return x & y;} }; /*************************************************************************************************/ template <class T> struct bitwise_xor : std::binary_function<T, T, T> { T operator()(const T& x, const T& y) const {return x ^ y;} }; /*************************************************************************************************/ } // namespace adobe /*************************************************************************************************/ #endif /*************************************************************************************************/ --- NEW FILE: array.hpp --- /* Copyright 2005 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /*************************************************************************************************/ #ifndef ADOBE_ARRAY_HPP #define ADOBE_ARRAY_HPP /*************************************************************************************************/ // REVISIT (fbrereto) : GCC has a compiler bug when it comes to befriending a function inside // another namespace. Herb Sutter has written an article about it: // http://gcc.gnu.org/ml/gcc-prs/2002-10/msg01010.html -- This flag moves // the array_get/array_set code out of the implementation namespace so it // can compile under GCC. #define ADOBE_NAMESPACE_FRIEND_GCC_BUG 0 /*************************************************************************************************/ #include <cstddef> #include <iterator> #include <vector> #include <boost/operators.hpp> #include <adobe/array_fwd.hpp> #include <adobe/copy_on_write.hpp> /* NOTE (sparent) : This file can't just pull in value_fwd.hpp because some of the template functions require the full definition of adobe::value_t. */ #include <adobe/value.hpp> /*************************************************************************************************/ namespace adobe { /*************************************************************************************************/ /* REVISIT (fbrereto) : The array_get functor is in place because VC 7.1 emits a C2912 explicit specialization error when trying to specialize: template <class T> void array_get(const array_t& object, std::size_t index, T& x); ...and... template <class T> const typename promote<T>::type& array_get(const array_t& object, std::size_t index, select<T>); for the case when T is adobe::value_t. This is a compiler bug. Varied posts have been made about the topic: http://groups-beta.google.com/groups?q=C2912&hl=en&lr=&c2coff=1&safe=off&sa=N&tab=wg Several of the postings state the bug has been fixed with VC2005 Alpha. */ /*************************************************************************************************/ #if !defined(ADOBE_NO_DOCUMENTATION) #if ADOBE_NAMESPACE_FRIEND_GCC_BUG namespace implementation { #endif /*************************************************************************************************/ template <typename T> struct array_get; template <class T> array_t& array_set(array_t& object, std::size_t index, const T& value); template <class T> array_t& array_push_back(array_t& object, const T& value); /*************************************************************************************************/ #if ADOBE_NAMESPACE_FRIEND_GCC_BUG } // namespace implementation #endif #endif /*************************************************************************************************/ bool operator==(const array_t& x, const array_t& y); /*************************************************************************************************/ class array_t : boost::equality_comparable<array_t> { public: #if !defined(ADOBE_NO_DOCUMENTATION) struct implementation_t; #endif typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; typedef value_t value_type; typedef value_type& reference; typedef const value_type& const_reference; typedef value_type* pointer; typedef const value_type* const_pointer; class back_insert_iterator; typedef std::vector<value_t>::const_iterator const_iterator; /* NOTE (sparent) : All iterators are const - an iterator typedef, however, is needed to meet the container requirements. */ typedef const_iterator iterator; #if !defined(ADOBE_NO_DOCUMENTATION) friend class back_insert_iterator; #endif typedef std::reverse_iterator<const_iterator> const_reverse_iterator; typedef const_reverse_iterator reverse_iterator; // basic methods #if !defined(ADOBE_NO_DOCUMENTATION) array_t(); array_t(const array_t& r); array_t& operator = (const array_t&); ~array_t(); #endif explicit array_t(size_type n, const value_t& item = value_empty()); #if 0 // REVISIT (sparent) : This constructor requires access to implementation - // so we use a function form (copy) instead. template <class InputIterator> array_t(InputIterator first, InputIterator last); #endif // read interface const_reference at(size_type index) const; const_reference operator[](size_type index) const; template <class T> const typename promote<T>::type& get(size_type index) const; template <class T> void get(size_type index, T& value) const; const_reference front() const; const_reference back() const; // write interface class write_reference; write_reference write(); template <class T> array_t& set(size_type index, const T& value) { #if ADOBE_NAMESPACE_FRIEND_GCC_BUG return implementation::array_set(*this, index, value); #else return array_set(*this, index, value); #endif } template <class T> array_t& push_back(const T& value) { #if ADOBE_NAMESPACE_FRIEND_GCC_BUG return implementation::array_push_back(*this, value); #else return array_push_back(*this, value); #endif } class back_insert_iterator : public boost::output_iterator_helper<back_insert_iterator> { public: typedef value_t value_type; template <typename T> back_insert_iterator& operator = (const T& value) { return operator = (value_type(value)); } back_insert_iterator& operator = (const value_type& value); private: friend class array_t; explicit back_insert_iterator (array_t& r); implementation_t& object_m; }; bool empty() const; size_type size() const; size_type max_size() const; void resize(size_type, const value_t& c = value_empty()); void assign(size_type, const value_t& u); size_type erase(size_type index); void pop_back(); void clear(); const_iterator begin() const; const_iterator end() const; const_reverse_iterator rbegin() const; const_reverse_iterator rend() const; back_insert_iterator back_inserter() { return back_insert_iterator(*this); } // cow specific methods bool identity(const array_t& x) const { return object_m.identity(x.object_m); } bool unique_instance() const; #if !defined(ADOBE_NO_DOCUMENTATION) private: #if ADOBE_NAMESPACE_FRIEND_GCC_BUG friend struct implementation::array_get<value_t>; friend array_t& implementation::array_set<>(array_t& object, size_type index, const value_t& value); friend array_t& implementation::array_push_back<>(array_t& object, const value_t& value); #else friend struct array_get<value_t>; friend array_t& array_set<>(array_t& object, size_type index, const value_t& value); friend array_t& array_push_back<>(array_t& object, const value_t& value); #endif friend class write_reference; value_t& get_value_reference(size_type x); adobe::copy_on_write<implementation_t> object_m; #endif }; /*************************************************************************************************/ class array_t::write_reference { public: value_t& operator[] (size_type index); private: friend class array_t; write_reference(array_t& x) : array_m(x) { } array_t& array_m; }; /*************************************************************************************************/ inline array_t::write_reference array_t::write() { return write_reference(*this); } /*************************************************************************************************/ #if ADOBE_NAMESPACE_FRIEND_GCC_BUG namespace implementation { #endif /*************************************************************************************************/ #if !defined(ADOBE_NO_DOCUMENTATION) template <> struct array_get<value_t> { const value_t& operator () (const array_t& object, array_t::size_type index, select<value_t>); void operator () (const array_t& object, array_t::size_type index, value_t& x); }; template <typename T> struct array_get { void operator () (const array_t& object, std::size_t index, T& x) { value_t result; array_get<value_t>()(object, index, result); result.get(x); } const typename promote<T>::type& operator () (const array_t& object, std::size_t index, select<T>) { return array_get<value_t>()(object, index, select<value_t>()).template get<T>(); } }; /*************************************************************************************************/ template <> array_t& array_set(array_t&, array_t::size_type, const value_t&); template <class T> array_t& array_set(array_t& object, array_t::size_type index, const T& x) { return array_set(object, index, value_t(x)); } /*************************************************************************************************/ template <> array_t& array_push_back(array_t&, const value_t&); template <class T> array_t& array_push_back(array_t& object, const T& x) { return array_push_back(object, value_t(x)); } #endif /*************************************************************************************************/ #if ADOBE_NAMESPACE_FRIEND_GCC_BUG } // namespace implementation #endif /*************************************************************************************************/ template <class T> inline const typename promote<T>::type& array_t::get(size_type index) const { #if ADOBE_NAMESPACE_FRIEND_GCC_BUG return implementation::array_get<T>()(*this, index, select<T>()); #else return array_get<T>()(*this, index, select<T>()); #endif } template <class T> inline void array_t::get(size_type index, T& value) const { #if ADOBE_NAMESPACE_FRIEND_GCC_BUG implementation::array_get<T>()(*this, index, value); #else array_get<T>()(*this, index, value); #endif } /*************************************************************************************************/ inline array_t::const_reverse_iterator array_t::rbegin() const { return const_reverse_iterator(end()); } inline array_t::const_reverse_iterator array_t::rend() const { return const_reverse_iterator(begin()); } /*************************************************************************************************/ } // namespace adobe /*************************************************************************************************/ #endif /*************************************************************************************************/ --- NEW FILE: xstr.hpp --- /* Copyright 2005 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /*************************************************************************************************/ #ifndef ADOBE_XSTR_HPP #define ADOBE_XSTR_HPP /*************************************************************************************************/ #include <adobe/name_fwd.hpp> #include <adobe/dictionary_fwd.hpp> #include <adobe/algorithm.hpp> /*************************************************************************************************/ namespace adobe { /*************************************************************************************************/ class xstr_t; /*************************************************************************************************/ } // namespace adobe /*************************************************************************************************/ #if !defined(ADOBE_NO_DOCUMENTATION) void swap(adobe::xstr_t& x, adobe::xstr_t& y); #endif /*************************************************************************************************/ namespace adobe { /*************************************************************************************************/ class xstr_t { public: typedef std::pair<const char*, const char*> parse_range_t; explicit xstr_t(const char* xstr); xstr_t(const char* xstr, std::size_t n); xstr_t(const char* xstr, std::size_t n, const adobe::dictionary_t& context); #if !defined(ADOBE_NO_DOCUMENTATION) xstr_t(const xstr_t& rhs); ~xstr_t(); xstr_t& operator = (const xstr_t& rhs); #endif const char* get() const; static void assign_glossary(const parse_range_t& parse_range); static void append_glossary(const parse_range_t& parse_range); static void set_default_context(const adobe::dictionary_t& context); static adobe::dictionary_t get_default_context(); private: #if !defined(ADOBE_NO_DOCUMENTATION) friend void ::swap(adobe::xstr_t& x, adobe::xstr_t& y); struct implementation_t; implementation_t* object_m; #endif }; /*************************************************************************************************/ } // namespace adobe /*************************************************************************************************/ #if !defined(ADOBE_NO_DOCUMENTATION) inline void swap(adobe::xstr_t& x, adobe::xstr_t& y) { adobe::swap(x.object_m, y.object_m); } #endif /*************************************************************************************************/ #endif /*************************************************************************************************/ --- NEW FILE: table_index.hpp --- /* Copyright 2005 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /*************************************************************************************************/ #include <functional> #include <boost/bind.hpp> #include <boost/function.hpp> #include <boost/operators.hpp> #include <boost/iterator/indirect_iterator.hpp> #include <adobe/algorithm.hpp> /*************************************************************************************************/ namespace adobe { /*************************************************************************************************/ template < class Key, class T, class Compare, class Transform > class table_index; /*************************************************************************************************/ } // namespace adobe /*************************************************************************************************/ template <class Key, class T, class Compare, class Transform> void swap( adobe::table_index<Key, T, Compare, Transform>& x, adobe::table_index<Key, T, Compare, Transform>& y); /*************************************************************************************************/ namespace adobe { /*************************************************************************************************/ template < class Key, class T, class Compare = std::less<Key>, class Transform = boost::function<const Key& (const T&)> > class table_index { public: typedef typename std::vector<T*> index_type; typedef Transform transform_type; typedef Key key_type; typedef T value_type; typedef Compare key_compare; // Revisit? // typedef Allocator allocator_type; typedef T& reference; typedef const T& const_reference; typedef typename index_type::size_type size_type; typedef typename index_type::difference_type difference_type; typedef T* pointer; typedef const T* const_pointer; typedef boost::indirect_iterator<typename index_type::iterator> iterator; typedef boost::indirect_iterator<typename index_type::const_iterator> const_iterator; typedef std::reverse_iterator<iterator> reverse_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator; template <class TransformPrimitive> explicit table_index(TransformPrimitive transform, const key_compare& compare = key_compare()) : transform_m(boost::bind<const key_type&>(transform, _1)), compare_m(compare) { } explicit table_index(const transform_type&, const key_compare& = key_compare()); template <class InputIterator> table_index( InputIterator first, InputIterator last, const transform_type&, const key_compare& = key_compare()); //allocator_type get_allocator() const; size_type max_size() const; size_type size() const; bool empty() const; iterator begin(); const_iterator begin() const; iterator end(); const_iterator end() const; reverse_iterator rbegin(); const_reverse_iterator rbegin() const; reverse_iterator rend(); const_reverse_iterator rend() const; const_reference at(size_type n) const; reference at(size_type n); reference front(); const_reference front() const; reference back(); const_reference back() const; void push_back(value_type&); void pop_back(); iterator insert(iterator, value_type&); template <class InputIterator> void insert(iterator position, InputIterator first, InputIterator last); iterator erase(iterator position); // only removes from index iterator erase(iterator first, iterator last); // only removes from index void clear(); void swap(table_index&); index_type& index(); const index_type& index() const; void sort(); // Operations on a sorted index. reference operator[](const key_type&); const_reference operator[](const key_type&) const; iterator find(const key_type& x); const_iterator find(const key_type& x) const; size_type count(const key_type& x) const; iterator lower_bound(const key_type& x); const_iterator lower_bound(const key_type& x) const; iterator upper_bound(const key_type& x); const_iterator upper_bound(const key_type& x) const; std::pair<iterator, iterator> equal_range(const key_type& x); std::pair<const_iterator, const_iterator> equal_range(const key_type& x) const; private: #ifdef BOOST_MSVC friend void ::swap<Key, T, Compare, Transform>( adobe::table_index<Key, T, Compare, Transform>& x, adobe::table_index<Key, T, Compare, Transform>& y); #else friend void ::swap<>( adobe::table_index<Key, T, Compare, Transform>& x, adobe::table_index<Key, T, Compare, Transform>& y); #endif #ifndef ADOBE_NO_DOCUMENTATION struct indirect_compare_t : std::binary_function<pointer, pointer, bool> { typedef bool result_type; indirect_compare_t(transform_type& transform, const key_compare& compare) : transform_m(transform), compare_m(compare) { } bool operator () (pointer x, pointer y) const { return compare_m(transform_m(*x), transform_m(*y)); } private: transform_type transform_m; /* REVISIT (sparent) : want reference here? */ key_compare compare_m; }; struct bound_predicate_t : std::unary_function<pointer, bool> { bound_predicate_t(const key_type& key, transform_type& transform, const key_compare& compare) : transform_m(transform), compare_m(compare), key_m(key) { } bool operator () (pointer x) const { return !compare_m(transform_m(*x), key_m); } private: transform_type transform_m; /* REVISIT (sparent) : want reference here? */ key_compare compare_m; key_type key_m; }; struct bound_predicate_upper_t : std::unary_function<pointer, bool> { bound_predicate_upper_t(const key_type& key, transform_type& transform, const key_compare& compare) : transform_m(transform), compare_m(compare), key_m(key) { } bool operator () (pointer x) const { return compare_m(key_m, transform_m(*x)); // key < *x is the same as *x > key } private: transform_type transform_m; /* REVISIT (sparent) : want reference here? */ key_compare compare_m; key_type key_m; }; #endif transform_type transform_m; key_compare compare_m; index_type index_m; }; /*************************************************************************************************/ template <class Key, class T, class Compare, class Transform> table_index<Key, T, Compare, Transform>::table_index( const transform_type& transform, const key_compare& compare) : transform_m(transform), compare_m(compare) { } /*************************************************************************************************/ template <class Key, class T, class Compare, class Transform> template <class InputIterator> table_index<Key, T, Compare, Transform>::table_index( InputIterator first, InputIterator last, const transform_type& transform, const key_compare& compare) : transform_m(transform), compare_m(compare) { insert(begin(), first, last); } /*************************************************************************************************/ template <class Key, class T, class Compare, class Transform> inline typename table_index<Key, T, Compare, Transform>::iterator table_index<Key, T, Compare, Transform>::begin() { return iterator(index_m.begin()); } /*************************************************************************************************/ template <class Key, class T, class Compare, class Transform> inline typename table_index<Key, T, Compare, Transform>::const_iterator table_index<Key, T, Compare, Transform>::begin() const { return const_iterator(index_m.begin()); } /*************************************************************************************************/ template <class Key, class T, class Compare, class Transform> inline typename table_index<Key, T, Compare, Transform>::iterator table_index<Key, T, Compare, Transform>::end() { return iterator(index_m.end()); } /*************************************************************************************************/ template <class Key, class T, class Compare, class Transform> inline typename table_index<Key, T, Compare, Transform>::const_iterator table_index<Key, T, Compare, Transform>::end() const { return iterator(index_m.end()); } /*************************************************************************************************/ template <class Key, class T, class Compare, class Transform> inline typename table_index<Key, T, Compare, Transform>::reverse_iterator table_index<Key, T, Compare, Transform>::rbegin() { return reverse_iterator(index_m.rbegin()); } /*************************************************************************************************/ template <class Key, class T, class Compare, class Transform> inline typename table_index<Key, T, Compare, Transform>::const_reverse_iterator table_index<Key, T, Compare, Transform>::rbegin() const { return const_reverse_iterator(index_m.rbegin()); } /*************************************************************************************************/ template <class Key, class T, class Compare, class Transform> inline typename table_index<Key, T, Compare, Transform>::reverse_iterator table_index<Key, T, Compare, Transform>::rend() { return reverse_iterator(index_m.rend()); } /*************************************************************************************************/ template <class Key, class T, class Compare, class Transform> inline typename table_index<Key, T, Compare, Transform>::const_reverse_iterator table_index<Key, T, Compare, Transform>::rend() const { return reverse_iterator(index_... [truncated message content] |