diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 00:22:50 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 10:56:02 -0400 |
commit | 9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch) | |
tree | 3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/db/auth/user_name.h | |
parent | 01965cf52bce6976637ecb8f4a622aeb05ab256a (diff) | |
download | mongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz |
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/auth/user_name.h')
-rw-r--r-- | src/mongo/db/auth/user_name.h | 219 |
1 files changed, 123 insertions, 96 deletions
diff --git a/src/mongo/db/auth/user_name.h b/src/mongo/db/auth/user_name.h index 55220f33e10..03f39fa42d6 100644 --- a/src/mongo/db/auth/user_name.h +++ b/src/mongo/db/auth/user_name.h @@ -37,126 +37,153 @@ namespace mongo { +/** + * Representation of a name of a principal (authenticatable user) in a MongoDB system. + * + * Consists of a "user name" part, and a "database name" part. + */ +class UserName { +public: + UserName() : _splitPoint(0) {} + UserName(StringData user, StringData dbname); + /** - * Representation of a name of a principal (authenticatable user) in a MongoDB system. - * - * Consists of a "user name" part, and a "database name" part. + * Gets the user part of a UserName. */ - class UserName { - public: - UserName() : _splitPoint(0) {} - UserName(StringData user, StringData dbname); - - /** - * Gets the user part of a UserName. - */ - StringData getUser() const { return StringData(_fullName).substr(0, _splitPoint); } - - /** - * Gets the database name part of a UserName. - */ - StringData getDB() const { return StringData(_fullName).substr(_splitPoint + 1); } - - /** - * Gets the full unique name of a user as a string, formatted as "user@db". - */ - const std::string& getFullName() const { return _fullName; } - - /** - * Stringifies the object, for logging/debugging. - */ - std::string toString() const { return getFullName(); } - - private: - std::string _fullName; // The full name, stored as a string. "user@db". - size_t _splitPoint; // The index of the "@" separating the user and db name parts. - }; - - static inline bool operator==(const UserName& lhs, const UserName& rhs) { - return lhs.getFullName() == rhs.getFullName(); + StringData getUser() const { + return StringData(_fullName).substr(0, _splitPoint); } - static inline bool operator!=(const UserName& lhs, const UserName& rhs) { - return lhs.getFullName() != rhs.getFullName(); + /** + * Gets the database name part of a UserName. + */ + StringData getDB() const { + return StringData(_fullName).substr(_splitPoint + 1); } - static inline bool operator<(const UserName& lhs, const UserName& rhs) { - return lhs.getFullName() < rhs.getFullName(); + /** + * Gets the full unique name of a user as a string, formatted as "user@db". + */ + const std::string& getFullName() const { + return _fullName; } - std::ostream& operator<<(std::ostream& os, const UserName& name); - /** - * Iterator over an unspecified container of UserName objects. + * Stringifies the object, for logging/debugging. */ - class UserNameIterator { - public: - class Impl { - MONGO_DISALLOW_COPYING(Impl); - public: - Impl() {}; - virtual ~Impl() {}; - static Impl* clone(Impl* orig) { return orig ? orig->doClone(): NULL; } - virtual bool more() const = 0; - virtual const UserName& get() const = 0; - - virtual const UserName& next() = 0; - - private: - virtual Impl* doClone() const = 0; - }; - - UserNameIterator() : _impl(nullptr) {} - UserNameIterator(const UserNameIterator& other) : _impl(Impl::clone(other._impl.get())) {} - explicit UserNameIterator(Impl* impl) : _impl(impl) {} - - UserNameIterator& operator=(const UserNameIterator& other) { - _impl.reset(Impl::clone(other._impl.get())); - return *this; - } + std::string toString() const { + return getFullName(); + } - bool more() const { return _impl.get() && _impl->more(); } - const UserName& get() const { return _impl->get(); } +private: + std::string _fullName; // The full name, stored as a string. "user@db". + size_t _splitPoint; // The index of the "@" separating the user and db name parts. +}; - const UserName& next() { return _impl->next(); } +static inline bool operator==(const UserName& lhs, const UserName& rhs) { + return lhs.getFullName() == rhs.getFullName(); +} - const UserName& operator*() const { return get(); } - const UserName* operator->() const { return &get(); } +static inline bool operator!=(const UserName& lhs, const UserName& rhs) { + return lhs.getFullName() != rhs.getFullName(); +} - private: - std::unique_ptr<Impl> _impl; - }; +static inline bool operator<(const UserName& lhs, const UserName& rhs) { + return lhs.getFullName() < rhs.getFullName(); +} + +std::ostream& operator<<(std::ostream& os, const UserName& name); +/** + * Iterator over an unspecified container of UserName objects. + */ +class UserNameIterator { +public: + class Impl { + MONGO_DISALLOW_COPYING(Impl); - template <typename ContainerIterator> - class UserNameContainerIteratorImpl : public UserNameIterator::Impl { - MONGO_DISALLOW_COPYING(UserNameContainerIteratorImpl); public: - UserNameContainerIteratorImpl(const ContainerIterator& begin, - const ContainerIterator& end) : - _curr(begin), _end(end) {} - virtual ~UserNameContainerIteratorImpl() {} - virtual bool more() const { return _curr != _end; } - virtual const UserName& next() { return *(_curr++); } - virtual const UserName& get() const { return *_curr; } - virtual UserNameIterator::Impl* doClone() const { - return new UserNameContainerIteratorImpl(_curr, _end); + Impl(){}; + virtual ~Impl(){}; + static Impl* clone(Impl* orig) { + return orig ? orig->doClone() : NULL; } + virtual bool more() const = 0; + virtual const UserName& get() const = 0; + + virtual const UserName& next() = 0; private: - ContainerIterator _curr; - ContainerIterator _end; + virtual Impl* doClone() const = 0; }; - template <typename ContainerIterator> - UserNameIterator makeUserNameIterator(const ContainerIterator& begin, - const ContainerIterator& end) { - return UserNameIterator( new UserNameContainerIteratorImpl<ContainerIterator>(begin, end)); + UserNameIterator() : _impl(nullptr) {} + UserNameIterator(const UserNameIterator& other) : _impl(Impl::clone(other._impl.get())) {} + explicit UserNameIterator(Impl* impl) : _impl(impl) {} + + UserNameIterator& operator=(const UserNameIterator& other) { + _impl.reset(Impl::clone(other._impl.get())); + return *this; + } + + bool more() const { + return _impl.get() && _impl->more(); + } + const UserName& get() const { + return _impl->get(); + } + + const UserName& next() { + return _impl->next(); } - template <typename Container> - UserNameIterator makeUserNameIteratorForContainer(const Container& container) { - return makeUserNameIterator(container.begin(), container.end()); + const UserName& operator*() const { + return get(); } + const UserName* operator->() const { + return &get(); + } + +private: + std::unique_ptr<Impl> _impl; +}; + + +template <typename ContainerIterator> +class UserNameContainerIteratorImpl : public UserNameIterator::Impl { + MONGO_DISALLOW_COPYING(UserNameContainerIteratorImpl); + +public: + UserNameContainerIteratorImpl(const ContainerIterator& begin, const ContainerIterator& end) + : _curr(begin), _end(end) {} + virtual ~UserNameContainerIteratorImpl() {} + virtual bool more() const { + return _curr != _end; + } + virtual const UserName& next() { + return *(_curr++); + } + virtual const UserName& get() const { + return *_curr; + } + virtual UserNameIterator::Impl* doClone() const { + return new UserNameContainerIteratorImpl(_curr, _end); + } + +private: + ContainerIterator _curr; + ContainerIterator _end; +}; + +template <typename ContainerIterator> +UserNameIterator makeUserNameIterator(const ContainerIterator& begin, + const ContainerIterator& end) { + return UserNameIterator(new UserNameContainerIteratorImpl<ContainerIterator>(begin, end)); +} + +template <typename Container> +UserNameIterator makeUserNameIteratorForContainer(const Container& container) { + return makeUserNameIterator(container.begin(), container.end()); +} } // namespace mongo |