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 mat... [truncated message content] |