IWORKXMLContextBase.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /*
00003  * This file is part of the libetonyek project.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  */
00009 
00010 #ifndef IWORKXMLCONTEXTBASE_H_INCLUDED
00011 #define IWORKXMLCONTEXTBASE_H_INCLUDED
00012 
00013 #include <boost/enable_shared_from_this.hpp>
00014 #include <boost/optional.hpp>
00015 
00016 #include "IWORKXMLContext.h"
00017 #include "IWORKTypes_fwd.h"
00018 
00019 namespace libetonyek
00020 {
00021 
00022 class IWORKXMLParserState;
00023 
00024 class IWORKCollector;
00025 
00026 template<class Base, class State, class Collector = IWORKCollector>
00027 class IWORKXMLContextBase : public Base
00028 {
00029 public:
00030   explicit IWORKXMLContextBase(State &state)
00031     : Base(state)
00032     , m_state(state)
00033   {
00034   }
00035 
00036   template<typename T>
00037   IWORKXMLContextBase(State &state, const T &a)
00038     : Base(state, a)
00039     , m_state(state)
00040   {
00041   }
00042 
00043   State &getState()
00044   {
00045     return m_state;
00046   }
00047 
00048 protected:
00049   Collector &getCollector() const
00050   {
00051     return m_state.getCollector();
00052   }
00053 
00054   int getToken(const char *const value) const
00055   {
00056     return m_state.getTokenizer().getId(value);
00057   }
00058 
00059   bool isCollector() const
00060   {
00061     return m_state.m_enableCollector;
00062   }
00063 
00064 protected:
00065   State &m_state;
00066 };
00067 
00068 class IWORKXMLContextMinimal : public IWORKXMLContext
00069 {
00070 protected:
00071   IWORKXMLContextMinimal();
00072 
00073   virtual void startOfElement();
00074   virtual void endOfAttributes();
00075   virtual void endOfElement();
00076 };
00077 
00078 class IWORKXMLContextElement : public IWORKXMLContextMinimal, public boost::enable_shared_from_this<IWORKXMLContextElement>
00079 {
00080 protected:
00081   explicit IWORKXMLContextElement(IWORKXMLParserState &);
00082 
00083   virtual void attribute(int name, const char *value);
00084   virtual void text(const char *value);
00085 
00086   const boost::optional<ID_t> &getId() const;
00087 
00088 private:
00089   boost::optional<ID_t> m_id;
00090 };
00091 
00092 class IWORKXMLContextText : public IWORKXMLContextMinimal
00093 {
00094 protected:
00095   explicit IWORKXMLContextText(IWORKXMLParserState &);
00096 
00097   virtual IWORKXMLContextPtr_t element(int token);
00098 };
00099 
00100 class IWORKXMLContextMixed : public IWORKXMLContextMinimal, public boost::enable_shared_from_this<IWORKXMLContextMixed>
00101 {
00102 protected:
00103   explicit IWORKXMLContextMixed(IWORKXMLParserState &);
00104 };
00105 
00106 class IWORKXMLContextEmpty : public IWORKXMLContextMinimal
00107 {
00108 protected:
00109   explicit IWORKXMLContextEmpty(IWORKXMLParserState &);
00110 
00111   virtual void attribute(int name, const char *value);
00112   virtual IWORKXMLContextPtr_t element(int token);
00113   virtual void text(const char *value);
00114 
00115   const boost::optional<ID_t> &getId() const;
00116   const boost::optional<ID_t> &getRef() const;
00117 
00118 private:
00119   boost::optional<ID_t> m_id;
00120   boost::optional<ID_t> m_ref;
00121 };
00122 
00123 typedef IWORKXMLContextBase<IWORKXMLContextElement, IWORKXMLParserState> IWORKXMLElementContextBase;
00124 typedef IWORKXMLContextBase<IWORKXMLContextText, IWORKXMLParserState> IWORKXMLTextContextBase;
00125 typedef IWORKXMLContextBase<IWORKXMLContextMixed, IWORKXMLParserState> IWORKXMLMixedContextBase;
00126 typedef IWORKXMLContextBase<IWORKXMLContextEmpty, IWORKXMLParserState> IWORKXMLEmptyContextBase;
00127 
00128 }
00129 
00130 #endif // IWORKXMLCONTEXTBASE_H_INCLUDED
00131 
00132 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */