0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
NameIdMapper.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
22 #ifndef Hypertable_Lib_NameIdMapper_h
23 #define Hypertable_Lib_NameIdMapper_h
24 
25 #include <Common/Compat.h>
26 
27 #include "NamespaceListing.h"
28 
29 #include <Hyperspace/Session.h>
30 
31 #include <Common/String.h>
32 
33 #include <memory>
34 #include <mutex>
35 #include <vector>
36 
37 namespace Hyperspace {
38  class Session;
39 }
40 
41 namespace Hypertable {
42 
45  class NameIdMapper {
46 
47  public:
48 
49  enum Flag { IS_NAMESPACE=0x0001, CREATE_INTERMEDIATE=0x0002 };
50 
51  NameIdMapper(Hyperspace::SessionPtr &hyperspace, const std::string &toplevel_dir);
58  bool name_to_id(const std::string &name, std::string &id, bool *is_namespacep=0);
59 
66  bool id_to_name(const std::string &id, std::string &name, bool *is_namespacep=0);
67 
74  void id_to_sublisting(const std::string &id, bool include_sub_entries, std::vector<NamespaceListing> &listing);
75 
82  void add_mapping(const std::string &name, std::string &id, int flags=0, bool ignore_exists=false);
83 
87  void drop_mapping(const std::string &name);
88 
94  bool exists_mapping(const std::string &name, bool *is_namespace);
95 
103  void rename(const std::string &old_name, const std::string &new_name);
104 
105  void add_entry(const std::string &names_parent, const std::string &names_entry,
106  std::vector<uint64_t> &ids, bool is_namespace);
107 
108  protected:
109  bool do_mapping(const std::string &input, bool id_in, std::string &output, bool *is_namespacep);
110  static void get_namespace_listing(const std::vector<Hyperspace::DirEntryAttr> &dir_listing, std::vector<NamespaceListing> &listing);
111 
114  std::string m_toplevel_dir;
115  std::string m_names_dir;
116  std::string m_ids_dir;
118  };
119 
121  typedef std::shared_ptr<NameIdMapper> NameIdMapperPtr;
122 
123 }
124 
125 #endif // Hypertable_Lib_NameIdMapper_h
static std::mutex mutex
Definition: Logger.cc:43
bool id_to_name(const std::string &id, std::string &name, bool *is_namespacep=0)
Definition: NameIdMapper.cc:69
void add_entry(const std::string &names_parent, const std::string &names_entry, std::vector< uint64_t > &ids, bool is_namespace)
Definition: NameIdMapper.cc:74
void id_to_sublisting(const std::string &id, bool include_sub_entries, std::vector< NamespaceListing > &listing)
bool do_mapping(const std::string &input, bool id_in, std::string &output, bool *is_namespacep)
void drop_mapping(const std::string &name)
Drops a mapping.
Hyperspace definitions
std::shared_ptr< Session > SessionPtr
Definition: Session.h:734
bool exists_mapping(const std::string &name, bool *is_namespace)
void add_mapping(const std::string &name, std::string &id, int flags=0, bool ignore_exists=false)
Adds a new mapping.
Compatibility Macros for C/C++.
Hyperspace::SessionPtr m_hyperspace
Definition: NameIdMapper.h:113
Hyperspace session.
Definition: Session.h:148
void rename(const std::string &old_name, const std::string &new_name)
Rename one entity, it doesn't recursively rename all entities under the path specified by old_name...
Hypertable definitions
static void get_namespace_listing(const std::vector< Hyperspace::DirEntryAttr > &dir_listing, std::vector< NamespaceListing > &listing)
A String class based on std::string.
bool name_to_id(const std::string &name, std::string &id, bool *is_namespacep=0)
Definition: NameIdMapper.cc:64
Easy mapping between a Table/Namespace name string to ids and vice versa.
Definition: NameIdMapper.h:45
std::shared_ptr< NameIdMapper > NameIdMapperPtr
Smart pointer to NameIdMapper.
Definition: NameIdMapper.h:121
NameIdMapper(Hyperspace::SessionPtr &hyperspace, const std::string &toplevel_dir)
Definition: NameIdMapper.cc:40