OSDN Git Service

rule/num_string.hpp: 新実装してみた
authorMyun2 <myun2@nwhite.info>
Thu, 24 May 2012 16:35:14 +0000 (01:35 +0900)
committerMyun2 <myun2@nwhite.info>
Thu, 24 May 2012 16:35:14 +0000 (01:35 +0900)
roast/include/roast/lexical/rule/num_string.hpp

index f3bf466..768c5e6 100644 (file)
@@ -29,19 +29,25 @@ namespace roast
                        
                        ////
                        
-                       template <typename T>
+                       template <typename T = int>
                        struct num_string_
                        {
                        private:
                                
-                               template <typename _Strm, typename _Document, typename U>
-                               bool generate_impl(_Strm& strm, _Document& doc) const
+                               template <typename _Strm, typename _Document>
+                               bool _generate_signed(_Strm& strm, _Document& doc) const
                                {
+                                       char work[12];
+                                       sprintf(work, "%d", value);
+                                       strm << work;
                                        return true;
                                }
-                               template <typename _Strm, typename _Document, typename U>
-                               bool generate_impl(_Strm& strm, _Document& doc) const
+                               template <typename _Strm, typename _Document>
+                               bool _generate_unsigned(_Strm& strm, _Document& doc) const
                                {
+                                       char work[11];
+                                       sprintf(work, "%d", value);
+                                       strm << work;
                                        return true;
                                }
                                
@@ -60,12 +66,15 @@ namespace roast
                                template <typename _Strm, typename _Document>
                                bool generate(_Strm& strm, _Document& doc) const
                                {
-                                       strm << m_str;
-                                       return true;
+                                       if ( type_traits::is_signed<T>::value )
+                                               return _generate_signed(strm, doc);
+                                       else
+                                               return _generate_unsigned(strm, doc);
                                }
                                
                                operator const T(){ return value; }
                        };
+                       typedef num_string_<> num_string;
 
                        ///////////////////////////////////////////////////////////////////
                        
@@ -110,15 +119,16 @@ namespace roast
                        ///////////////////////////////////////////////////////////////////
                        
                        template <int _Integral, int _Decimal, int _DecimalZeroCount=0>
-                       class float_string : public seq<
-                               num_string<_Integral>,
+                       class fixed_float_string : public seq<
+                               fixed_num_string<_Integral>,
                                chars::dot,
                                fixed_repeat<unichar<'0'>, _DecimalZeroCount>,
-                               num_string<_Decimal>
+                               fixed_num_string<_Decimal>
                        > {};
                        
                        ///////////////////////////////////////////////////////////////////
                }
+               using namespace rule;
        }
 }