From 9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 Mon Sep 17 00:00:00 2001 From: Mark Benvenuto Date: Sat, 20 Jun 2015 00:22:50 -0400 Subject: SERVER-18579: Clang-Format - reformat code, no comment reflow --- src/mongo/db/auth/user_name.h | 219 ++++++++++++++++++++++++------------------ 1 file changed, 123 insertions(+), 96 deletions(-) (limited to 'src/mongo/db/auth/user_name.h') 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; - }; +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 - 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 - UserNameIterator makeUserNameIterator(const ContainerIterator& begin, - const ContainerIterator& end) { - return UserNameIterator( new UserNameContainerIteratorImpl(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 - 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; +}; + + +template +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 +UserNameIterator makeUserNameIterator(const ContainerIterator& begin, + const ContainerIterator& end) { + return UserNameIterator(new UserNameContainerIteratorImpl(begin, end)); +} + +template +UserNameIterator makeUserNameIteratorForContainer(const Container& container) { + return makeUserNameIterator(container.begin(), container.end()); +} } // namespace mongo -- cgit v1.2.1