|
From: Foster B. <fos...@us...> - 2005-04-18 21:15:55
|
Update of /cvsroot/adobe-source/sandbox/visual_refactor/adobe/future/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27679/adobe/future/source Added Files: assemblage.cpp iomanip.cpp iomanip_pdf.cpp iomanip_xml.cpp Log Message: SO SORRY for the large qty of emails -- creating a branch for Adobe Begin refactoring. --- NEW FILE: assemblage.cpp --- /* 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 <adobe/future/assemblage.hpp> #include <adobe/algorithm.hpp> /*************************************************************************************************/ namespace adobe { /*************************************************************************************************/ assemblage_t::assemblage_t() { } /*************************************************************************************************/ assemblage_t::~assemblage_t() { // disconnect all our connections adobe::for_each(connections_m, boost::bind(&connection_t::disconnect, _1)); /* REVISIT (sparent) : This should be adobe::for_each_reverse(destruct_signal_m, adobe::apply()); */ for (destruct_signal_t::iterator last(destruct_signal_m.end()), first(destruct_signal_m.begin()); first != last; ) { --last; (*last)(); } } /*************************************************************************************************/ assemblage_t::connection_t& assemblage_t::hold_connection(const connection_t& connection) { connections_m.push_front(connection); return *connections_m.begin(); } /*************************************************************************************************/ void assemblage_t::signal_destruction(const destruct_slot_t& slot) { destruct_signal_m.push_back(slot); } /*************************************************************************************************/ } // namespace adobe /*************************************************************************************************/ --- NEW FILE: iomanip.cpp --- /* 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) */ /*************************************************************************************************/ #ifdef ADOBE_SERIALIZATION /*************************************************************************************************/ #include <adobe/future/iomanip.hpp> /*************************************************************************************************/ namespace adobe { /*************************************************************************************************/ namespace implementation { /*************************************************************************************************/ bool type_string(const std::type_info& t) { return (t == typeid(std::string) || t == typeid(const std::string) || t == typeid(char*) || t == typeid(const char*)); } /*************************************************************************************************/ bool type_float(const std::type_info& t) { return (t == typeid(double) || t == typeid(const double) || t == typeid(float) || t == typeid(const float)); } /*************************************************************************************************/ bool type_integer(const std::type_info& t) { return (t == typeid(int) || t == typeid(const int) || t == typeid(unsigned int) || t == typeid(const unsigned int) || t == typeid(long) || t == typeid(const long) || t == typeid(unsigned long) || t == typeid(const unsigned long) || t == typeid(short) || t == typeid(const short) || t == typeid(unsigned short) || t == typeid(const unsigned short)); } /*************************************************************************************************/ bool type_bool(const std::type_info& t) { return (t == typeid(bool) || t == typeid(const bool)); } /*************************************************************************************************/ bool type_name(const std::type_info& t) { return (t == typeid(name_t)); } /*************************************************************************************************/ } // namespace implementation /*************************************************************************************************/ const name_t bag_name_g("bag"); const name_t seq_name_g("seq"); const name_t alt_name_g("alt"); const name_t atom_name_g("atom"); /*************************************************************************************************/ int format_base_idx() { static const int idx(std::ios_base::xalloc()); return idx; } format_base* get_formatter(std::ostream& os) { return static_cast<format_base*>(os.pword(format_base_idx())); } /*************************************************************************************************/ // format_manip_boilerplate is a standard iostream manipulator boilerplate, that will get the adobe // iomanip format object currently installed and call the relative function in that object. #define glue(x) x #define format_manip_boilerplate(x) \ format_base::stream_type& glue(x)(format_base::stream_type& os) \ { \ format_base* format(get_formatter(os)); \ if (format) format->glue(x)(os); \ return os; \ } /*************************************************************************************************/ format_manip_boilerplate(begin_format) format_manip_boilerplate(end_format) format_manip_boilerplate(end_bag) format_manip_boilerplate(begin_sequence) format_manip_boilerplate(end_sequence) format_manip_boilerplate(begin_alternate) format_manip_boilerplate(end_alternate) format_manip_boilerplate(end_atom) /*************************************************************************************************/ template <> std::ostream& fmt(std::ostream& os, const bool& t) { // In the case of a bool we don't necessarily want boolalpha (or NOT boolalpha). // For the time being we'll just use true and false but we need to hook a format // specific result for a true or false boolean value. os << adobe::begin_atom(typeid(const bool)) << (t ? "true" : "false") << adobe::end_atom; return os; } /*************************************************************************************************/ template <> std::ostream& fmt(std::ostream& os, const float& t) { // In the case of a floating-point number we want to // reduce it to an integer if there is no decimal value. long int_version(static_cast<long>(t)); if (int_version == t) { os << adobe::format(int_version); } else { os << adobe::begin_atom(typeid(const float)) << t << adobe::end_atom; } return os; } /*************************************************************************************************/ template <> std::ostream& fmt(std::ostream& os, const double& t) { // In the case of a floating-point number we want to // reduce it to an integer if there is no decimal value. long int_version(static_cast<long>(t)); if (int_version == t) { os << adobe::format(int_version); } else { os << adobe::begin_atom(typeid(const double)) << t << adobe::end_atom; } return os; } /*************************************************************************************************/ template <> std::ostream& fmt(std::ostream& os, const adobe::value_t& t) { // The pain about an adobe::value_t is that you need to // figure out all the different types that are in it // that you want to override (for example, double and bool). if (implementation::type_float(t.type())) { os << adobe::format(t.get<double>()); } else if (implementation::type_bool(t.type())) { os << adobe::format(t.get<bool>()); } else { os << adobe::begin_atom(t.type()) << t << adobe::end_atom; } return os; } /*************************************************************************************************/ } // namespace adobe /*************************************************************************************************/ #endif /*************************************************************************************************/ --- NEW FILE: iomanip_pdf.cpp --- /* 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) */ /*************************************************************************************************/ #ifdef ADOBE_SERIALIZATION /*************************************************************************************************/ #include <adobe/future/iomanip_pdf.hpp> /*************************************************************************************************/ namespace adobe { /*************************************************************************************************/ void pdf_format::begin_format(stream_type& os) { push_stack(os, new pdf_format_element(name_t("pdf"))); } /*************************************************************************************************/ void pdf_format::begin_bag(stream_type& os, const std::string& ident) { push_stack(os, new pdf_format_element(bag_name_g, ident)); } /*************************************************************************************************/ void pdf_format::begin_sequence(stream_type& os) { push_stack(os, new pdf_format_element(seq_name_g)); } /*************************************************************************************************/ void pdf_format::begin_atom(stream_type& os, const std::type_info& typeinfo) { push_stack(os, new pdf_format_element(atom_name_g, typeinfo)); } /*************************************************************************************************/ void pdf_format::stack_event(stream_type& os, bool is_push) { pdf_format_element* top(my_stack_top()); name_t self(top ? top->tag() : "ERROR"); name_t parent(stack_depth() >= 2 ? stack_n(1)->tag() : ""); name_t grandparent(stack_depth() >= 3 ? stack_n(2)->tag() : ""); if (is_push) { if (self == static_name_t("pdf")) { os << "% pdf output\n"; } else if (self == bag_name_g) { if (parent != atom_name_g) os << indents(depth()); os << "<<\n"; up(); } else if (self == seq_name_g) { if (parent != bag_name_g) { if (parent != atom_name_g) os << indents(depth()); os << "[ "; } } else if (self == atom_name_g) { handle_atom(os, is_push); } } else { if (self == static_name_t("pdf")) { os << "% end pdf output\n"; } else if (self == bag_name_g) { down(); os << indents(depth()) << ">>"; if (parent != atom_name_g) { os << "\n"; } } else if (self == seq_name_g) { if (parent == bag_name_g) { os << "\n"; } else { os << "]"; if (parent != atom_name_g) { os << "\n"; } } } else if (self == atom_name_g) { handle_atom(os, is_push); } } } /*************************************************************************************************/ void pdf_format::handle_atom(stream_type& os, bool is_push) { pdf_format_element* top(my_stack_top()); name_t self(top ? top->tag() : "ERROR"); name_t parent(stack_depth() >= 2 ? stack_n(1)->tag() : ""); name_t grandparent(stack_depth() >= 3 ? stack_n(2)->tag() : ""); if (!top) return; const std::type_info& top_type(top->type()); if (is_push) { if (implementation::type_string(top_type)) { if (parent != seq_name_g) os << indents(depth()); if (parent == seq_name_g && grandparent == bag_name_g && my_stack_n(1)->num_out_m == 0) os << indents(depth()) << "/"; else os << "("; } else if (implementation::type_name(top_type)) { if (parent == seq_name_g && grandparent == bag_name_g && my_stack_n(1)->num_out_m == 0) os << indents(depth()); os << "/"; } else if (implementation::type_float(top_type)) { // For PDF, we want to output floating-point values in decimal-based // fixed-point notation (PDF doesn't support any other format) with // a very high precision for accceptable roundtrip values. os.setf(std::ios_base::dec, std::ios_base::basefield); os.setf(std::ios_base::fixed, std::ios_base::floatfield); os.precision(15); } // other data type format stuff goes here } else { if (parent == seq_name_g && grandparent == bag_name_g && my_stack_n(1)->num_out_m == 0) ; else { if (implementation::type_string(top_type)) { os << ")"; } else if (implementation::type_float(top_type)) { // For PDF, we want to output floating-point values in decimal-based // fixed-point notation (PDF doesn't support any other format) with // a very high precision for accceptable roundtrip values. os.setf(std::ios_base::dec, std::ios_base::basefield); os.setf(std::ios_base::fixed, std::ios_base::floatfield); os.precision(15); } // other data type format stuff goes here } if (parent == seq_name_g) { my_stack_n(1)->num_out_m++; os << " "; } else if (implementation::type_name(top_type)) os << " "; else os << "\n"; } } /*************************************************************************************************/ pdf_format_element* pdf_format::my_stack_top() { return my_stack_n(0); } /*************************************************************************************************/ pdf_format_element* pdf_format::my_stack_n(std::size_t n) { format_base::stack_element_type element(stack_n(n)); return dynamic_cast<pdf_format_element*>(element); } /*************************************************************************************************/ std::ostream& begin_pdf(std::ostream& os) { replace_pword<format_base, pdf_format>(os, format_base_idx()); os << begin_format; return os; } /*************************************************************************************************/ std::ostream& end_pdf(std::ostream& os) { os << end_format; return os; } /*************************************************************************************************/ } // namespace adobe /*************************************************************************************************/ #endif /*************************************************************************************************/ --- NEW FILE: iomanip_xml.cpp --- /* 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) */ /*************************************************************************************************/ #ifdef ADOBE_SERIALIZATION /*************************************************************************************************/ #include <adobe/future/source/iomanip_xml.hpp> /*************************************************************************************************/ namespace adobe { /*************************************************************************************************/ void xml_format::begin_format(stream_type& os) { push_stack(os, new xml_format_element(name_t("xml"))); } /*************************************************************************************************/ void xml_format::begin_bag(stream_type& os, const std::string& ident) { push_stack(os, new xml_format_element(bag_name_g, ident)); } /*************************************************************************************************/ void xml_format::begin_sequence(stream_type& os) { push_stack(os, new xml_format_element(seq_name_g)); } /*************************************************************************************************/ void xml_format::begin_atom(stream_type& os, const std::type_info& typeinfo) { push_stack(os, new xml_format_element(atom_name_g, typeinfo)); } /*************************************************************************************************/ void xml_format::stack_event(stream_type& os, bool is_push) { xml_format_element* top(my_stack_top()); name_t self(top ? top->tag() : "ERROR"); name_t parent(stack_depth() >= 2 ? stack_n(1)->tag() : ""); name_t grandparent(stack_depth() >= 3 ? stack_n(2)->tag() : ""); if (is_push) { if (self == static_name_t("xml")) { os << indents(depth()) << "<xml>\n"; } else if (self == bag_name_g) { os << "<dict>\n"; up(); } else if (self == seq_name_g) { if (parent != bag_name_g) { os << "<array>\n"; up(); } } else if (self == atom_name_g) { handle_atom(os, is_push); } } else { if (self == static_name_t("xml")) { os << indents(depth()) << "</xml>\n"; } else if (self == bag_name_g) { down(); os << indents(depth()) << "</dict>"; if (parent != atom_name_g) os << "\n"; } else if (self == seq_name_g) { if (parent != bag_name_g) { down(); os << indents(depth()) << "</array>"; if (parent != atom_name_g) os << "\n"; } } else if (self == atom_name_g) { handle_atom(os, is_push); } } } /*************************************************************************************************/ void xml_format::handle_atom(stream_type& os, bool is_push) { xml_format_element* top(my_stack_top()); name_t self(top ? top->tag() : "ERROR"); name_t parent(stack_depth() >= 2 ? stack_n(1)->tag() : ""); name_t grandparent(stack_depth() >= 3 ? stack_n(2)->tag() : ""); if (!top) return; const std::type_info& self_type(top->type()); if (is_push) { if (self != seq_name_g) os << indents(depth()); if (parent == seq_name_g && grandparent == bag_name_g && my_stack_n(1)->num_out_m == 0) os << "<key>"; else { if (implementation::type_string(self_type)) os << "<string>"; else if (implementation::type_integer(self_type)) os << "<integer>"; else if (implementation::type_float(self_type)) os << "<double>"; else if (implementation::type_name(self_type)) os << "<ident>"; } } else { if (parent == seq_name_g && grandparent == bag_name_g && my_stack_n(1)->num_out_m == 0) os << "</key>"; else { if (implementation::type_string(self_type)) os << "</string>"; else if (implementation::type_integer(self_type)) os << "</integer>"; else if (implementation::type_float(self_type)) os << "</double>"; else if (implementation::type_name(self_type)) os << "</ident>"; } if (parent == seq_name_g) my_stack_n(1)->num_out_m++; if (self != seq_name_g) os << "\n"; } } /*************************************************************************************************/ xml_format_element* xml_format::my_stack_top() { return my_stack_n(0); } /*************************************************************************************************/ xml_format_element* xml_format::my_stack_n(std::size_t n) { format_base::stack_element_type element(stack_n(n)); return dynamic_cast<xml_format_element*>(element); } /*************************************************************************************************/ std::ostream& begin_xml(std::ostream& os) { replace_pword<format_base, xml_format>(os, format_base_idx()); os << begin_format; return os; } /*************************************************************************************************/ std::ostream& end_xml(std::ostream& os) { os << end_format; return os; } /*************************************************************************************************/ } // namespace adobe /*************************************************************************************************/ #endif /*************************************************************************************************/ |