diff options
author | Andrew Morrow <acm@mongodb.com> | 2015-01-03 14:11:49 -0500 |
---|---|---|
committer | Andrew Morrow <acm@mongodb.com> | 2015-01-05 18:26:59 -0500 |
commit | 939db8fd31790eff642abd446552294c66c5ff8a (patch) | |
tree | 88f6703b4b07db958470dec2bea40d59629a37d5 /src/mongo | |
parent | 60e074c4c123f559c126ea01877e7bdc33f1bbbd (diff) | |
download | mongo-939db8fd31790eff642abd446552294c66c5ff8a.tar.gz |
SERVER-13256 Move ptr<T> out of goodies to own header
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/sorter/sorter.cpp | 1 | ||||
-rw-r--r-- | src/mongo/dbtests/basictests.cpp | 1 | ||||
-rw-r--r-- | src/mongo/s/chunk.h | 1 | ||||
-rw-r--r-- | src/mongo/util/goodies.h | 38 | ||||
-rw-r--r-- | src/mongo/util/ptr.h | 75 |
5 files changed, 78 insertions, 38 deletions
diff --git a/src/mongo/db/sorter/sorter.cpp b/src/mongo/db/sorter/sorter.cpp index 2844cc9f4a8..7bd739fba86 100644 --- a/src/mongo/db/sorter/sorter.cpp +++ b/src/mongo/db/sorter/sorter.cpp @@ -58,6 +58,7 @@ #include "mongo/util/bufreader.h" #include "mongo/util/goodies.h" #include "mongo/util/mongoutils/str.h" +#include "mongo/util/ptr.h" namespace mongo { namespace sorter { diff --git a/src/mongo/dbtests/basictests.cpp b/src/mongo/dbtests/basictests.cpp index e6c323c1db5..8a407685bb0 100644 --- a/src/mongo/dbtests/basictests.cpp +++ b/src/mongo/dbtests/basictests.cpp @@ -36,6 +36,7 @@ #include "mongo/util/base64.h" #include "mongo/util/compress.h" #include "mongo/util/paths.h" +#include "mongo/util/ptr.h" #include "mongo/util/queue.h" #include "mongo/util/stringutils.h" #include "mongo/util/text.h" diff --git a/src/mongo/s/chunk.h b/src/mongo/s/chunk.h index 8d9f3a6e8e3..1ec82d39488 100644 --- a/src/mongo/s/chunk.h +++ b/src/mongo/s/chunk.h @@ -38,6 +38,7 @@ #include "mongo/s/shard.h" #include "mongo/s/shard_key_pattern.h" #include "mongo/util/concurrency/ticketholder.h" +#include "mongo/util/ptr.h" namespace mongo { diff --git a/src/mongo/util/goodies.h b/src/mongo/util/goodies.h index 56ab4e65c19..8c0c46835be 100644 --- a/src/mongo/util/goodies.h +++ b/src/mongo/util/goodies.h @@ -155,43 +155,5 @@ namespace mongo { std::ostream& operator<<(std::ostream &s, const ThreadSafeString &o); - /** A generic pointer type for function arguments. - * It will convert from any pointer type except auto_ptr. - * Semantics are the same as passing the pointer returned from get() - * const ptr<T> => T * const - * ptr<const T> => T const * or const T* - */ - template <typename T> - struct ptr { - - ptr() : _p(NULL) {} - - // convert to ptr<T> - ptr(T* p) : _p(p) {} // needed for NULL - template<typename U> ptr(U* p) : _p(p) {} - template<typename U> ptr(const ptr<U>& p) : _p(p) {} - template<typename U> ptr(const boost::shared_ptr<U>& p) : _p(p.get()) {} - template<typename U> ptr(const boost::scoped_ptr<U>& p) : _p(p.get()) {} - //template<typename U> ptr(const std::auto_ptr<U>& p) : _p(p.get()) {} - - // assign to ptr<T> - ptr& operator= (T* p) { _p = p; return *this; } // needed for NULL - template<typename U> ptr& operator= (U* p) { _p = p; return *this; } - template<typename U> ptr& operator= (const ptr<U>& p) { _p = p; return *this; } - template<typename U> ptr& operator= (const boost::shared_ptr<U>& p) { _p = p.get(); return *this; } - template<typename U> ptr& operator= (const boost::scoped_ptr<U>& p) { _p = p.get(); return *this; } - //template<typename U> ptr& operator= (const std::auto_ptr<U>& p) { _p = p.get(); return *this; } - - // use - T* operator->() const { return _p; } - T& operator*() const { return *_p; } - - // convert from ptr<T> - operator T* () const { return _p; } - - private: - T* _p; - }; - } // namespace mongo diff --git a/src/mongo/util/ptr.h b/src/mongo/util/ptr.h new file mode 100644 index 00000000000..01b47f1c982 --- /dev/null +++ b/src/mongo/util/ptr.h @@ -0,0 +1,75 @@ +/** + * Copyright (C) 2015 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#pragma once + +#include <boost/scoped_ptr.hpp> +#include <boost/shared_ptr.hpp> + +namespace mongo { + + + /** A generic pointer type for function arguments. + * It will convert from any pointer type except auto_ptr. + * Semantics are the same as passing the pointer returned from get() + * const ptr<T> => T * const + * ptr<const T> => T const * or const T* + */ + template <typename T> + struct ptr { + + ptr() : _p(NULL) {} + + // convert to ptr<T> + ptr(T* p) : _p(p) {} // needed for NULL + template<typename U> ptr(U* p) : _p(p) {} + template<typename U> ptr(const ptr<U>& p) : _p(p) {} + template<typename U> ptr(const boost::shared_ptr<U>& p) : _p(p.get()) {} + template<typename U> ptr(const boost::scoped_ptr<U>& p) : _p(p.get()) {} + //template<typename U> ptr(const std::auto_ptr<U>& p) : _p(p.get()) {} + + // assign to ptr<T> + ptr& operator= (T* p) { _p = p; return *this; } // needed for NULL + template<typename U> ptr& operator= (U* p) { _p = p; return *this; } + template<typename U> ptr& operator= (const ptr<U>& p) { _p = p; return *this; } + template<typename U> ptr& operator= (const boost::shared_ptr<U>& p) { _p = p.get(); return *this; } + template<typename U> ptr& operator= (const boost::scoped_ptr<U>& p) { _p = p.get(); return *this; } + //template<typename U> ptr& operator= (const std::auto_ptr<U>& p) { _p = p.get(); return *this; } + + // use + T* operator->() const { return _p; } + T& operator*() const { return *_p; } + + // convert from ptr<T> + operator T* () const { return _p; } + + private: + T* _p; + }; + +} // namespace mongo |