Drizzled Public API Documentation

property_map.h

00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2011 Brian Aker
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #pragma once
00022 
00023 #include <drizzled/util/storable.h>
00024 #include <drizzled/util/string.h>
00025 #include <boost/unordered_map.hpp>
00026 
00027 namespace drizzled
00028 {
00029 
00030 class Session;
00031 
00032 namespace session
00033 {
00034 
00035 class PropertyMap {
00036 private:
00037   typedef boost::unordered_map<std::string, util::Storable *, util::insensitive_hash, util::insensitive_equal_to> Map;
00038 
00039 public:
00040   typedef Map::iterator iterator;
00041   typedef Map::const_iterator const_iterator;
00042 
00043   drizzled::util::Storable *getProperty(const std::string &arg)
00044   {
00045     return _properties[arg];
00046   }
00047 
00048   template<class T>
00049   bool setProperty(const std::string &arg, T *value)
00050   {
00051     _properties[arg]= value;
00052 
00053     return true;
00054   }
00055 
00056   iterator begin()
00057   {
00058     return _properties.begin();
00059   }
00060 
00061   iterator end()
00062   {
00063     return _properties.end();
00064   }
00065 
00066   const_iterator begin() const
00067   {
00068     return _properties.begin();
00069   }
00070 
00071   const_iterator end() const
00072   {
00073     return _properties.end();
00074   }
00075 
00076   ~PropertyMap()
00077   {
00078     for (iterator iter= _properties.begin(); iter != _properties.end(); iter++)
00079     {
00080       boost::checked_delete(iter->second);
00081     }
00082     _properties.clear();
00083   }
00084 
00085 private:
00086   Map _properties;
00087 };
00088 
00089 } /* namespace session */
00090 } /* namespace drizzled */
00091