Drizzled Public API Documentation

key.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 #include <boost/thread/mutex.hpp>
00022 #include <boost/thread/condition_variable.hpp>
00023 #include <boost/unordered_map.hpp>
00024 #include <boost/unordered/unordered_set.hpp>
00025 
00026 #include <string>
00027 
00028 #include <drizzled/session.h>
00029 #include <drizzled/util/string.h>
00030 
00031 
00032 #pragma once
00033 
00034 namespace user_locks {
00035 
00036 class Key {
00037   drizzled::identifier::User context;
00038   std::string lock_name;
00039   size_t hash_value;
00040 
00041 public:
00042   Key(const drizzled::identifier::User &context_arg, const std::string &lock_name_arg) :
00043     context(context_arg),
00044     lock_name(lock_name_arg)
00045   {
00046     drizzled::util::insensitive_hash hasher;
00047     hash_value= hasher(context.username() + lock_name_arg);
00048   }
00049 
00050   size_t getHashValue() const
00051   {
00052     return hash_value;
00053   }
00054 
00055   const std::string &getLockName() const
00056   {
00057     return lock_name;
00058   }
00059 
00060   const std::string &getUser() const
00061   {
00062     return context.username();
00063   }
00064 };
00065 
00066 bool operator==(Key const& left, Key const& right);
00067 
00068 std::size_t hash_value(Key const& b);
00069 
00070 typedef boost::unordered_set<Key> Keys;
00071 
00072 } /* namespace user_locks */
00073