ShMetaImpl.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2006 Serious Hack Inc.
00004 // 
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
00020 #ifndef SH_METAIMPL_HPP
00021 #define SH_METAIMPL_HPP
00022 
00023 #include "ShMeta.hpp"
00024 
00025 namespace SH {
00026 
00027 inline ShMeta::ShMeta(const ShMeta &other)
00028   : m_meta(0)
00029 {
00030   *this = other;
00031 }
00032 
00033 inline const ShMeta & ShMeta::operator=(const ShMeta &other)
00034 {
00035   if(other.m_meta) {
00036     m_meta = new MetaMap();
00037     *m_meta = *other.m_meta;
00038   }
00039   else {
00040     m_meta = 0;
00041   }
00042   return *this;
00043 }
00044 
00045 inline ShMeta::~ShMeta()
00046 {
00047   delete m_meta;
00048 }
00049 
00050 inline std::string ShMeta::name() const
00051 {
00052   return meta("n"); 
00053 }
00054 
00055 inline void ShMeta::name(const std::string& n)
00056 {
00057   meta("n", n);
00058 }
00059 
00060 inline bool ShMeta::has_name() const
00061 {
00062   return !meta("n").empty(); 
00063 }
00064 
00065 inline bool ShMeta::internal() const
00066 {
00067   return !meta("i").empty(); 
00068 }
00069 
00070 inline void ShMeta::internal(bool i)
00071 {
00072   meta("i", i ? "1" : "");
00073 }
00074 
00075 inline std::string ShMeta::title() const
00076 {
00077   return meta("t");
00078 }
00079 
00080 inline void ShMeta::title(const std::string& t)
00081 {
00082   meta("t", t);
00083 }
00084 
00085 inline std::string ShMeta::description() const
00086 {
00087   return meta("d");
00088 }
00089 
00090 inline void ShMeta::description(const std::string& d)
00091 {
00092   meta("d", d);
00093 }
00094 
00095 inline std::string ShMeta::meta(const std::string& key) const
00096 {
00097   if (!m_meta) return std::string(); 
00098 
00099   MetaMap::const_iterator I = m_meta->find(key);
00100   if (I == m_meta->end()) return std::string();
00101   return I->second;
00102 }
00103 
00104 inline ShMeta::MetaMap::const_iterator ShMeta::begin_meta() const
00105 {
00106   if (!m_meta) m_meta = new MetaMap();
00107   return m_meta->begin();
00108 }
00109 
00110 inline ShMeta::MetaMap::const_iterator ShMeta::end_meta() const
00111 {
00112   if (!m_meta) m_meta = new MetaMap();
00113   return m_meta->end();
00114 }
00115 
00116 inline void ShMeta::meta(const std::string& key, const std::string& value)
00117 {
00118   if(!m_meta) m_meta = new MetaMap();
00119   (*m_meta)[key] = value;
00120 }
00121 
00122 inline bool ShMeta::has_meta(const std::string& key) const
00123 {
00124   return m_meta && (m_meta->find(key) != m_meta->end());
00125 }
00126 
00127 }
00128 
00129 #endif
00130 

Generated on Thu Feb 16 14:51:36 2006 for Sh by  doxygen 1.4.6