Drizzled Public API Documentation

catalog.h
00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 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/enum.h>
00024 #include <drizzled/definitions.h>
00025 #include <drizzled/util/data_ref.h>
00026 #include <cstring>
00027 #include <cassert>
00028 #include <ostream>
00029 #include <vector>
00030 #include <algorithm>
00031 #include <functional>
00032 #include <iosfwd>
00033 #include <boost/algorithm/string.hpp>
00034 
00035 namespace drizzled {
00036 namespace identifier {
00037 
00038 class Catalog : public Identifier
00039 {
00040 public:
00041   Catalog(str_ref);
00042   bool isValid() const;
00043   bool compare(const std::string &arg) const;
00044 
00045   const std::string &getPath() const
00046   {
00047     return path;
00048   }
00049 
00050   const std::string &getName() const
00051   {
00052     return _name;
00053   }
00054 
00055   const std::string &name() const
00056   {
00057     return _name;
00058   }
00059 
00060   virtual std::string getSQLPath() const
00061   {
00062     return _name;
00063   }
00064 
00065   size_t getHashValue() const
00066   {
00067     return hash_value;
00068   }
00069 
00070   friend bool operator<(const Catalog &left, const Catalog &right)
00071   {
00072     return boost::ilexicographical_compare(left.getName(), right.getName());
00073   }
00074 
00075   friend std::ostream& operator<<(std::ostream& output, const Catalog &identifier)
00076   {
00077     return output << "Catalog:(" <<  identifier.getName() << ", " << identifier.getPath() << ")";
00078   }
00079 
00080   friend bool operator==(const Catalog &left, const Catalog &right)
00081   {
00082     return boost::iequals(left.getName(), right.getName());
00083   }
00084 
00085   void resetPath()
00086   {
00087     init();
00088   }
00089 
00090 private:
00091   void init();
00092 
00093   std::string _name;
00094   std::string path;
00095   size_t hash_value;
00096 };
00097 
00098 inline std::size_t hash_value(Catalog const& b)
00099 {
00100   return b.getHashValue();
00101 }
00102 
00103 } /* namespace identifier */
00104 } /* namespace drizzled */