1
0
Fork 0

use namespace std

This commit is contained in:
Jan Steemann 2014-06-05 01:29:01 +02:00
parent 229e710dd1
commit 1925a16640
1 changed files with 23 additions and 46 deletions

View File

@ -49,11 +49,6 @@ namespace triagens {
// --SECTION-- constructors / destructors
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup ArangoDB
/// @{
////////////////////////////////////////////////////////////////////////////////
public:
////////////////////////////////////////////////////////////////////////////////
@ -71,34 +66,25 @@ namespace triagens {
~CollectionNameResolver () {
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- public methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup ArangoDB
/// @{
////////////////////////////////////////////////////////////////////////////////
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief look up a collection id for a collection name (local case)
////////////////////////////////////////////////////////////////////////////////
TRI_voc_cid_t getCollectionId (string const& name) const {
TRI_voc_cid_t getCollectionId (std::string const& name) const {
if (name[0] >= '0' && name[0] <= '9') {
// name is a numeric id
return (TRI_voc_cid_t) triagens::basics::StringUtils::uint64(name);
}
const TRI_vocbase_col_t* collection = getCollectionStruct(name);
TRI_vocbase_col_t const* collection = getCollectionStruct(name);
if (collection != 0) {
if (collection != nullptr) {
return collection->_cid;
}
return 0;
@ -108,19 +94,21 @@ namespace triagens {
/// @brief look up a collection struct for a collection name
////////////////////////////////////////////////////////////////////////////////
const TRI_vocbase_col_t* getCollectionStruct (string const& name) const {
const TRI_vocbase_col_t* getCollectionStruct (std::string const& name) const {
std::unordered_map<std::string, TRI_vocbase_col_t const*>::iterator it;
if (! _resolvedNames.empty()) {
map<string, const TRI_vocbase_col_t*>::const_iterator it = _resolvedNames.find(name);
it = _resolvedNames.find(name);
if (it != _resolvedNames.end()) {
return (*it).second;
}
}
const TRI_vocbase_col_t* collection = TRI_LookupCollectionByNameVocBase(_vocbase, name.c_str());
TRI_vocbase_col_t const* collection = TRI_LookupCollectionByNameVocBase(_vocbase, name.c_str());
if (collection != 0) {
_resolvedNames.insert(make_pair(name, collection));
if (collection != nullptr) {
_resolvedNames.insert(it, std::make_pair(name, collection));
}
return collection;
@ -130,7 +118,7 @@ namespace triagens {
/// @brief look up a cluster collection id for a cluster collection name
////////////////////////////////////////////////////////////////////////////////
TRI_voc_cid_t getCollectionIdCluster (string const& name) const {
TRI_voc_cid_t getCollectionIdCluster (std::string const& name) const {
if (! ServerState::instance()->isRunningInCluster()) {
return getCollectionId(name);
}
@ -156,16 +144,18 @@ namespace triagens {
/// translate the local collection ID into a cluster wide collection name.
////////////////////////////////////////////////////////////////////////////////
string getCollectionName (const TRI_voc_cid_t cid) const {
std::string getCollectionName (const TRI_voc_cid_t cid) const {
std::unordered_map<TRI_voc_cid_t, std::string>::iterator it;
if (! _resolvedIds.empty()) {
map<TRI_voc_cid_t, string>::const_iterator it = _resolvedIds.find(cid);
it = _resolvedIds.find(cid);
if (it != _resolvedIds.end()) {
return (*it).second;
}
}
string name;
std::string name;
if (ServerState::instance()->isDBserver()) {
TRI_READ_LOCK_COLLECTIONS_VOCBASE(_vocbase);
@ -174,13 +164,13 @@ namespace triagens {
TRI_LookupByKeyAssociativePointer
(&_vocbase->_collectionsById, &cid));
if (0 != found) {
if (nullptr != found) {
name = triagens::basics::StringUtils::itoa(found->_planId);
}
TRI_READ_UNLOCK_COLLECTIONS_VOCBASE(_vocbase);
if (!name.empty()) {
if (! name.empty()) {
shared_ptr<CollectionInfo> ci
= ClusterInfo::instance()->getCollection(found->_dbName, name);
name = ci->name();
@ -198,7 +188,7 @@ namespace triagens {
name = "_unknown";
}
_resolvedIds.insert(make_pair(cid, name));
_resolvedIds.insert(it, std::make_pair(cid, name));
return name;
}
@ -208,7 +198,7 @@ namespace triagens {
/// collection id
////////////////////////////////////////////////////////////////////////////////
string getCollectionNameCluster (const TRI_voc_cid_t cid) const {
std::string getCollectionNameCluster (const TRI_voc_cid_t cid) const {
if (! ServerState::instance()->isRunningInCluster()) {
return getCollectionName(cid);
}
@ -219,7 +209,7 @@ namespace triagens {
shared_ptr<CollectionInfo> ci
= ClusterInfo::instance()->getCollection(_vocbase->_name,
triagens::basics::StringUtils::itoa(cid));
string name = ci->name();
std::string name = ci->name();
if (name.empty()) {
ClusterInfo::instance()->flush();
@ -231,19 +221,10 @@ namespace triagens {
return "_unknown";
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- private variables
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup ArangoDB
/// @{
////////////////////////////////////////////////////////////////////////////////
private:
////////////////////////////////////////////////////////////////////////////////
@ -256,17 +237,13 @@ namespace triagens {
/// @brief collection id => collection struct map
////////////////////////////////////////////////////////////////////////////////
mutable std::map<std::string, const TRI_vocbase_col_t*> _resolvedNames;
mutable std::unordered_map<std::string, TRI_vocbase_col_t const*> _resolvedNames;
////////////////////////////////////////////////////////////////////////////////
/// @brief collection id => collection name map
////////////////////////////////////////////////////////////////////////////////
mutable std::map<TRI_voc_cid_t, std::string> _resolvedIds;
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
mutable std::unordered_map<TRI_voc_cid_t, std::string> _resolvedIds;
};
}