Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66445 - sandbox/chrono/boost/static_string
From: vicente.botet_at_[hidden]
Date: 2010-11-07 15:36:48


Author: viboes
Date: 2010-11-07 15:36:45 EST (Sun, 07 Nov 2010)
New Revision: 66445
URL: http://svn.boost.org/trac/boost/changeset/66445

Log:
Chrono: Add static_string to support static parsing for chrono_io

Added:
   sandbox/chrono/boost/static_string/
   sandbox/chrono/boost/static_string/basic_str.hpp (contents, props changed)
   sandbox/chrono/boost/static_string/c_str.hpp (contents, props changed)
   sandbox/chrono/boost/static_string/insert.hpp (contents, props changed)
   sandbox/chrono/boost/static_string/match.hpp (contents, props changed)
   sandbox/chrono/boost/static_string/ptree.hpp (contents, props changed)
   sandbox/chrono/boost/static_string/static_string.hpp (contents, props changed)
   sandbox/chrono/boost/static_string/value_type.hpp (contents, props changed)

Added: sandbox/chrono/boost/static_string/basic_str.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/static_string/basic_str.hpp 2010-11-07 15:36:45 EST (Sun, 07 Nov 2010)
@@ -0,0 +1,47 @@
+// basic_str.hpp --------------------------------------------------------------//
+
+// Copyright 2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+
+#ifndef BOOST_STATIC_STRING_BASIC_STR_HPP
+#define BOOST_STATIC_STRING_BASIC_STR_HPP
+
+#include <boost/mpl/vector/vector10_c.hpp>
+
+namespace boost {
+namespace static_string {
+
+struct nil {};
+
+template <char H1>
+struct str_1 {
+ typedef mpl::vector1_c<char, H1> type;
+};
+
+template <char H1, char H2>
+struct str_2 {
+ typedef mpl::vector2_c<char, H1, H2> type;
+};
+
+template <char H1, char H2, char H3>
+struct str_3 {
+ typedef mpl::vector3_c<char, H1, H2, H3> type;
+};
+
+template <char H1, char H2, char H3, char H4>
+struct str_4 {
+ typedef mpl::vector4_c<char, H1, H2, H3, H4> type;
+};
+
+template <char H1, char H2, char H3, char H4, char H5>
+struct str_5 {
+ typedef mpl::vector5_c<char, H1, H2, H3, H4, H5> type;
+};
+
+} // namespace static_string
+} // namespace boost
+
+#endif // BOOST_STATIC_STRING_BASIC_STR_HPP

Added: sandbox/chrono/boost/static_string/c_str.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/static_string/c_str.hpp 2010-11-07 15:36:45 EST (Sun, 07 Nov 2010)
@@ -0,0 +1,83 @@
+// c_str.hpp --------------------------------------------------------------//
+
+// Copyright 2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+
+#ifndef BOOST_STATIC_STRING_C_STR_HPP
+#define BOOST_STATIC_STRING_C_STR_HPP
+
+#include <boost/static_string/value_type.hpp>
+#include <boost/mpl/next.hpp>
+#include <boost/mpl/deref.hpp>
+#include <boost/mpl/integral_c.hpp>
+#include <boost/mpl/end.hpp>
+#include <boost/mpl/begin.hpp>
+#include <boost/preprocessor/cat.hpp>
+#include <boost/preprocessor/inc.hpp>
+
+#if !defined(BOOST_STATIC_STRING_LIMIT_C_STR_SIZE)
+# define BOOST_STATIC_STRING_LIMIT_C_STR_SIZE 32
+#endif
+
+namespace boost {
+namespace static_string {
+namespace detail
+{
+ template<typename It, typename End>
+ struct next_unless
+ : mpl::next<It>
+ {};
+
+ template<typename End>
+ struct next_unless<End, End>
+ {
+ typedef End type;
+ };
+
+ template<typename T, typename It, typename End>
+ struct deref_unless
+ : mpl::deref<It>
+ {};
+
+ template<typename T, typename End>
+ struct deref_unless<T, End, End>
+ {
+ typedef mpl::integral_c<T, 0> type;
+ };
+}
+
+template<typename Sequence>
+struct c_str
+{
+// typedef typename value_type<Sequence>::type value_type;
+ typedef typename mpl::end<Sequence>::type iend;
+ typedef typename mpl::begin<Sequence>::type i0;
+ #define M0(z, n, data) \
+ typedef \
+ typename static_string::detail::next_unless<BOOST_PP_CAT(i, n), iend>::type \
+ BOOST_PP_CAT(i, BOOST_PP_INC(n));
+ BOOST_PP_REPEAT(BOOST_MPL_LIMIT_STRING_SIZE, M0, ~)
+ #undef M0
+
+ typedef c_str type;
+ static typename value_type<Sequence>::type const value[BOOST_STATIC_STRING_LIMIT_C_STR_SIZE+1];
+};
+
+template<typename Sequence>
+typename value_type<Sequence>::type const c_str<Sequence>::value[BOOST_STATIC_STRING_LIMIT_C_STR_SIZE+1] =
+{
+ #define M0(z, n, data) \
+ static_string::detail::deref_unless<typename value_type<Sequence>::type, BOOST_PP_CAT(i, n), iend>::type::value,
+ BOOST_PP_REPEAT(BOOST_STATIC_STRING_LIMIT_C_STR_SIZE, M0, ~)
+ #undef M0
+ mpl::integral_c<typename value_type<Sequence>::type, 0>::type::value
+// '\0'
+};
+
+} // namespace static_string
+} // namespace boost
+
+#endif // BOOST_STATIC_STRING_C_STR_HPP

Added: sandbox/chrono/boost/static_string/insert.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/static_string/insert.hpp 2010-11-07 15:36:45 EST (Sun, 07 Nov 2010)
@@ -0,0 +1,210 @@
+// insert.hpp --------------------------------------------------------------//
+
+// Copyright 2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+
+#ifndef BOOST_STATIC_STRING_INSERT_HPP
+#define BOOST_STATIC_STRING_INSERT_HPP
+
+#include <boost/static_string/basic_str.hpp>
+#include <boost/static_string/ptree.hpp>
+#include <boost/mpl/pair.hpp>
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/empty.hpp>
+#include <boost/mpl/front.hpp>
+#include <boost/mpl/pop_front.hpp>
+
+namespace boost {
+namespace static_string {
+
+template <typename M, typename X>
+struct insert;
+
+namespace detail {
+
+template <typename Seq, typename I, bool empty=false>
+struct insert_nil_false
+{
+ typedef
+ basic_ptree<
+ typename mpl::front<Seq>::type, mpl::int_<-1>,
+ typename insert<
+ nil,
+ mpl::pair<typename mpl::pop_front<Seq>::type,I>
+ >::type
+ > type;
+};
+
+template <typename Seq, typename I>
+struct insert_nil_false<Seq, I, true>
+{
+ typedef basic_ptree<typename mpl::front<Seq>::type, I> type;
+};
+
+template <typename Seq, typename I, bool empty=false>
+struct insert_nil
+{
+ typedef typename insert_nil_false<Seq, I,
+ mpl::empty<typename mpl::pop_front<Seq>::type>::value
+ >::type type;
+};
+
+template <typename Seq, typename I>
+struct insert_nil<Seq, I, true >
+{
+ typedef nil type;
+};
+
+template <typename PTree, typename Seq, typename I, bool Equals, bool SeqEmpty>
+struct insert_basic_ptree_false;
+
+template <typename Key, typename I, typename F, typename Seq, typename I2>
+struct insert_basic_ptree_false<basic_ptree<Key, I, F>, Seq, I2, true, true>
+{
+ // replace index
+ typedef basic_ptree<Key, I2, F> type;
+};
+
+template <typename Key, typename I, typename F, typename Seq, typename I2>
+struct insert_basic_ptree_false<basic_ptree<Key, I, F>, Seq, I2, true, false>
+{
+ // insert on forest
+ typedef basic_ptree<Key, I,
+ typename insert<F, mpl::pair<typename mpl::pop_front<Seq>::type,
+ I2>
+ >::type
+ > type;
+};
+template <typename Key, typename I, typename F, typename Seq, typename I2, bool SeqEmpty>
+struct insert_basic_ptree_false<basic_ptree<Key, I, F>, Seq, I2, false, SeqEmpty>
+{
+ // make a forest
+ typedef forest<
+ basic_ptree<Key, I, F>,
+ typename insert<nil, mpl::pair<Seq, I2> >::type
+ > type;
+
+};
+template <typename PTree, typename Seq, typename I, bool SeqEmpty>
+struct insert_basic_ptree;
+
+template <typename Key, typename I, typename F, typename Seq, typename I2>
+struct insert_basic_ptree<basic_ptree<Key, I, F>, Seq, I2, false >
+{
+ typedef typename insert_basic_ptree_false<basic_ptree<Key, I, F>, Seq, I2,
+ is_same<typename mpl::front<Seq>::type, Key>::value,
+ mpl::empty<typename mpl::pop_front<Seq>::type>::value
+ >::type type;
+};
+
+template <typename BasicPTree, typename Seq, typename I>
+struct insert_basic_ptree<BasicPTree, Seq, I, true >
+{
+ typedef nil type;
+};
+
+template <typename Forest, typename Seq, typename I, bool Equal>
+struct insert_forest_false;
+
+template <typename Key, typename I, typename F, typename F2, typename Seq, typename I2>
+struct insert_forest_false<forest<basic_ptree<Key, I, F>, F2>, Seq, I2, true >
+{
+ typedef forest<
+ basic_ptree<Key, I,
+ typename insert<F, mpl::pair<typename mpl::pop_front<Seq>::type, I2> >::type
+ >,
+ F2
+ > type;
+};
+
+template <typename Key, typename I, typename F, typename F2, typename Seq, typename I2>
+struct insert_forest_false<forest<basic_ptree<Key, I, F>, F2>, Seq, I2, false >
+{
+ typedef forest<
+ basic_ptree<Key, I, F>,
+ typename insert<F2, mpl::pair<Seq, I2> >::type
+ > type;
+};
+
+
+template <typename Forest, typename Seq, typename I, bool SeqEmpty=true>
+struct insert_forest
+{
+ typedef Forest type;
+};
+
+template <typename Key, typename I, typename F, typename F2, typename Seq, typename I2>
+struct insert_forest<forest<basic_ptree<Key, I, F>, F2>, Seq, I2, false >
+{
+ typedef typename insert_forest_false<forest<basic_ptree<Key, I, F>, F2>, Seq, I,
+ is_same<typename mpl::front<Seq>::type, Key >::value
+ >::type type;
+};
+
+}
+
+template <typename Seq, typename I>
+struct insert<nil, mpl::pair<Seq, I > >
+{
+ typedef typename static_string::detail::insert_nil<Seq, I,
+ mpl::empty<Seq>::value
+ >::type type;
+};
+
+// basic_ptree
+
+template <typename Key, typename I, typename F, typename Seq, typename I2>
+struct insert<basic_ptree<Key, I, F>, mpl::pair<Seq, I2> >
+{
+ typedef typename static_string::detail::insert_basic_ptree<
+ basic_ptree<Key, I, F>, Seq, I2,
+ mpl::empty<Seq>::value
+ >::type type;
+};
+
+
+// forest
+
+template <typename Seq, typename I>
+struct insert<forest<nil,nil>, mpl::pair<Seq, I> >
+{
+ typedef forest<typename insert<nil, mpl::pair<Seq, I> >::type> type;
+};
+
+template <typename Key, typename I, typename F, typename F2, typename Seq, typename I2>
+struct insert<forest<basic_ptree<Key, I, F>, F2>, mpl::pair<Seq, I2> >
+{
+#if 0
+ typedef typename static_string::detail::insert_forest<
+ forest<basic_ptree<Key, I, F>, F2>, Seq, I2
+ mpl::empty<Seq>
+#else
+ typedef typename mpl::if_<
+ mpl::empty<Seq>,
+ nil,
+ typename mpl::if_<
+ is_same<typename mpl::front<Seq>::type, Key >,
+ forest<
+ basic_ptree<Key, I,
+ typename insert<F, mpl::pair<typename mpl::pop_front<Seq>::type, I2> >::type
+ >,
+ F2
+ >,
+ forest<
+ basic_ptree<Key, I, F>,
+ typename insert<F2, mpl::pair<Seq, I2> >::type
+ >
+ >::type
+#endif
+ >::type type;
+};
+
+
+} // namespace static_string
+} // namespace boost
+
+#endif // BOOST_STATIC_STRING_HPP

Added: sandbox/chrono/boost/static_string/match.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/static_string/match.hpp 2010-11-07 15:36:45 EST (Sun, 07 Nov 2010)
@@ -0,0 +1,110 @@
+// match.hpp --------------------------------------------------------------//
+
+// Copyright 2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+
+#ifndef BOOST_STATIC_STRING_MATCH_HPP
+#define BOOST_STATIC_STRING_MATCH_HPP
+
+#include <boost/static_string/static_string/basic_str.hpp>
+#include <boost/static_string/static_string/ptree.hpp>
+#include <boost/mpl/integral_c.hpp>
+
+#include <ios>
+
+namespace boost {
+namespace static_string {
+
+//template <typename Forest, typename InputIterator>
+//int
+//match(Forest f, InputIterator& b, InputIterator e, std::ios_base::iostate& err);
+
+namespace static_string_detail {
+
+template <typename InputIterator>
+int
+match(nil, InputIterator&, InputIterator)
+{
+ return -1;
+}
+
+template <typename CharT, CharT Head, typename Index, typename Forest, typename InputIterator>
+int
+match(basic_ptree<mpl::integral_c<CharT, Head>, Index, Forest>, InputIterator& i, InputIterator e)
+{
+ // an empty range doesn't match a tree
+ if (i == e) return -1;
+ // if the heads are the same
+ if (*i == Head) {
+ // consume a character
+ i++;
+ // if we reached the end of the range return the Index of sub-tree
+ if (i == e) return Index::value;
+ // if the next charecter is a white space
+ if (*i == ' ') {
+ // consume it and return the Index of the sub-tree
+ i++;
+ return Index::value;
+ } else {
+ int res=match(Forest(), i, e);
+ if (res==-1) return -2;
+ else {
+ // otherwise return the match
+ return res;
+ }
+ }
+ } else {
+ // otherwise, return no match and no character consumed
+ return -1;
+ }
+}
+
+
+// int match(T, InputIterator& i, InputIterator e);
+// the result either identifies the match, or is
+// -1 meaning no match and no character were consumed
+// -2 meaning no match and some character were consumed
+
+template <typename Tree, typename Forest, typename InputIterator>
+int
+match(forest<Tree, Forest>, InputIterator& i, InputIterator e)
+{
+ // an empty range doesn't match a forest
+ if (i == e) return -1;
+ int res=match(Tree(), i, e);
+ // if the range matches the first tree return the match
+ if (res>=0) return res;
+ // if the range doesn't matches the first tree and
+ // there were no consumer characters try with the other trees
+ if (res==-1) return match(Forest(), i, e);
+ else {
+ // otherwise, i.e. there were some character consumed return this
+ return res;
+ }
+}
+
+
+
+
+} // namespace static_string_detail
+
+template <typename Forest, typename InputIterator>
+int
+match(Forest f, InputIterator& b, InputIterator e, std::ios_base::iostate& err)
+{
+
+ int res=static_string_detail::match(f, b, e);
+ if (b == e)
+ err |= std::ios_base::eofbit;
+ if (res>=0) return res;
+ err |= std::ios_base::failbit;
+ return -1;
+}
+
+} // namespace static_string
+} // namespace boost
+
+#endif // BOOST_STATIC_STRING_MATCH_HPP

Added: sandbox/chrono/boost/static_string/ptree.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/static_string/ptree.hpp 2010-11-07 15:36:45 EST (Sun, 07 Nov 2010)
@@ -0,0 +1,44 @@
+// ptree.hpp --------------------------------------------------------------//
+
+// Copyright 2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+
+#ifndef BOOST_STATIC_STRING_PTREE_HPP
+#define BOOST_STATIC_STRING_PTREE_HPP
+#include <boost/mpl/int.hpp>
+
+#include <ios>
+
+namespace boost {
+namespace static_string {
+
+
+template <typename Tree=nil, typename Forest=nil>
+struct forest;
+
+//template <typename K, int V>
+//struct pair {
+// typedef K key;
+// static const int value = V ;
+//};
+
+template <typename Key, typename Index=mpl::int_<-1>, typename Forest=nil >
+struct basic_ptree {
+ typedef Key key_type;
+ typedef Index index_type;
+ typedef Forest childs;
+};
+
+template <typename Tree, typename Forest>
+struct forest {
+ typedef Tree head;
+ typedef Forest tail;
+};
+
+} // namespace static_string
+} // namespace boost
+
+#endif // BOOST_STATIC_STRING_PTREE_HPP

Added: sandbox/chrono/boost/static_string/static_string.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/static_string/static_string.hpp 2010-11-07 15:36:45 EST (Sun, 07 Nov 2010)
@@ -0,0 +1,19 @@
+// static_string.hpp --------------------------------------------------------------//
+
+// Copyright 2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+
+#ifndef BOOST_STATIC_STRING_HPP
+#define BOOST_STATIC_STRING_HPP
+
+#include <boost/static_string/basic_str.hpp>
+#include <boost/static_string/ptree.hpp>
+#include <boost/static_string/match.hpp>
+#include <boost/static_string/insert.hpp>
+#include <boost/static_string/value_type.hpp>
+#include <boost/static_string/c_str.hpp>
+
+#endif // BOOST_STATIC_STRING_HPP

Added: sandbox/chrono/boost/static_string/value_type.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/static_string/value_type.hpp 2010-11-07 15:36:45 EST (Sun, 07 Nov 2010)
@@ -0,0 +1,23 @@
+// value_type.hpp --------------------------------------------------------------//
+
+// Copyright 2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+
+#ifndef BOOST_STATIC_STRING_VALUE_TYPE_HPP
+#define BOOST_STATIC_STRING_VALUE_TYPE_HPP
+
+namespace boost {
+namespace static_string {
+
+template<typename Sequence>
+struct value_type {
+ typedef typename Sequence::value_type type;
+};
+
+} // namespace static_string
+} // namespace boost
+
+#endif // BOOST_STATIC_STRING_VALUE_TYPE_HPP


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk