OSDN Git Service

lexical2/fixed_string.hpp Add.
authormyun2 <myun2@nwhite.info>
Tue, 12 Jun 2012 08:28:59 +0000 (17:28 +0900)
committermyun2 <myun2@nwhite.info>
Tue, 12 Jun 2012 08:28:59 +0000 (17:28 +0900)
roast/include/roast/lexical2/fixed_string.hpp [new file with mode: 0644]
roast/include/roast/lexical2/lexical.hpp
roast/include/roast/lexical2/string.hpp

diff --git a/roast/include/roast/lexical2/fixed_string.hpp b/roast/include/roast/lexical2/fixed_string.hpp
new file mode 100644 (file)
index 0000000..6bbc89a
--- /dev/null
@@ -0,0 +1,95 @@
+//     Roast+ License
+/*
+       Fixed String (gcc workaround)
+*/
+#ifndef __SFJP_ROAST__lexical2__fixed_string_HPP__
+#define __SFJP_ROAST__lexical2__fixed_string_HPP__
+
+#include "roast/lexical2/fixed.hpp"
+
+#pragma warning(disable:4503)
+
+namespace roast
+{
+       namespace lexical
+       {
+               namespace rule
+               {
+                       ///////////////////////////////////////////////////////////////////
+
+                       template <unsigned int _StrLength=0>
+                       class fixed_string_ : public lengthable
+                       {
+                       protected:
+                               const char* m_str;
+                       public:
+                               static const int length = _StrLength;
+
+                               //////////////////////////////////////////////////
+                               //fixed_string_(const char* s) : m_str(s){}             for gcc workaround
+
+                               template <typename _It, typename _Param>
+                               bool analyze(_It& it, _Param& param)
+                               {
+                                       for(const char* p=m_str; *p!='\0'; p++, it++)
+                                       {
+                                               if ( *it != *p )
+                                                       return false;
+                                       }
+                                       return true;
+                               }
+
+                               //----
+                               
+                               template <typename _Strm, typename _Document>
+                               bool generate(_Strm& strm, _Document& doc) const
+                               {
+                                       strm << m_str;
+                                       return true;
+                               }
+                               
+                               const char* get() const { return m_str; }
+                               const char* c_str() const { return m_str; }
+                               operator const char*() const { return m_str; }
+                       };
+
+#define ROAST_LEXICAL_FIXSTR(CLS,S)    \
+                       class CLS : public ::roast::lexical::rule::fixed_string_<sizeof(S)-1>   \
+                       {       \
+                       public: \
+                               CLS(){ m_str = S; }     \
+                       };
+
+                       typedef fixed_string_<> fixed_string;
+                       
+                       struct c_str : fixed_string
+                       {
+                               c_str(){ m_str = 0/*NULL*/; }
+                               c_str(const char* s){ m_str = s; }
+                               
+                               void set(const char* s){ m_str = s; }
+                       };
+               }
+#define ROAST_LEXICAL_FIXED_STRING(CLS,S)              ROAST_LEXICAL_FIXSTR(CLS,S)
+#define ROAST_LEXICAL_FIXSTR2(NAME)                            ROAST_LEXICAL_FIXSTR(NAME,#NAME)
+#define ROAST_LEXICAL_FIXED_STRING2(NAME)              ROAST_LEXICAL_FIXSTR(NAME,#NAME)
+
+               using rule::fixed_string;
+               
+               ////////////////////////////////////////////////////////////////////////
+               
+               //      generate/analyze() Functions
+               
+               //      generate
+               template <typename _Strm, unsigned int _StrLength>
+               bool generate(_Strm& strm, const ::roast::lexical::rule::fixed_string_<_StrLength>& str)
+               {
+                       strm << str.get();
+                       return true;
+               }
+               
+               ////////////////////////////////////////////////////////////////////////
+       }
+}
+
+#endif//__SFJP_ROAST__lexical2__fixed_string_HPP__
index c6ad661..8a406e8 100644 (file)
@@ -11,6 +11,7 @@
 //     Types
 #include "roast/lexical2/empty_type.hpp"
 #include "roast/lexical2/fixed_numeric.hpp"
+#include "roast/lexical2/fixed_string.hpp"
 #include "roast/lexical2/characters.hpp"
 
 //     Utilities
index 1881abe..8c0b182 100644 (file)
@@ -4,6 +4,7 @@
 #ifndef __SFJP_ROAST__lexical2__string_HPP__
 #define __SFJP_ROAST__lexical2__string_HPP__
 
+#include "
 #pragma warning(disable:4503)
 
 namespace roast