# # # add_file "specialized_lexical_cast.cc" # content [68bbce15ba5547d5fd3864106540e374b2dc7029] # # add_file "specialized_lexical_cast.hh" # content [ca247b704ab5bab202aa0ca87ac213371f1f7458] # # patch "Makefile.am" # from [782c145b15c9cb84fe237260d7190fb8d9138649] # to [21c268b576044d1a95fc266e5ac44a079a2bfd24] # # patch "roster.cc" # from [48f5189daf2fed1db746b3bd3b0de2e56dd8097e] # to [15adfd583f65d20b920933966f24fee2861406e0] # # patch "roster_delta.cc" # from [4d06fa6a95df2ff254ce9572a57bc0b0d1bb7e52] # to [23a29080ca95c48aaed1492f2bd9b00340e86d9a] # ============================================================ --- specialized_lexical_cast.cc 68bbce15ba5547d5fd3864106540e374b2dc7029 +++ specialized_lexical_cast.cc 68bbce15ba5547d5fd3864106540e374b2dc7029 @@ -0,0 +1,55 @@ +// Copyright (C) 2007 Timothy Brownawell +// +// This program is made available under the GNU GPL version 2.0 or +// greater. See the accompanying file COPYING for details. +// +// This program is distributed WITHOUT ANY WARRANTY; without even the +// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. + + +#include "specialized_lexical_cast.hh" + +template<> +std::string boost::lexical_cast(unsigned int const & _i) +{ + unsigned int i = _i; + if (!i) + return std::string("0"); + + unsigned int const maxlen = sizeof(unsigned int) * 3; + char buf[1+maxlen]; + buf[maxlen] = '\0'; + + unsigned int pos = maxlen; + + while (i && pos <= maxlen) + { + --pos; + buf[pos] = ('0' + (i%10)); + i /= 10; + } + return std::string(buf+pos); +} + +template<> +unsigned int boost::lexical_cast(std::string const & s) +{ + unsigned int out = 0; + std::string::const_iterator i; + for (i = s.begin(); i != s.end() && (unsigned int)(*i - '0') < 10; ++i) + { + out = out*10 + (*i - '0'); + } + if (i != s.end()) + throw boost::bad_lexical_cast(); + return out; +} + +// Local Variables: +// mode: C++ +// fill-column: 76 +// c-file-style: "gnu" +// indent-tabs-mode: nil +// End: +// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s: ============================================================ --- specialized_lexical_cast.hh ca247b704ab5bab202aa0ca87ac213371f1f7458 +++ specialized_lexical_cast.hh ca247b704ab5bab202aa0ca87ac213371f1f7458 @@ -0,0 +1,37 @@ +#ifndef __SPECIALIZED_LEXICAL_CAST_HH__ +#define __SPECIALIZED_LEXICAL_CAST_HH__ + + +// Copyright (C) 2007 Timothy Brownawell +// +// This program is made available under the GNU GPL version 2.0 or +// greater. See the accompanying file COPYING for details. +// +// This program is distributed WITHOUT ANY WARRANTY; without even the +// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. + + +#include + +// Generic lexical_cast can be a bit slow sometimes. If a particular +// version shows up in profiles, consider writing a specialization. + +namespace boost { + template<> + std::string lexical_cast(unsigned int const & _i); + + template<> + unsigned int lexical_cast(std::string const & s); + +} + +#endif + +// Local Variables: +// mode: C++ +// fill-column: 76 +// c-file-style: "gnu" +// indent-tabs-mode: nil +// End: +// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s: ============================================================ --- Makefile.am 782c145b15c9cb84fe237260d7190fb8d9138649 +++ Makefile.am 21c268b576044d1a95fc266e5ac44a079a2bfd24 @@ -83,6 +83,7 @@ MOST_SOURCES = \ package_revision.c package_revision.h \ package_full_revision.c package_full_revision.h \ option.cc option.hh options.cc options.hh options_list.hh \ + specialized_lexical_cast.cc specialized_lexical_cast.hh \ i18n.h parallel_iter.hh safe_map.hh pch.hh NETXX_SOURCES = \ ============================================================ --- roster.cc 48f5189daf2fed1db746b3bd3b0de2e56dd8097e +++ roster.cc 15adfd583f65d20b920933966f24fee2861406e0 @@ -23,14 +23,13 @@ #include "vocab.hh" #include "transforms.hh" #include "simplestring_xform.hh" +#include "specialized_lexical_cast.hh" #include "file_io.hh" #include "parallel_iter.hh" #include "restrictions.hh" #include "safe_map.hh" #include "ui.hh" -#include - using std::inserter; using std::make_pair; using std::map; ============================================================ --- roster_delta.cc 4d06fa6a95df2ff254ce9572a57bc0b0d1bb7e52 +++ roster_delta.cc 23a29080ca95c48aaed1492f2bd9b00340e86d9a @@ -13,7 +13,7 @@ #include #include -#include +#include "specialized_lexical_cast.hh" #include "safe_map.hh" #include "parallel_iter.hh"