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 <string.h>
00026 
00027 #include <assert.h>
00028 
00029 #include <ostream>
00030 #include <vector>
00031 #include <algorithm>
00032 #include <functional>
00033 #include <iostream>
00034 
00035 #include <boost/algorithm/string.hpp>
00036 
00037 namespace drizzled {
00038 
00039 class lex_string_t;
00040 
00041 namespace identifier {
00042 
00043 class Catalog : public Identifier
00044 {
00045   std::string _name;
00046   std::string path;
00047 
00048   void init();
00049 
00050 public:
00051   typedef std::vector<Catalog> vector;
00052   typedef const Catalog& const_reference;
00053   typedef Catalog& reference;
00054 
00055   Catalog(const std::string &name_arg);
00056   Catalog(const drizzled::lex_string_t &name_arg);
00057 
00058   virtual ~Catalog()
00059   { }
00060 
00061   const std::string &getPath() const;
00062 
00063   const std::string &getName() const
00064   {
00065     return _name;
00066   }
00067 
00068   const std::string &name() const
00069   {
00070     return _name;
00071   }
00072 
00073   virtual void getSQLPath(std::string &sql_path) const;
00074 
00075   bool isValid() const;
00076   bool compare(const std::string &arg) const;
00077 
00078   size_t getHashValue() const
00079   {
00080     return hash_value;
00081   }
00082 
00083   friend bool operator<(const Catalog &left, const Catalog &right)
00084   {
00085     return  boost::algorithm::to_upper_copy(left.getName()) < boost::algorithm::to_upper_copy(right.getName());
00086   }
00087 
00088   friend std::ostream& operator<<(std::ostream& output, const Catalog &identifier)
00089   {
00090     output << "Catalog:(";
00091     output <<  identifier.getName();
00092     output << ", ";
00093     output << identifier.getPath();
00094     output << ")";
00095 
00096     return output;  // for multiple << operators.
00097   }
00098 
00099   friend bool operator==(const Catalog &left,
00100                          const Catalog &right)
00101   {
00102     return boost::iequals(left.getName(), right.getName());
00103   }
00104 
00105 private:
00106   size_t hash_value;
00107 
00108 };
00109 
00110 std::size_t hash_value(Catalog const& b);
00111 
00112 } /* namespace identifier */
00113 } /* namespace drizzled */