IWORKPropertyContext.h
Go to the documentation of this file.
00001 /* -*- Mode: Context++; 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 IWORKPROPERTYCONTEXT_H_INCLUDED
00011 #define IWORKPROPERTYCONTEXT_H_INCLUDED
00012 
00013 #include <boost/optional.hpp>
00014 
00015 #include "IWORKPropertyContextBase.h"
00016 #include "IWORKPropertyInfo.h"
00017 
00018 namespace libetonyek
00019 {
00020 
00021 template<typename Property, typename Context, int TokenId>
00022 class IWORKPropertyContext : public IWORKPropertyContextBase
00023 {
00024 public:
00025   IWORKPropertyContext(IWORKXMLParserState &state, IWORKPropertyMap &propMap);
00026 
00027 private:
00028   virtual IWORKXMLContextPtr_t element(int name);
00029   virtual void endOfElement();
00030 
00031 private:
00032   boost::optional<typename IWORKPropertyInfo<Property>::ValueType> m_value;
00033 };
00034 
00035 template<typename Property, typename Context, int TokenId>
00036 IWORKPropertyContext<Property, Context, TokenId>::IWORKPropertyContext(IWORKXMLParserState &state, IWORKPropertyMap &propMap)
00037   : IWORKPropertyContextBase(state, propMap)
00038   , m_value()
00039 {
00040 }
00041 
00042 template<typename Property, typename Context, int TokenId>
00043 IWORKXMLContextPtr_t IWORKPropertyContext<Property, Context, TokenId>::element(const int name)
00044 {
00045   m_default = false;
00046   if (TokenId == name)
00047     return makeContext<Context>(getState(), m_value);
00048   return IWORKXMLContextPtr_t();
00049 }
00050 
00051 template<typename Property, typename Context, int TokenId>
00052 void IWORKPropertyContext<Property, Context, TokenId>::endOfElement()
00053 {
00054   if (bool(m_value))
00055     m_propMap.put<Property>(get(m_value));
00056   else if (m_default)
00057     m_propMap.clear<Property>();
00058 }
00059 
00060 }
00061 
00062 #endif // IWORKPROPERTYCONTEXT_H_INCLUDED
00063 
00064 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */