OSDN Git Service

lexical2/variable.hpp: とりあえず、追加しておく
authormyun2 <myun2@nwhite.info>
Tue, 12 Jun 2012 08:27:00 +0000 (17:27 +0900)
committermyun2 <myun2@nwhite.info>
Tue, 12 Jun 2012 08:27:00 +0000 (17:27 +0900)
roast/include/roast/lexical2/variable.hpp [new file with mode: 0644]

diff --git a/roast/include/roast/lexical2/variable.hpp b/roast/include/roast/lexical2/variable.hpp
new file mode 100644 (file)
index 0000000..e41530b
--- /dev/null
@@ -0,0 +1,90 @@
+//     Roast+ License
+/*
+*/
+#ifndef __SFJP_ROAST__lexical2__variable_HPP__
+#define __SFJP_ROAST__lexical2__variable_HPP__
+
+#include "roast/memory/sized_ptr.hpp"
+
+namespace roast
+{
+       namespace lexical
+       {
+               ////////////////////////////////////////////////////////////////////
+               
+               template <typename T>
+               class variable
+               {
+               public:
+                       T data;
+               
+                       /////////////////
+                       
+                       /*
+                       template <typename InputIterator, typename _Param>
+                       bool parse(InputIterator& it, const _Param& param) const
+                       {
+                               //memcmp
+                               
+                               bool ret = (*it == data);
+                               if ( ret )
+                                       it++;
+                               return ret;
+                       }*/
+
+                       //----
+                       
+                       template <typename OutputStream, typename _Document>
+                       void generate(OutputStream& os, const _Document& doc) const
+                       {
+                               os << data;
+                       }
+               };
+
+               ////////////////////////////////////////////////////////////////////
+               
+               template <typename T>
+               class fixed_ptr
+               {
+               private:
+                       const unsigned int length;
+                       const T* data;
+               public:
+                       fixed_ptr(const T* ptr, unsigned int size=0) : data(ptr), length(size){}
+                       
+                       /////////////////
+                       
+                       template <typename InputIterator, typename _Param>
+                       bool parse(InputIterator& it, const _Param& param) const
+                       {
+                               const T* p = data;
+                               for(unsigned int i=length; i!=0; i--, p++, it++)
+                               {
+                                       if ( *it != data )
+                                               return false;
+                               }
+                               return true;
+                       }
+
+                       //----
+                       
+                       template <typename OutputStream, typename _Document>
+                       void generate(OutputStream& os, const _Document& doc) const
+                       {
+                               os.write(data, length);
+                               
+                               /*
+                               const T* p = data;
+                               for(unsigned int i=length; i!=0; i--, p++)
+                               {
+                                       os << *p;
+                               }
+                               */
+                       }
+               };
+
+               ////////////////////////////////////////////////////////////////////
+       }
+}
+
+#endif//__SFJP_ROAST__lexical2__variable_HPP__