From 1a64be2dcf624be0435ffcb0f01c0e461f3f2d4e Mon Sep 17 00:00:00 2001 From: Petr Filipsky Date: Thu, 28 Jun 2018 18:29:35 +0200 Subject: [PATCH 1/3] Replace deprecated std::auto_ptr with std::unique_ptr For more details see the: https://clang.llvm.org/extra/clang-tidy/checks/modernize-replace-auto-ptr.html --- booster/booster/aio/io_service.h | 2 +- booster/booster/aio/reactor.h | 2 +- booster/booster/callback.h | 4 +- booster/booster/locale/format.h | 2 +- booster/booster/locale/generator.h | 2 +- booster/booster/locale/localization_backend.h | 6 +- booster/booster/locale/util.h | 6 +- booster/booster/log.h | 2 +- booster/booster/shared_ptr.h | 4 +- booster/booster/smart_ptr/shared_count.h | 2 +- booster/booster/streambuf.h | 4 +- booster/lib/aio/src/acceptor.cpp | 6 +- booster/lib/aio/src/deadline_timer.cpp | 6 +- booster/lib/aio/src/io_service.cpp | 2 +- booster/lib/aio/src/stream_socket.cpp | 6 +- booster/lib/function/test/test_callback.cpp | 17 ++--- booster/lib/iostreams/src/streambuf.cpp | 6 +- booster/lib/locale/src/encoding/codepage.cpp | 6 +- .../locale/src/encoding/uconv_codepage.ipp | 12 ++-- booster/lib/locale/src/icu/boundary.cpp | 10 +-- booster/lib/locale/src/icu/codecvt.cpp | 11 ++-- booster/lib/locale/src/icu/codecvt.h | 2 +- booster/lib/locale/src/icu/date_time.cpp | 2 +- booster/lib/locale/src/icu/formatter.cpp | 26 ++++---- booster/lib/locale/src/icu/formatter.h | 6 +- booster/lib/locale/src/icu/numeric.cpp | 4 +- .../locale/src/icu/predefined_formatters.h | 10 +-- booster/lib/locale/src/posix/codecvt.cpp | 11 ++-- booster/lib/locale/src/posix/codecvt.h | 2 +- .../src/shared/localization_backend.cpp | 23 +++---- booster/lib/locale/src/shared/message.cpp | 4 +- booster/lib/locale/src/shared/mo_lambda.cpp | 66 ++++++++++--------- booster/lib/locale/src/shared/mo_lambda.h | 2 +- .../lib/locale/src/util/codecvt_converter.cpp | 37 ++++++----- booster/lib/locale/src/util/gregorian.cpp | 4 +- .../locale/test/test_codepage_converter.cpp | 10 +-- booster/lib/log/src/log.cpp | 5 +- booster/lib/thread/src/pthread.cpp | 2 +- cppcms/applications_pool.h | 42 ++++++------ cppcms/archive_traits.h | 2 +- cppcms/crypto.h | 14 ++-- cppcms/service.h | 2 +- cppcms/session_cookies.h | 6 +- cppcms/session_dual.h | 2 +- cppcms/session_pool.h | 12 ++-- cppcms/views_pool.h | 16 ++--- private/aes_encryptor.h | 6 +- private/fastcgi_api.h | 6 +- private/hmac_encryptor.h | 2 +- private/http_api.h | 2 +- private/prefork_acceptor.h | 2 +- private/scgi_api.h | 6 +- private/service_impl.h | 24 +++---- src/aes.cpp | 14 ++-- src/aes_encryptor.cpp | 17 ++--- src/application.cpp | 1 + src/applications_pool.cpp | 17 ++--- src/cache_storage.cpp | 4 +- src/copy_filter.cpp | 6 +- src/crypto.cpp | 23 +++---- src/fastcgi_api.cpp | 22 +++---- src/hello_world.cpp | 1 + src/hmac_encryptor.cpp | 8 ++- src/http_api.cpp | 9 +-- src/http_context.cpp | 8 ++- src/internal_file_server.cpp | 1 + src/make_key.cpp | 4 +- src/scgi_api.cpp | 19 +++--- src/service.cpp | 7 +- src/session_cookies.cpp | 6 +- src/session_dual.cpp | 6 +- src/session_pool.cpp | 34 +++++----- src/tcp_cache_server.cpp | 2 +- src/views_pool.cpp | 12 ++-- tests/cache_backend_test.cpp | 2 +- tests/cache_frontend_test.cpp | 1 + tests/cookie_test.cpp | 1 + tests/cppcms_service_test.cpp | 1 + tests/disco_test.cpp | 1 + tests/encryptor_test.cpp | 12 ++-- tests/file_server_test.cpp | 1 + tests/filter_test.cpp | 1 + tests/form_test.cpp | 1 + tests/forwarder_test.cpp | 1 + tests/gzip_test.cpp | 1 + tests/http_timeouts_test.cpp | 1 + tests/jsonrpc_test.cpp | 2 + tests/pool_test.cpp | 1 + tests/proto_test.cpp | 1 + tests/response_test.cpp | 1 + tests/secure_post_test.cpp | 1 + tests/serialization_test.cpp | 2 +- tests/session_interface_test.cpp | 1 + tests/status_test.cpp | 1 + tests/storage_test.cpp | 2 +- tests/tc_test.cpp | 1 + 96 files changed, 400 insertions(+), 336 deletions(-) diff --git a/booster/booster/aio/io_service.h b/booster/booster/aio/io_service.h index cbc41f4b..30b2bec3 100644 --- a/booster/booster/aio/io_service.h +++ b/booster/booster/aio/io_service.h @@ -137,7 +137,7 @@ namespace aio { private: struct data; hold_ptr d; - std::auto_ptr impl_; + std::unique_ptr impl_; }; } // aio diff --git a/booster/booster/aio/reactor.h b/booster/booster/aio/reactor.h index 9c697100..9fa0e6e3 100644 --- a/booster/booster/aio/reactor.h +++ b/booster/booster/aio/reactor.h @@ -113,7 +113,7 @@ namespace aio { /// std::string name() const; private: - std::auto_ptr impl_; + std::unique_ptr impl_; }; } // aio } // booster diff --git a/booster/booster/callback.h b/booster/booster/callback.h index b21f820f..6c9ae706 100644 --- a/booster/booster/callback.h +++ b/booster/booster/callback.h @@ -164,7 +164,7 @@ namespace booster { {} \ \ template \ - callback(std::auto_ptr ptr) : call_ptr(ptr.release()) \ + callback(std::unique_ptr ptr) : call_ptr(ptr.release()) \ {} \ \ template \ @@ -172,7 +172,7 @@ namespace booster { { call_ptr = c; return *this; } \ \ template \ - callback const &operator=(std::auto_ptr c) \ + callback const &operator=(std::unique_ptr c) \ { call_ptr = 0; call_ptr = c.release(); return *this; } \ \ template \ diff --git a/booster/booster/locale/format.h b/booster/booster/locale/format.h index 884e062d..6a885cfd 100644 --- a/booster/booster/locale/format.h +++ b/booster/booster/locale/format.h @@ -121,7 +121,7 @@ namespace booster { std::ios_base &ios_; struct data; - std::auto_ptr d; + std::unique_ptr d; }; } diff --git a/booster/booster/locale/generator.h b/booster/booster/locale/generator.h index 032a1aef..d9105bdd 100644 --- a/booster/booster/locale/generator.h +++ b/booster/booster/locale/generator.h @@ -220,7 +220,7 @@ namespace booster { void operator=(generator const &); struct data; - std::auto_ptr d; + std::unique_ptr d; }; } diff --git a/booster/booster/locale/localization_backend.h b/booster/booster/locale/localization_backend.h index 5248ce84..1e8a5e60 100644 --- a/booster/booster/locale/localization_backend.h +++ b/booster/booster/locale/localization_backend.h @@ -104,14 +104,14 @@ namespace booster { /// /// Create new localization backend according to current settings. /// - std::auto_ptr get() const; + std::unique_ptr get() const; /// /// Add new backend to the manager, each backend should be uniquely defined by its name. /// /// This library provides: "icu", "posix", "winapi" and "std" backends. /// - void add_backend(std::string const &name,std::auto_ptr backend); + void add_backend(std::string const &name,std::unique_ptr backend); /// /// Clear backend @@ -143,7 +143,7 @@ namespace booster { static localization_backend_manager global(); private: class impl; - std::auto_ptr pimpl_; + std::unique_ptr pimpl_; }; } // locale diff --git a/booster/booster/locale/util.h b/booster/booster/locale/util.h index c9de187a..f63540fe 100644 --- a/booster/booster/locale/util.h +++ b/booster/booster/locale/util.h @@ -176,7 +176,7 @@ namespace util { /// This function creates a \a base_converter that can be used for conversion between UTF-8 and /// unicode code points /// - BOOSTER_API std::auto_ptr create_utf8_converter(); + BOOSTER_API std::unique_ptr create_utf8_converter(); /// /// This function creates a \a base_converter that can be used for conversion between single byte /// character encodings like ISO-8859-1, koi8-r, windows-1255 and Unicode code points, @@ -184,7 +184,7 @@ namespace util { /// If \a encoding is not supported, empty pointer is returned. You should check if /// std::auto_ptr::get() != 0 /// - BOOSTER_API std::auto_ptr create_simple_converter(std::string const &encoding); + BOOSTER_API std::unique_ptr create_simple_converter(std::string const &encoding); /// @@ -199,7 +199,7 @@ namespace util { /// of wide encoding type /// BOOSTER_API - std::locale create_codecvt(std::locale const &in,std::auto_ptr cvt,character_facet_type type); + std::locale create_codecvt(std::locale const &in,std::unique_ptr cvt,character_facet_type type); /// /// Install utf8 codecvt to UTF-16 or UTF-32 into locale \a in and return diff --git a/booster/booster/log.h b/booster/booster/log.h index 09773bab..16fe278e 100644 --- a/booster/booster/log.h +++ b/booster/booster/log.h @@ -104,7 +104,7 @@ namespace log { char const *file_name_; int file_line_; - std::auto_ptr message_; + std::unique_ptr message_; struct data; copy_ptr d; diff --git a/booster/booster/shared_ptr.h b/booster/booster/shared_ptr.h index d4e19dc8..782ee776 100644 --- a/booster/booster/shared_ptr.h +++ b/booster/booster/shared_ptr.h @@ -221,7 +221,7 @@ template class shared_ptr } template - explicit shared_ptr(std::auto_ptr & r): px(r.get()), pn() + explicit shared_ptr(std::unique_ptr & r): px(r.get()), pn() { Y * tmp = r.get(); pn = booster::detail::shared_count(r); @@ -254,7 +254,7 @@ template class shared_ptr template - shared_ptr & operator=( std::auto_ptr & r ) + shared_ptr & operator=( std::unique_ptr & r ) { this_type(r).swap(*this); return *this; diff --git a/booster/booster/smart_ptr/shared_count.h b/booster/booster/smart_ptr/shared_count.h index 4dfe7694..cb82b01f 100644 --- a/booster/booster/smart_ptr/shared_count.h +++ b/booster/booster/smart_ptr/shared_count.h @@ -103,7 +103,7 @@ class shared_count // auto_ptr is special cased to provide the strong guarantee template - explicit shared_count( std::auto_ptr & r ): pi_( new sp_counted_impl_p( r.get() ) ) + explicit shared_count( std::unique_ptr & r ): pi_( new sp_counted_impl_p( r.get() ) ) { r.release(); diff --git a/booster/booster/streambuf.h b/booster/booster/streambuf.h index 2926c902..4b3b9716 100644 --- a/booster/booster/streambuf.h +++ b/booster/booster/streambuf.h @@ -79,7 +79,7 @@ namespace booster { /// /// Assign an io_device to the streambuf transferring an ownership on it /// - void device(std::auto_ptr d); + void device(std::unique_ptr d); /// /// Assign an existing io_device to the streambuf. /// @@ -130,7 +130,7 @@ namespace booster { struct _data; hold_ptr<_data> d; // for future use - std::auto_ptr device_auto_ptr_; + std::unique_ptr device_auto_ptr_; io_device *device_; }; diff --git a/booster/lib/aio/src/acceptor.cpp b/booster/lib/aio/src/acceptor.cpp index 56726fd0..b87eddda 100644 --- a/booster/lib/aio/src/acceptor.cpp +++ b/booster/lib/aio/src/acceptor.cpp @@ -9,6 +9,8 @@ #include "socket_details.h" #include +#include + //#define BOOSTER_AIO_FORCE_POLL @@ -101,7 +103,7 @@ namespace { acceptor *source; async_acceptor(event_handler const &_h,stream_socket *_t,acceptor *_s) : h(_h),target(_t),source(_s) {} - typedef std::auto_ptr pointer; + typedef std::unique_ptr pointer; void operator()(system::error_code const &e) { @@ -122,7 +124,7 @@ void acceptor::async_accept(stream_socket &target,event_handler const &h) if(!dont_block(h)) return; async_acceptor::pointer acceptor(new async_acceptor( h, &target, this )); - on_readable(acceptor); + on_readable(std::move(acceptor)); } diff --git a/booster/lib/aio/src/deadline_timer.cpp b/booster/lib/aio/src/deadline_timer.cpp index fdc45f42..02f1e997 100644 --- a/booster/lib/aio/src/deadline_timer.cpp +++ b/booster/lib/aio/src/deadline_timer.cpp @@ -9,6 +9,8 @@ #include #include +#include + namespace booster { namespace aio { @@ -89,10 +91,10 @@ struct deadline_timer::waiter : public booster::callable wt(new waiter); + std::unique_ptr wt(new waiter); wt->h=h; wt->self = this; - event_id_ = get_io_service().set_timer_event(deadline_,wt); + event_id_ = get_io_service().set_timer_event(deadline_,std::move(wt)); } void deadline_timer::cancel() diff --git a/booster/lib/aio/src/io_service.cpp b/booster/lib/aio/src/io_service.cpp index 9764a220..866374ae 100644 --- a/booster/lib/aio/src/io_service.cpp +++ b/booster/lib/aio/src/io_service.cpp @@ -355,7 +355,7 @@ class event_loop_impl { // The reactor itself so multiple threads // can dispatch events on same reactor // - std::auto_ptr reactor_; + std::unique_ptr reactor_; // // Rest of the data protected by the diff --git a/booster/lib/aio/src/stream_socket.cpp b/booster/lib/aio/src/stream_socket.cpp index 24e7fb7c..c0ae972c 100644 --- a/booster/lib/aio/src/stream_socket.cpp +++ b/booster/lib/aio/src/stream_socket.cpp @@ -11,6 +11,8 @@ #ifndef BOOSTER_WIN32 #include + +#include #endif #ifdef __sun @@ -334,7 +336,7 @@ namespace { async_connector(event_handler const &_h,stream_socket *_s) : h(_h),sock(_s) {} - typedef std::auto_ptr pointer; + typedef std::unique_ptr pointer; void operator()(system::error_code const &e) { @@ -521,7 +523,7 @@ void stream_socket::async_connect(endpoint const &ep,event_handler const &h) connect(ep,e); if(e && would_block(e)) { async_connector::pointer connector(new async_connector(h,this)); - on_writeable(connector); + on_writeable(std::move(connector)); } else { get_io_service().post(h,e); diff --git a/booster/lib/function/test/test_callback.cpp b/booster/lib/function/test/test_callback.cpp index a3d86a36..6ee3b190 100644 --- a/booster/lib/function/test/test_callback.cpp +++ b/booster/lib/function/test/test_callback.cpp @@ -8,6 +8,7 @@ #include #include "test.h" #include +#include bool foov_called; void foov() { @@ -101,8 +102,8 @@ int main() TEST(fcnt2()==4); { - std::auto_ptr mc(new mycall()); - callback f(mc); + std::unique_ptr mc(new mycall()); + callback f(std::move(mc)); f(); TEST(mycall_called); mycall_called=false; } @@ -113,9 +114,9 @@ int main() TEST(mycall_called); mycall_called=false; } { - std::auto_ptr mc(new mycall()); + std::unique_ptr mc(new mycall()); callback f; - f=mc; + f=std::move(mc); f(); TEST(mycall_called); mycall_called=false; } @@ -127,8 +128,8 @@ int main() TEST(mycall_called); mycall_called=false; } { - std::auto_ptr mc(new myicall()); - callback f(mc); + std::unique_ptr mc(new myicall()); + callback f(std::move(mc)); f(2); TEST(mycall_called); mycall_called=false; } @@ -139,9 +140,9 @@ int main() TEST(mycall_called); mycall_called=false; } { - std::auto_ptr mc(new myicall()); + std::unique_ptr mc(new myicall()); callback f; - f=mc; + f=std::move(mc); f(2); TEST(mycall_called); mycall_called=false; } diff --git a/booster/lib/iostreams/src/streambuf.cpp b/booster/lib/iostreams/src/streambuf.cpp index 3e40e0e5..7c96a7d5 100644 --- a/booster/lib/iostreams/src/streambuf.cpp +++ b/booster/lib/iostreams/src/streambuf.cpp @@ -1,6 +1,8 @@ #define BOOSTER_SOURCE #include +#include + namespace booster { struct streambuf::_data{}; @@ -108,10 +110,10 @@ namespace booster { device_ = 0; device_auto_ptr_.reset(); } - void streambuf::device(std::auto_ptr d) + void streambuf::device(std::unique_ptr d) { reset_device(); - device_auto_ptr_=d; + device_auto_ptr_=std::move(d); device_ = device_auto_ptr_.get(); } void streambuf::set_buffer_size(size_t n) diff --git a/booster/lib/locale/src/encoding/codepage.cpp b/booster/lib/locale/src/encoding/codepage.cpp index 3c2cd35a..ab63f4bd 100644 --- a/booster/lib/locale/src/encoding/codepage.cpp +++ b/booster/lib/locale/src/encoding/codepage.cpp @@ -39,7 +39,7 @@ namespace booster { char const *from_charset, method_type how) { - std::auto_ptr cvt; + std::unique_ptr cvt; #ifdef BOOSTER_LOCALE_WITH_ICONV cvt.reset(new iconv_between()); if(cvt->open(to_charset,from_charset,how)) @@ -65,7 +65,7 @@ namespace booster { char const *charset, method_type how) { - std::auto_ptr > cvt; + std::unique_ptr > cvt; #ifdef BOOSTER_LOCALE_WITH_ICONV cvt.reset(new iconv_to_utf()); if(cvt->open(charset,how)) @@ -91,7 +91,7 @@ namespace booster { char const *charset, method_type how) { - std::auto_ptr > cvt; + std::unique_ptr > cvt; #ifdef BOOSTER_LOCALE_WITH_ICONV cvt.reset(new iconv_from_utf()); if(cvt->open(charset,how)) diff --git a/booster/lib/locale/src/encoding/uconv_codepage.ipp b/booster/lib/locale/src/encoding/uconv_codepage.ipp index 146102e2..413e3b79 100644 --- a/booster/lib/locale/src/encoding/uconv_codepage.ipp +++ b/booster/lib/locale/src/encoding/uconv_codepage.ipp @@ -61,8 +61,8 @@ namespace impl { typedef impl_icu::icu_std_converter from_type; typedef impl_icu::icu_std_converter to_type; - std::auto_ptr cvt_from_; - std::auto_ptr cvt_to_; + std::unique_ptr cvt_from_; + std::unique_ptr cvt_to_; }; @@ -105,8 +105,8 @@ namespace impl { typedef impl_icu::icu_std_converter from_type; typedef impl_icu::icu_std_converter to_type; - std::auto_ptr cvt_from_; - std::auto_ptr cvt_to_; + std::unique_ptr cvt_from_; + std::unique_ptr cvt_to_; }; @@ -146,8 +146,8 @@ namespace impl { typedef impl_icu::icu_std_converter from_type; typedef impl_icu::icu_std_converter to_type; - std::auto_ptr cvt_from_; - std::auto_ptr cvt_to_; + std::unique_ptr cvt_from_; + std::unique_ptr cvt_to_; }; diff --git a/booster/lib/locale/src/icu/boundary.cpp b/booster/lib/locale/src/icu/boundary.cpp index 2fb33ea0..f776e440 100644 --- a/booster/lib/locale/src/icu/boundary.cpp +++ b/booster/lib/locale/src/icu/boundary.cpp @@ -15,6 +15,8 @@ #include #include +#include + #include "cdata.h" #include "all_generator.h" #include "icu_util.h" @@ -103,10 +105,10 @@ index_type map_direct(boundary_type t,icu::BreakIterator *it,int reserve) return indx; } -std::auto_ptr get_iterator(boundary_type t,icu::Locale const &loc) +std::unique_ptr get_iterator(boundary_type t,icu::Locale const &loc) { UErrorCode err=U_ZERO_ERROR; - std::auto_ptr bi; + std::unique_ptr bi; switch(t) { case character: bi.reset(icu::BreakIterator::createCharacterInstance(loc,err)); @@ -126,7 +128,7 @@ std::auto_ptr get_iterator(boundary_type t,icu::Locale const check_and_throw_icu_error(err); if(!bi.get()) throw booster::runtime_error("Failed to create break iterator"); - return bi; + return std::move(bi); } @@ -134,7 +136,7 @@ template index_type do_map(boundary_type t,CharType const *begin,CharType const *end,icu::Locale const &loc,std::string const &encoding) { index_type indx; - std::auto_ptr bi(get_iterator(t,loc)); + std::unique_ptr bi(get_iterator(t,loc)); #if U_ICU_VERSION_MAJOR_NUM*100 + U_ICU_VERSION_MINOR_NUM >= 306 UErrorCode err=U_ZERO_ERROR; diff --git a/booster/lib/locale/src/icu/codecvt.cpp b/booster/lib/locale/src/icu/codecvt.cpp index 8ca10c7a..1fbeee4e 100644 --- a/booster/lib/locale/src/icu/codecvt.cpp +++ b/booster/lib/locale/src/icu/codecvt.cpp @@ -21,6 +21,7 @@ #endif #include "icu_util.h" +#include #include namespace booster { namespace locale { @@ -117,9 +118,9 @@ namespace impl_icu { int max_len_; }; - std::auto_ptr create_uconv_converter(std::string const &encoding) + std::unique_ptr create_uconv_converter(std::string const &encoding) { - std::auto_ptr cvt; + std::unique_ptr cvt; try { cvt.reset(new uconv_converter(encoding)); } @@ -127,7 +128,7 @@ namespace impl_icu { { // no encoding so we return empty pointer } - return cvt; + return std::move(cvt); } std::locale create_codecvt(std::locale const &in,std::string const &encoding,character_facet_type type) @@ -139,7 +140,7 @@ namespace impl_icu { return util::create_simple_codecvt(in,encoding,type); } catch(booster::locale::conv::invalid_charset_error const &) { - std::auto_ptr cvt; + std::unique_ptr cvt; try { cvt = create_uconv_converter(encoding); } @@ -147,7 +148,7 @@ namespace impl_icu { { cvt.reset(new util::base_converter()); } - return util::create_codecvt(in,cvt,type); + return util::create_codecvt(in,std::move(cvt),type); } } diff --git a/booster/lib/locale/src/icu/codecvt.h b/booster/lib/locale/src/icu/codecvt.h index f37ef7e2..d4fb82ad 100644 --- a/booster/lib/locale/src/icu/codecvt.h +++ b/booster/lib/locale/src/icu/codecvt.h @@ -14,7 +14,7 @@ namespace booster { namespace locale { namespace impl_icu { BOOSTER_API - std::auto_ptr create_uconv_converter(std::string const &encoding); + std::unique_ptr create_uconv_converter(std::string const &encoding); } // impl_icu } // locale diff --git a/booster/lib/locale/src/icu/date_time.cpp b/booster/lib/locale/src/icu/date_time.cpp index 11f112dd..15a0107d 100644 --- a/booster/lib/locale/src/icu/date_time.cpp +++ b/booster/lib/locale/src/icu/date_time.cpp @@ -217,7 +217,7 @@ namespace impl_icu { // fieldDifference has side effect of moving calendar (WTF?) // So we clone it for performing this operation // - std::auto_ptr self(calendar_->clone()); + std::unique_ptr self(calendar_->clone()); calendar_impl const *other_cal=dynamic_cast(other_ptr); if(other_cal){ diff --git a/booster/lib/locale/src/icu/formatter.cpp b/booster/lib/locale/src/icu/formatter.cpp index 65622814..300e1863 100644 --- a/booster/lib/locale/src/icu/formatter.cpp +++ b/booster/lib/locale/src/icu/formatter.cpp @@ -182,9 +182,9 @@ namespace locale { return do_parse(str,value); } - date_format(std::auto_ptr fmt,std::string codepage) : + date_format(std::unique_ptr fmt,std::string codepage) : cvt_(codepage), - aicu_fmt_(fmt) + aicu_fmt_(std::move(fmt)) { icu_fmt_ = aicu_fmt_.get(); } @@ -227,13 +227,13 @@ namespace locale { } icu_std_converter cvt_; - std::auto_ptr aicu_fmt_; + std::unique_ptr aicu_fmt_; icu::DateFormat *icu_fmt_; }; icu::UnicodeString strftime_to_icu_full(icu::DateFormat *dfin,char const *alt) { - std::auto_ptr df(dfin); + std::unique_ptr df(dfin); icu::SimpleDateFormat *sdf=dynamic_cast(df.get()); icu::UnicodeString tmp; if(sdf) { @@ -374,14 +374,14 @@ namespace locale { } template - std::auto_ptr > generate_formatter( + std::unique_ptr > generate_formatter( std::ios_base &ios, icu::Locale const &locale, std::string const &encoding) { using namespace booster::locale::flags; - std::auto_ptr > fmt; + std::unique_ptr > fmt; ios_info &info=ios_info::get(ios); uint64_t disp = info.display_flags(); @@ -389,7 +389,7 @@ namespace locale { if(disp == posix) - return fmt; + return std::move(fmt); UErrorCode err=U_ZERO_ERROR; @@ -455,7 +455,7 @@ namespace locale { case strftime: { using namespace flags; - std::auto_ptr adf; + std::unique_ptr adf; icu::DateFormat *df = 0; icu::SimpleDateFormat *sdf = cache.date_formatter(); // try to use cached first @@ -555,7 +555,7 @@ namespace locale { adf.reset(new icu::SimpleDateFormat(fmt,locale,err)); } if(U_FAILURE(err)) - return fmt; + return std::move(fmt); df = adf.get(); } @@ -563,26 +563,26 @@ namespace locale { // Depending if we own formatter or not if(adf.get()) - fmt.reset(new date_format(adf,encoding)); + fmt.reset(new date_format(std::move(adf),encoding)); else fmt.reset(new date_format(df,encoding)); } break; } - return fmt; + return std::move(fmt); } template<> - std::auto_ptr > formatter::create(std::ios_base &ios,icu::Locale const &l,std::string const &e) + std::unique_ptr > formatter::create(std::ios_base &ios,icu::Locale const &l,std::string const &e) { return generate_formatter(ios,l,e); } template<> - std::auto_ptr > formatter::create(std::ios_base &ios,icu::Locale const &l,std::string const &e) + std::unique_ptr > formatter::create(std::ios_base &ios,icu::Locale const &l,std::string const &e) { return generate_formatter(ios,l,e); } diff --git a/booster/lib/locale/src/icu/formatter.h b/booster/lib/locale/src/icu/formatter.h index f1bd8b30..d99dd4ca 100644 --- a/booster/lib/locale/src/icu/formatter.h +++ b/booster/lib/locale/src/icu/formatter.h @@ -87,7 +87,7 @@ namespace impl_icu { /// /// Would create a new spelling formatter only once. /// - static std::auto_ptr create(std::ios_base &ios,icu::Locale const &l,std::string const &enc); + static std::unique_ptr create(std::ios_base &ios,icu::Locale const &l,std::string const &enc); virtual ~formatter() { @@ -98,13 +98,13 @@ namespace impl_icu { /// Specialization for real implementation /// template<> - std::auto_ptr > formatter::create(std::ios_base &ios,icu::Locale const &l,std::string const &enc); + std::unique_ptr > formatter::create(std::ios_base &ios,icu::Locale const &l,std::string const &enc); /// /// Specialization for real implementation /// template<> - std::auto_ptr > formatter::create(std::ios_base &ios,icu::Locale const &l,std::string const &e); + std::unique_ptr > formatter::create(std::ios_base &ios,icu::Locale const &l,std::string const &e); #ifdef BOOSTER_HAS_CHAR16_T /// diff --git a/booster/lib/locale/src/icu/numeric.cpp b/booster/lib/locale/src/icu/numeric.cpp index 940c5352..5191dbd6 100644 --- a/booster/lib/locale/src/icu/numeric.cpp +++ b/booster/lib/locale/src/icu/numeric.cpp @@ -115,7 +115,7 @@ class num_format : public std::num_put, protected num_base typedef std::basic_string string_type; typedef CharType char_type; typedef formatter formatter_type; - typedef std::auto_ptr formatter_ptr; + typedef std::unique_ptr formatter_ptr; num_format(cdata const &d,size_t refs = 0) : std::num_put(refs), @@ -220,7 +220,7 @@ class num_parse : public std::num_get, protected num_base typedef std::basic_string string_type; typedef CharType char_type; typedef formatter formatter_type; - typedef std::auto_ptr formatter_ptr; + typedef std::unique_ptr formatter_ptr; typedef std::basic_istream stream_type; virtual iter_type do_get(iter_type in, iter_type end, std::ios_base &ios,std::ios_base::iostate &err,long &val) const diff --git a/booster/lib/locale/src/icu/predefined_formatters.h b/booster/lib/locale/src/icu/predefined_formatters.h index c9f663ff..1c8c3cad 100644 --- a/booster/lib/locale/src/icu/predefined_formatters.h +++ b/booster/lib/locale/src/icu/predefined_formatters.h @@ -43,7 +43,7 @@ namespace locale { for(int i=0;i<4;i++) { - std::auto_ptr fmt(icu::DateFormat::createDateInstance(styles[i],locale)); + std::unique_ptr fmt(icu::DateFormat::createDateInstance(styles[i],locale)); icu::SimpleDateFormat *sfmt = dynamic_cast(fmt.get()); if(sfmt) { sfmt->toPattern(date_format_[i]); @@ -51,7 +51,7 @@ namespace locale { } for(int i=0;i<4;i++) { - std::auto_ptr fmt(icu::DateFormat::createTimeInstance(styles[i],locale)); + std::unique_ptr fmt(icu::DateFormat::createTimeInstance(styles[i],locale)); icu::SimpleDateFormat *sfmt = dynamic_cast(fmt.get()); if(sfmt) { sfmt->toPattern(time_format_[i]); @@ -60,7 +60,7 @@ namespace locale { for(int i=0;i<4;i++) { for(int j=0;j<4;j++) { - std::auto_ptr fmt( + std::unique_ptr fmt( icu::DateFormat::createDateTimeInstance(styles[i],styles[j],locale)); icu::SimpleDateFormat *sfmt = dynamic_cast(fmt.get()); if(sfmt) { @@ -89,7 +89,7 @@ namespace locale { if(ptr) return ptr; UErrorCode err=U_ZERO_ERROR; - std::auto_ptr ap; + std::unique_ptr ap; switch(type) { case fmt_number: @@ -155,7 +155,7 @@ namespace locale { if(p) return p; - std::auto_ptr fmt(icu::DateFormat::createDateTimeInstance( + std::unique_ptr fmt(icu::DateFormat::createDateTimeInstance( icu::DateFormat::kMedium, icu::DateFormat::kMedium, locale_)); diff --git a/booster/lib/locale/src/posix/codecvt.cpp b/booster/lib/locale/src/posix/codecvt.cpp index 7af3f9f8..61ffb0b7 100644 --- a/booster/lib/locale/src/posix/codecvt.cpp +++ b/booster/lib/locale/src/posix/codecvt.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "codecvt.h" @@ -211,16 +212,16 @@ namespace impl_posix { iconv_t from_utf_; }; - std::auto_ptr create_iconv_converter(std::string const &encoding) + std::unique_ptr create_iconv_converter(std::string const &encoding) { - std::auto_ptr cvt; + std::unique_ptr cvt; try { cvt.reset(new mb2_iconv_converter(encoding)); } catch(std::exception const &e) { // Nothing to do, just retrun empty cvt } - return cvt; + return std::move(cvt); } #else // no iconv @@ -240,9 +241,9 @@ namespace impl_posix { return util::create_simple_codecvt(in,encoding,type); } catch(conv::invalid_charset_error const &) { - std::auto_ptr cvt; + std::unique_ptr cvt; cvt = create_iconv_converter(encoding); - return util::create_codecvt(in,cvt,type); + return util::create_codecvt(in,std::move(cvt),type); } } diff --git a/booster/lib/locale/src/posix/codecvt.h b/booster/lib/locale/src/posix/codecvt.h index 7cbd34bb..a17bf156 100644 --- a/booster/lib/locale/src/posix/codecvt.h +++ b/booster/lib/locale/src/posix/codecvt.h @@ -17,7 +17,7 @@ namespace booster { namespace locale { namespace impl_posix { BOOSTER_API - std::auto_ptr create_iconv_converter(std::string const &encoding); + std::unique_ptr create_iconv_converter(std::string const &encoding); } // impl_posix } // locale diff --git a/booster/lib/locale/src/shared/localization_backend.cpp b/booster/lib/locale/src/shared/localization_backend.cpp index dc110a2c..21b6f595 100644 --- a/booster/lib/locale/src/shared/localization_backend.cpp +++ b/booster/lib/locale/src/shared/localization_backend.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #ifdef BOOSTER_LOCALE_WITH_ICU @@ -46,15 +47,15 @@ namespace booster { default_backends_(32,-1) { } - std::auto_ptr get() const + std::unique_ptr get() const { std::vector > backends; for(unsigned i=0;i res(new actual_backend(backends,default_backends_)); - return res; + std::unique_ptr res(new actual_backend(backends,default_backends_)); + return std::move(res); } - void add_backend(std::string const &name,std::auto_ptr backend_ptr) + void add_backend(std::string const &name,std::unique_ptr backend_ptr) { booster::shared_ptr sptr(backend_ptr); if(all_backends_.empty()) { @@ -178,14 +179,14 @@ namespace booster { return *this; } - std::auto_ptr localization_backend_manager::get() const + std::unique_ptr localization_backend_manager::get() const { return pimpl_->get(); } - void localization_backend_manager::add_backend(std::string const &name,std::auto_ptr backend) + void localization_backend_manager::add_backend(std::string const &name,std::unique_ptr backend) { - pimpl_->add_backend(name,backend); + pimpl_->add_backend(name,std::move(backend)); } void localization_backend_manager::remove_all_backends() { @@ -217,15 +218,15 @@ namespace booster { struct init { init() { localization_backend_manager mgr; - std::auto_ptr backend; + std::unique_ptr backend; #ifdef BOOSTER_LOCALE_WITH_ICU backend.reset(impl_icu::create_localization_backend()); - mgr.add_backend("icu",backend); + mgr.add_backend("icu",std::move(backend)); #endif #ifndef BOOSTER_LOCALE_NO_POSIX_BACKEND backend.reset(impl_posix::create_localization_backend()); - mgr.add_backend("posix",backend); + mgr.add_backend("posix",std::move(backend)); #endif #ifndef BOOSTER_LOCALE_NO_WINAPI_BACKEND @@ -235,7 +236,7 @@ namespace booster { #ifndef BOOSTER_LOCALE_NO_STD_BACKEND backend.reset(impl_std::create_localization_backend()); - mgr.add_backend("std",backend); + mgr.add_backend("std",std::move(backend)); #endif localization_backend_manager::global(mgr); diff --git a/booster/lib/locale/src/shared/message.cpp b/booster/lib/locale/src/shared/message.cpp index 6d32cf6c..4a4c18f1 100644 --- a/booster/lib/locale/src/shared/message.cpp +++ b/booster/lib/locale/src/shared/message.cpp @@ -625,7 +625,7 @@ namespace booster { key_conversion_required_ = sizeof(CharType) == 1 && compare_encodings(locale_encoding,key_encoding)!=0; - std::auto_ptr mo; + std::unique_ptr mo; if(callback) { std::vector vfile = callback(file_name,locale_encoding); @@ -649,7 +649,7 @@ namespace booster { throw booster::runtime_error("Invalid mo-format, encoding is not specified"); if(!plural.empty()) { - std::auto_ptr ptr=lambda::compile(plural.c_str()); + std::unique_ptr ptr=lambda::compile(plural.c_str()); plural_forms_[id] = ptr; } diff --git a/booster/lib/locale/src/shared/mo_lambda.cpp b/booster/lib/locale/src/shared/mo_lambda.cpp index 6e51245f..b30a6e39 100644 --- a/booster/lib/locale/src/shared/mo_lambda.cpp +++ b/booster/lib/locale/src/shared/mo_lambda.cpp @@ -9,6 +9,8 @@ #include #include +#include + namespace booster { namespace locale { namespace gnu_gettext { @@ -29,7 +31,7 @@ namespace { // anon struct unary : public plural { unary(plural_ptr ptr) : - op1(ptr) + op1(std::move(ptr)) { } protected: @@ -40,8 +42,8 @@ namespace { // anon struct binary : public plural { binary(plural_ptr p1,plural_ptr p2) : - op1(p1), - op2(p2) + op1(std::move(p1)), + op2(std::move(p2)) { } protected: @@ -169,9 +171,9 @@ namespace { // anon struct conditional : public plural { conditional(plural_ptr p1,plural_ptr p2,plural_ptr p3) : - op1(p1), - op2(p2), - op3(p3) + op1(std::move(p1)), + op2(std::move(p2)), + op3(std::move(p3)) { } virtual int operator()(int n) const @@ -183,7 +185,7 @@ namespace { // anon plural_ptr op1_copy(op1->clone()); plural_ptr op2_copy(op2->clone()); plural_ptr op3_copy(op3->clone()); - return new conditional(op1_copy,op2_copy,op3_copy); + return new conditional(std::move(op1_copy),std::move(op2_copy),std::move(op3_copy)); } private: plural_ptr op1,op2,op3; @@ -194,24 +196,24 @@ namespace { // anon { switch(value) { - case '/': return plural_ptr(new div(left,right)); - case '*': return plural_ptr(new mul(left,right)); - case '%': return plural_ptr(new mod(left,right)); - case '+': return plural_ptr(new add(left,right)); - case '-': return plural_ptr(new sub(left,right)); - case SHL: return plural_ptr(new shl(left,right)); - case SHR: return plural_ptr(new shr(left,right)); - case '>': return plural_ptr(new gt(left,right)); - case '<': return plural_ptr(new lt(left,right)); - case GTE: return plural_ptr(new gte(left,right)); - case LTE: return plural_ptr(new lte(left,right)); - case EQ: return plural_ptr(new eq(left,right)); - case NEQ: return plural_ptr(new neq(left,right)); - case '&': return plural_ptr(new bin_and(left,right)); - case '^': return plural_ptr(new bin_xor(left,right)); - case '|': return plural_ptr(new bin_or (left,right)); - case AND: return plural_ptr(new l_and(left,right)); - case OR: return plural_ptr(new l_or(left,right)); + case '/': return plural_ptr(new div(std::move(left),std::move(right))); + case '*': return plural_ptr(new mul(std::move(left),std::move(right))); + case '%': return plural_ptr(new mod(std::move(left),std::move(right))); + case '+': return plural_ptr(new add(std::move(left),std::move(right))); + case '-': return plural_ptr(new sub(std::move(left),std::move(right))); + case SHL: return plural_ptr(new shl(std::move(left),std::move(right))); + case SHR: return plural_ptr(new shr(std::move(left),std::move(right))); + case '>': return plural_ptr(new gt(std::move(left),std::move(right))); + case '<': return plural_ptr(new lt(std::move(left),std::move(right))); + case GTE: return plural_ptr(new gte(std::move(left),std::move(right))); + case LTE: return plural_ptr(new lte(std::move(left),std::move(right))); + case EQ: return plural_ptr(new eq(std::move(left),std::move(right))); + case NEQ: return plural_ptr(new neq(std::move(left),std::move(right))); + case '&': return plural_ptr(new bin_and(std::move(left),std::move(right))); + case '^': return plural_ptr(new bin_xor(std::move(left),std::move(right))); + case '|': return plural_ptr(new bin_or (std::move(left),std::move(right))); + case AND: return plural_ptr(new l_and(std::move(left),std::move(right))); + case OR: return plural_ptr(new l_or(std::move(left),std::move(right))); default: return plural_ptr(); } @@ -305,7 +307,7 @@ namespace { // anon if(res.get() && t.next()!=END) { return plural_ptr(); }; - return res; + return std::move(res); } private: @@ -319,7 +321,7 @@ namespace { // anon return plural_ptr(); if(t.get()!=')') return plural_ptr(); - return op; + return std::move(op); } else if(t.next()==NUM) { int value; @@ -343,11 +345,11 @@ namespace { // anon return plural_ptr(); switch(op) { case '-': - return plural_ptr(new minus(op1)); + return plural_ptr(new minus(std::move(op1))); case '!': - return plural_ptr(new l_not(op1)); + return plural_ptr(new l_not(std::move(op1))); case '~': - return plural_ptr(new bin_not(op1)); + return plural_ptr(new bin_not(std::move(op1))); default: return plural_ptr(); } @@ -383,9 +385,9 @@ namespace { // anon return plural_ptr(); } else { - return cond; + return std::move(cond); } - return plural_ptr(new conditional(cond,case1,case2)); + return plural_ptr(new conditional(std::move(cond),std::move(case1),std::move(case2))); } tokenizer &t; diff --git a/booster/lib/locale/src/shared/mo_lambda.h b/booster/lib/locale/src/shared/mo_lambda.h index 0173215e..09fbe0db 100644 --- a/booster/lib/locale/src/shared/mo_lambda.h +++ b/booster/lib/locale/src/shared/mo_lambda.h @@ -24,7 +24,7 @@ namespace booster { } }; - typedef std::auto_ptr plural_ptr; + typedef std::unique_ptr plural_ptr; plural_ptr compile(char const *c_expression); diff --git a/booster/lib/locale/src/util/codecvt_converter.cpp b/booster/lib/locale/src/util/codecvt_converter.cpp index cf975a8f..a6422dd5 100644 --- a/booster/lib/locale/src/util/codecvt_converter.cpp +++ b/booster/lib/locale/src/util/codecvt_converter.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -260,48 +261,48 @@ namespace util { return 0; } - std::auto_ptr create_simple_converter(std::string const &encoding) + std::unique_ptr create_simple_converter(std::string const &encoding) { - std::auto_ptr res; + std::unique_ptr res; if(check_is_simple_encoding(encoding)) res.reset(new simple_converter(encoding)); - return res; + return std::move(res); } - std::auto_ptr create_utf8_converter() + std::unique_ptr create_utf8_converter() { - std::auto_ptr res(new utf8_converter()); - return res; + std::unique_ptr res(new utf8_converter()); + return std::move(res); } template class code_converter : public generic_codecvt > { public: - code_converter(std::auto_ptr cvt,size_t refs = 0) : + code_converter(std::unique_ptr cvt,size_t refs = 0) : generic_codecvt >(refs), - cvt_(cvt) + cvt_(std::move(cvt)) { max_len_ = cvt_->max_len(); thread_safe_ = cvt_->is_thread_safe(); } - typedef std::auto_ptr state_type; + typedef std::unique_ptr state_type; int max_encoding_length() const { return max_len_; } - std::auto_ptr initial_state(generic_codecvt_base::initial_convertion_state /* unused */) const + std::unique_ptr initial_state(generic_codecvt_base::initial_convertion_state /* unused */) const { - std::auto_ptr r; + std::unique_ptr r; if(!thread_safe_) r.reset(cvt_->clone()); - return r; + return std::move(r); } - utf::code_point to_unicode(std::auto_ptr &ptr,char const *&begin,char const *end) const + utf::code_point to_unicode(std::unique_ptr &ptr,char const *&begin,char const *end) const { if(thread_safe_) return cvt_->to_unicode(begin,end); @@ -309,7 +310,7 @@ namespace util { return ptr->to_unicode(begin,end); } - utf::code_point from_unicode(std::auto_ptr &ptr,utf::code_point u,char *begin,char const *end) const + utf::code_point from_unicode(std::unique_ptr &ptr,utf::code_point u,char *begin,char const *end) const { if(thread_safe_) return cvt_->from_unicode(u,begin,end); @@ -318,21 +319,21 @@ namespace util { } private: - std::auto_ptr cvt_; + std::unique_ptr cvt_; int max_len_; bool thread_safe_; }; - std::locale create_codecvt(std::locale const &in,std::auto_ptr cvt,character_facet_type type) + std::locale create_codecvt(std::locale const &in,std::unique_ptr cvt,character_facet_type type) { if(!cvt.get()) cvt.reset(new base_converter()); switch(type) { case char_facet: - return std::locale(in,new code_converter(cvt)); + return std::locale(in,new code_converter(std::move(cvt))); case wchar_t_facet: - return std::locale(in,new code_converter(cvt)); + return std::locale(in,new code_converter(std::move(cvt))); #if defined(BOOSTER_HAS_CHAR16_T) && !defined(BOOSTER_NO_CHAR16_T_CODECVT) case char16_t_facet: return std::locale(in,new code_converter(cvt)); diff --git a/booster/lib/locale/src/util/gregorian.cpp b/booster/lib/locale/src/util/gregorian.cpp index 69fc6457..549b2ab7 100644 --- a/booster/lib/locale/src/util/gregorian.cpp +++ b/booster/lib/locale/src/util/gregorian.cpp @@ -671,7 +671,7 @@ namespace util { { if(diff == 0) return 0; - std::auto_ptr self(clone()); + std::unique_ptr self(clone()); self->adjust_value(p,move,diff); if(diff > 0){ if(self->time_ > other->time_) @@ -692,7 +692,7 @@ namespace util { /// virtual int difference(abstract_calendar const *other_cal,period::marks::period_mark p) const { - std::auto_ptr keeper; + std::unique_ptr keeper; gregorian_calendar const *other = dynamic_cast(other_cal); if(!other) { keeper.reset(clone()); diff --git a/booster/lib/locale/test/test_codepage_converter.cpp b/booster/lib/locale/test/test_codepage_converter.cpp index fa3002c8..5b270092 100644 --- a/booster/lib/locale/test/test_codepage_converter.cpp +++ b/booster/lib/locale/test/test_codepage_converter.cpp @@ -17,6 +17,8 @@ #include +#include + char *make2(unsigned v) { static unsigned char buf[3] = {0}; @@ -80,7 +82,7 @@ bool test_incomplete(booster::locale::util::base_converter &cvt,unsigned codepoi #define TEST_FROM(str,codepoint) TEST(test_from(*cvt,codepoint,str)) #define TEST_INC(codepoint,len) TEST(test_incomplete(*cvt,codepoint,len)) -void test_shiftjis(std::auto_ptr cvt) +void test_shiftjis(std::unique_ptr cvt) { std::cout << "- Correct" << std::endl; TEST_TO("a",'a'); @@ -113,7 +115,7 @@ int main() try { using namespace booster::locale::util; - std::auto_ptr cvt; + std::unique_ptr cvt; std::cout << "Test UTF-8" << std::endl; std::cout << "- From UTF-8" << std::endl; @@ -281,7 +283,7 @@ int main() cvt = booster::locale::impl_icu::create_uconv_converter("Shift-JIS"); TEST(cvt.get()); - test_shiftjis(cvt); + test_shiftjis(std::move(cvt)); #endif #if defined(BOOSTER_LOCALE_WITH_ICONV) && !defined(BOOSTER_LOCALE_NO_POSIX_BACKEND) @@ -289,7 +291,7 @@ int main() cvt = booster::locale::impl_posix::create_iconv_converter("Shift-JIS"); if(cvt.get()) { - test_shiftjis(cvt); + test_shiftjis(std::move(cvt)); } else { std::cout<< "- Shift-JIS is not supported!" << std::endl; diff --git a/booster/lib/log/src/log.cpp b/booster/lib/log/src/log.cpp index b26a27e5..0e0ce762 100644 --- a/booster/lib/log/src/log.cpp +++ b/booster/lib/log/src/log.cpp @@ -18,6 +18,7 @@ #include "../../locale/src/util/timezone.h" #include #include +#include #include #include @@ -68,7 +69,7 @@ namespace log { module_(other.module_), file_name_(other.file_name_), file_line_(other.file_line_), - message_(other.message_) + message_(std::move(other.message_)) { } message &message::operator=(message &other) @@ -78,7 +79,7 @@ namespace log { module_ = other.module_; file_name_=other.file_name_; file_line_=other.file_line_; - message_=other.message_; + message_=std::move(other.message_); } return *this; } diff --git a/booster/lib/thread/src/pthread.cpp b/booster/lib/thread/src/pthread.cpp index fcae9319..64014adc 100644 --- a/booster/lib/thread/src/pthread.cpp +++ b/booster/lib/thread/src/pthread.cpp @@ -42,7 +42,7 @@ namespace booster { extern "C" void *booster_thread_func(void *p) { - std::auto_ptr caller(reinterpret_cast(p)); + std::unique_ptr caller(reinterpret_cast(p)); try { thread_function_type &func = *caller; func(); diff --git a/cppcms/applications_pool.h b/cppcms/applications_pool.h index 24ae9251..5efadf7e 100644 --- a/cppcms/applications_pool.h +++ b/cppcms/applications_pool.h @@ -155,7 +155,7 @@ namespace cppcms { /// /// Returns newly created instance of an application. /// - virtual std::auto_ptr operator()(service &) const = 0; + virtual std::unique_ptr operator()(service &) const = 0; virtual ~factory(){} }; @@ -167,7 +167,7 @@ namespace cppcms { /// /// \deprecated Use mount(booster::shared_ptr gen,int application_options) instead /// - void mount(std::auto_ptr aps); + void mount(std::unique_ptr aps); /// /// Mount an application factory \a app by mount_point \a point application matching and @@ -177,7 +177,7 @@ namespace cppcms { /// /// \deprecated Use mount(booster::shared_ptr gen,mount_point const &point,int application_options) instead /// - void mount(std::auto_ptr aps,mount_point const &point); + void mount(std::unique_ptr aps,mount_point const &point); /// /// Mount an asynchronous application \a app for processing of any incoming requests. Application @@ -267,10 +267,10 @@ namespace cppcms { template struct simple_factory0 : public applications_pool::factory { - std::auto_ptr operator()(service &s) const + std::unique_ptr operator()(service &s) const { - std::auto_ptr app(new T(s)); - return app; + std::unique_ptr app(new T(s)); + return std::move(app); } }; template @@ -278,10 +278,10 @@ namespace cppcms { { simple_factory1(P1 p1) : p1_(p1) {} P1 p1_; - std::auto_ptr operator()(service &s) const + std::unique_ptr operator()(service &s) const { - std::auto_ptr app(new T(s,p1_)); - return app; + std::unique_ptr app(new T(s,p1_)); + return std::move(app); } }; template @@ -290,10 +290,10 @@ namespace cppcms { simple_factory2(P1 p1,P2 p2) : p1_(p1),p2_(p2) {} P1 p1_; P2 p2_; - std::auto_ptr operator()(service &s) const + std::unique_ptr operator()(service &s) const { - std::auto_ptr app(new T(s,p1_,p2_)); - return app; + std::unique_ptr app(new T(s,p1_,p2_)); + return std::move(app); } }; } // details @@ -307,10 +307,10 @@ namespace cppcms { /// \deprecated Use create_pool /// template - std::auto_ptr applications_factory() + std::unique_ptr applications_factory() { - std::auto_ptr f(new details::simple_factory0); - return f; + std::unique_ptr f(new details::simple_factory0); + return std::move(f); } /// @@ -320,10 +320,10 @@ namespace cppcms { /// \deprecated Use create_pool /// template - std::auto_ptr applications_factory(P1 p1) + std::unique_ptr applications_factory(P1 p1) { - std::auto_ptr f(new details::simple_factory1(p1)); - return f; + std::unique_ptr f(new details::simple_factory1(p1)); + return std::move(f); } /// @@ -333,10 +333,10 @@ namespace cppcms { /// \deprecated Use create_pool /// template - std::auto_ptr applications_factory(P1 p1,P2 p2) + std::unique_ptr applications_factory(P1 p1,P2 p2) { - std::auto_ptr f(new details::simple_factory2(p1,p2)); - return f; + std::unique_ptr f(new details::simple_factory2(p1,p2)); + return std::move(f); } /// \cond INTERNAL diff --git a/cppcms/archive_traits.h b/cppcms/archive_traits.h index 7fd561c3..6814a5b7 100644 --- a/cppcms/archive_traits.h +++ b/cppcms/archive_traits.h @@ -400,7 +400,7 @@ CPPCMS_ARCHIVE_SMART_POINTER(booster::shared_ptr) CPPCMS_ARCHIVE_SMART_POINTER(booster::hold_ptr) CPPCMS_ARCHIVE_SMART_POINTER(booster::copy_ptr) CPPCMS_ARCHIVE_SMART_POINTER(booster::clone_ptr) -CPPCMS_ARCHIVE_SMART_POINTER(std::auto_ptr) +CPPCMS_ARCHIVE_SMART_POINTER(std::unique_ptr) CPPCMS_ARCHIVE_INTRUSIVE_POINTER(booster::intrusive_ptr) diff --git a/cppcms/crypto.h b/cppcms/crypto.h index 8ac0d0d5..ee5aad21 100644 --- a/cppcms/crypto.h +++ b/cppcms/crypto.h @@ -142,16 +142,16 @@ namespace cppcms { /// /// Create MD5 message digest /// - static std::auto_ptr md5(); + static std::unique_ptr md5(); /// /// Create SHA1 message digest /// - static std::auto_ptr sha1(); + static std::unique_ptr sha1(); /// /// Create message digest by name, more then sha1 and md5 may be supported, /// if CppCMS is compiled with cryptography library like libgcrypt or openssl /// - static std::auto_ptr create_by_name(std::string const &name); + static std::unique_ptr create_by_name(std::string const &name); }; /// @@ -162,7 +162,7 @@ namespace cppcms { /// /// Create hmac that uses given \a digest algorithm and a binary key - \a key /// - hmac(std::auto_ptr digest,key const &k); + hmac(std::unique_ptr digest,key const &k); /// /// Create hmac that uses message digest algorithm called \a name and use a binary key - \a key /// @@ -190,7 +190,7 @@ namespace cppcms { void init(); struct data_; booster::hold_ptr d; - std::auto_ptr md_,md_opad_; + std::unique_ptr md_,md_opad_; key key_; }; @@ -215,7 +215,7 @@ namespace cppcms { /// /// If the encryption method is not supported returns an empty pointer! /// - static std::auto_ptr create(cbc_type type); + static std::unique_ptr create(cbc_type type); /// /// Create a new cbc object that performs encryption using algorithm \a name /// @@ -224,7 +224,7 @@ namespace cppcms { /// Currently supported aes128, aes192, aes256, with names "aes" = "aes-128" = "aes128" , "aes-192" "aes192", /// "aes-256" = "aes256". They require CppCMS to be compiled with OpenSSL or GNU-TLS library /// - static std::auto_ptr create(std::string const &name); + static std::unique_ptr create(std::string const &name); /// /// Get the size of the block CBC works on diff --git a/cppcms/service.h b/cppcms/service.h index 3ed084e6..c2f8bd68 100644 --- a/cppcms/service.h +++ b/cppcms/service.h @@ -207,7 +207,7 @@ namespace cppcms { private: void setup(); - std::auto_ptr setup_acceptor(json::value const &,int,int shift=0); + std::unique_ptr setup_acceptor(json::value const &,int,int shift=0); void stop(); void start_acceptor(bool after_fork=false); void setup_exit_handling(); diff --git a/cppcms/session_cookies.h b/cppcms/session_cookies.h index aa19641b..987293d1 100644 --- a/cppcms/session_cookies.h +++ b/cppcms/session_cookies.h @@ -60,7 +60,7 @@ namespace sessions { /// /// Return a pointer to a newly created encryptor. /// - virtual std::auto_ptr get() = 0; + virtual std::unique_ptr get() = 0; /// /// Destructor - cleanup everything @@ -76,7 +76,7 @@ namespace sessions { /// /// Create a new object passing it a pointer ecryptor as parameter /// - session_cookies(std::auto_ptr encryptor); + session_cookies(std::unique_ptr encryptor); /// /// Destroy it and destroy an encryptor it was created with /// @@ -104,7 +104,7 @@ namespace sessions { private: struct _data; booster::hold_ptr<_data> d; - std::auto_ptr encryptor_; + std::unique_ptr encryptor_; }; } // sessions } // cppcms diff --git a/cppcms/session_dual.h b/cppcms/session_dual.h index efc669aa..db9c43ae 100644 --- a/cppcms/session_dual.h +++ b/cppcms/session_dual.h @@ -32,7 +32,7 @@ class CPPCMS_API session_dual : public session_api { /// \a data_size_limit represents the maximal data size that can be stored on client side, if the data size is bigger then that /// the session data will be stored on server /// - session_dual( std::auto_ptr enc, + session_dual( std::unique_ptr enc, booster::shared_ptr storage, size_t data_size_limit); /// diff --git a/cppcms/session_pool.h b/cppcms/session_pool.h index 57544328..53c0fe55 100644 --- a/cppcms/session_pool.h +++ b/cppcms/session_pool.h @@ -66,17 +66,17 @@ namespace cppcms { /// /// Assign your own implementation of session_api passing pointer to session_api_factory. /// - void backend(std::auto_ptr b); + void backend(std::unique_ptr b); /// /// Assign your own implementation of sessions::encryptor that would be used for client side session /// management by passing pointer to sessions::encryptor_factory /// - void encryptor(std::auto_ptr e); + void encryptor(std::unique_ptr e); /// /// Assign your own implementation of sessions::session_storage that would be used for server side session /// management by passing pointer to sessions::session_storage_factory /// - void storage(std::auto_ptr s); + void storage(std::unique_ptr s); private: impl::cached_settings const &cached_settings(); @@ -102,9 +102,9 @@ namespace cppcms { booster::hold_ptr<_data> d; - std::auto_ptr backend_; - std::auto_ptr encryptor_; - std::auto_ptr storage_; + std::unique_ptr backend_; + std::unique_ptr encryptor_; + std::unique_ptr storage_; service *service_; }; diff --git a/cppcms/views_pool.h b/cppcms/views_pool.h index 3b284a22..8ef8b474 100644 --- a/cppcms/views_pool.h +++ b/cppcms/views_pool.h @@ -35,7 +35,7 @@ namespace cppcms { class CPPCMS_API generator : public booster::noncopyable { public: /// The callback that creates a single view - typedef std::auto_ptr view_factory_type(std::ostream &,base_content *c); + typedef std::unique_ptr view_factory_type(std::ostream &,base_content *c); generator(); ~generator(); @@ -76,7 +76,7 @@ namespace cppcms { /// Create a view by its name that writes that data to \a outout using /// a content \a content. /// - std::auto_ptr create(std::string const &view_name, + std::unique_ptr create(std::string const &view_name, std::ostream &output, base_content *content) const; /// @@ -86,9 +86,9 @@ namespace cppcms { private: template - static std::auto_ptr view_builder(std::ostream &stream,base_content *c) + static std::unique_ptr view_builder(std::ostream &stream,base_content *c) { - std::auto_ptr p; + std::unique_ptr p; try { p.reset(new View(stream,dynamic_cast(*c))); @@ -96,14 +96,14 @@ namespace cppcms { catch(std::bad_cast const &) { throw cppcms_error("cppcms::views::generator: an attempt to use content of invalid type"); } - return p; + return std::move(p); } template - static std::auto_ptr unsafe_view_builder(std::ostream &stream,base_content *c) + static std::unique_ptr unsafe_view_builder(std::ostream &stream,base_content *c) { - std::auto_ptr p(new View(stream,static_cast(*c))); - return p; + std::unique_ptr p(new View(stream,static_cast(*c))); + return std::move(p); } diff --git a/private/aes_encryptor.h b/private/aes_encryptor.h index 2b794645..a6dba6a4 100644 --- a/private/aes_encryptor.h +++ b/private/aes_encryptor.h @@ -20,7 +20,7 @@ class CPPCMS_API aes_factory : public encryptor_factory { public: aes_factory(std::string const &cbc,crypto::key const &cbc_key,std::string const &hmac,crypto::key const &hmac_key); aes_factory(std::string const &algo,crypto::key const &k); - virtual std::auto_ptr get(); + virtual std::unique_ptr get(); virtual ~aes_factory() {} private: std::string cbc_; @@ -37,8 +37,8 @@ class CPPCMS_API aes_cipher : public cppcms::sessions::encryptor { virtual bool decrypt(std::string const &cipher,std::string &plain); private: void load(); - std::auto_ptr cbc_; - std::auto_ptr digest_; + std::unique_ptr cbc_; + std::unique_ptr digest_; std::string cbc_name_,md_name_; crypto::key cbc_key_; crypto::key mac_key_; diff --git a/private/fastcgi_api.h b/private/fastcgi_api.h index 1690632a..2fd00399 100644 --- a/private/fastcgi_api.h +++ b/private/fastcgi_api.h @@ -17,10 +17,10 @@ namespace cppcms { namespace impl { namespace cgi { class acceptor; - std::auto_ptr fastcgi_api_tcp_socket_factory(cppcms::service &srv,std::string ip,int port,int backlog); + std::unique_ptr fastcgi_api_tcp_socket_factory(cppcms::service &srv,std::string ip,int port,int backlog); #if !defined(CPPCMS_WIN32) - std::auto_ptr fastcgi_api_unix_socket_factory(cppcms::service &srv,std::string socket,int backlog); - std::auto_ptr fastcgi_api_unix_socket_factory(cppcms::service &srv,int backlog); + std::unique_ptr fastcgi_api_unix_socket_factory(cppcms::service &srv,std::string socket,int backlog); + std::unique_ptr fastcgi_api_unix_socket_factory(cppcms::service &srv,int backlog); #endif } // cgi diff --git a/private/hmac_encryptor.h b/private/hmac_encryptor.h index c3601e51..83066d24 100644 --- a/private/hmac_encryptor.h +++ b/private/hmac_encryptor.h @@ -18,7 +18,7 @@ namespace impl { class CPPCMS_API hmac_factory : public encryptor_factory { public: - virtual std::auto_ptr get(); + virtual std::unique_ptr get(); hmac_factory(std::string const &algo,crypto::key const &k); virtual ~hmac_factory() {} private: diff --git a/private/http_api.h b/private/http_api.h index efa3b86e..147ffa57 100644 --- a/private/http_api.h +++ b/private/http_api.h @@ -17,7 +17,7 @@ namespace cppcms { namespace impl { namespace cgi { class acceptor; - std::auto_ptr http_api_factory(cppcms::service &srv,std::string ip,int port,int backlog); + std::unique_ptr http_api_factory(cppcms::service &srv,std::string ip,int port,int backlog); } // cgi } // impl } // cppcms diff --git a/private/prefork_acceptor.h b/private/prefork_acceptor.h index 1c74147e..eda0c67e 100644 --- a/private/prefork_acceptor.h +++ b/private/prefork_acceptor.h @@ -195,7 +195,7 @@ class prefork_acceptor : public booster::noncopyable { int read_interrupter_,write_interrupter_; bool stop_; cppcms::service *service_; - std::auto_ptr thread_; + std::unique_ptr thread_; booster::fork_shared_mutex mutex_; }; diff --git a/private/scgi_api.h b/private/scgi_api.h index d96c03a6..376e0582 100644 --- a/private/scgi_api.h +++ b/private/scgi_api.h @@ -17,10 +17,10 @@ namespace cppcms { namespace impl { namespace cgi { class acceptor; - std::auto_ptr scgi_api_tcp_socket_factory(cppcms::service &srv,std::string ip,int port,int backlog); + std::unique_ptr scgi_api_tcp_socket_factory(cppcms::service &srv,std::string ip,int port,int backlog); #if !defined(CPPCMS_WIN32) - std::auto_ptr scgi_api_unix_socket_factory(cppcms::service &srv,std::string socket,int backlog); - std::auto_ptr scgi_api_unix_socket_factory(cppcms::service &srv,int backlog); + std::unique_ptr scgi_api_unix_socket_factory(cppcms::service &srv,std::string socket,int backlog); + std::unique_ptr scgi_api_unix_socket_factory(cppcms::service &srv,int backlog); #endif } // cgi diff --git a/private/service_impl.h b/private/service_impl.h index ab77192f..a2f4a07f 100644 --- a/private/service_impl.h +++ b/private/service_impl.h @@ -42,21 +42,21 @@ namespace impl { private: friend class cppcms::service; - std::auto_ptr io_service_; + std::unique_ptr io_service_; std::vector > acceptors_; #ifndef CPPCMS_WIN32 - std::auto_ptr prefork_acceptor_; + std::unique_ptr prefork_acceptor_; #endif - std::auto_ptr settings_; - std::auto_ptr applications_pool_; - std::auto_ptr thread_pool_; - std::auto_ptr locale_generator_; - std::auto_ptr views_pool_; - std::auto_ptr cache_pool_; - std::auto_ptr session_pool_; - std::auto_ptr forwarder_; - std::auto_ptr cached_settings_; + std::unique_ptr settings_; + std::unique_ptr applications_pool_; + std::unique_ptr thread_pool_; + std::unique_ptr locale_generator_; + std::unique_ptr views_pool_; + std::unique_ptr cache_pool_; + std::unique_ptr session_pool_; + std::unique_ptr forwarder_; + std::unique_ptr cached_settings_; std::locale default_locale_; std::vector > on_fork_; @@ -64,7 +64,7 @@ namespace impl { int id_; booster::aio::native_type notification_socket_; - std::auto_ptr sig_,breaker_; + std::unique_ptr sig_,breaker_; std::vector args_; diff --git a/src/aes.cpp b/src/aes.cpp index c5b519c2..7b7dad6e 100644 --- a/src/aes.cpp +++ b/src/aes.cpp @@ -15,6 +15,8 @@ #if defined(CPPCMS_HAVE_OPENSSL) #include + +#include #define CPPCMS_HAVE_AES #endif @@ -375,9 +377,9 @@ namespace crypto { #endif -std::auto_ptr cbc::create(std::string const &name) +std::unique_ptr cbc::create(std::string const &name) { - std::auto_ptr res; + std::unique_ptr res; if(name=="aes" || name=="AES" || name=="aes128" || name=="aes-128" || name=="AES128" || name=="AES-128") res = cbc::create(aes128); else if(name=="aes192" || name=="aes-192" || name=="AES192" || name=="AES-192") @@ -385,12 +387,12 @@ std::auto_ptr cbc::create(std::string const &name) else if(name=="aes256" || name=="aes-256" || name=="AES256" || name=="AES-256") res = cbc::create(aes256); - return res; + return std::move(res); } -std::auto_ptr cbc::create(cbc::cbc_type type) +std::unique_ptr cbc::create(cbc::cbc_type type) { - std::auto_ptr res; + std::unique_ptr res; switch(type) { #ifdef CPPCMS_HAVE_AES case aes128: @@ -406,7 +408,7 @@ std::auto_ptr cbc::create(cbc::cbc_type type) default: ; } - return res; + return std::move(res); } diff --git a/src/aes_encryptor.cpp b/src/aes_encryptor.cpp index 1cc73607..fc21c7c3 100644 --- a/src/aes_encryptor.cpp +++ b/src/aes_encryptor.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -40,8 +41,8 @@ aes_factory::aes_factory(std::string const &algo,crypto::key const &k) : cbc_(algo), hmac_("sha1") { - std::auto_ptr md_ptr(crypto::message_digest::create_by_name(hmac_)); - std::auto_ptr cbc_ptr(crypto::cbc::create(algo)); + std::unique_ptr md_ptr(crypto::message_digest::create_by_name(hmac_)); + std::unique_ptr cbc_ptr(crypto::cbc::create(algo)); if(!cbc_ptr.get()) { throw booster::invalid_argument("cppcms::sessions::aes_factory: the algorithm " + algo + " is not supported," " or the cppcms library was compiled without OpenSSL/GNU-TLS support"); @@ -77,11 +78,11 @@ aes_factory::aes_factory(std::string const &algo,crypto::key const &k) : } -std::auto_ptr aes_factory::get() +std::unique_ptr aes_factory::get() { - std::auto_ptr ptr; + std::unique_ptr ptr; ptr.reset(new aes_cipher(cbc_,hmac_,cbc_key_,hmac_key_)); - return ptr; + return std::move(ptr); } @@ -124,7 +125,7 @@ std::string aes_cipher::encrypt(string const &plain) { load(); - std::auto_ptr digest(digest_->clone()); + std::unique_ptr digest(digest_->clone()); unsigned digest_size = digest->digest_size(); uint32_t size = plain.size(); @@ -141,7 +142,7 @@ std::string aes_cipher::encrypt(string const &plain) memcpy(&input[cbc_block_size + sizeof(size)],plain.c_str(),plain.size()); cbc_->encrypt(&input.front(),&output.front(),block_size); - crypto::hmac signature(digest,mac_key_); + crypto::hmac signature(std::move(digest),mac_key_); signature.append(&output[0],block_size); signature.readout(&output[block_size]); @@ -164,7 +165,7 @@ bool aes_cipher::decrypt(std::string const &cipher,std::string &plain) return false; } - crypto::hmac signature(std::auto_ptr(digest_->clone()),mac_key_); + crypto::hmac signature(std::unique_ptr(digest_->clone()),mac_key_); signature.append(cipher.c_str(),real_size); std::vector verify(digest_size,0); signature.readout(&verify[0]); diff --git a/src/application.cpp b/src/application.cpp index d8cb24c1..ea65c773 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include diff --git a/src/applications_pool.cpp b/src/applications_pool.cpp index 1af6d976..4a492763 100644 --- a/src/applications_pool.cpp +++ b/src/applications_pool.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -398,17 +399,17 @@ void application_specific_pool::prepopulate(cppcms::service &srv) namespace impl { class legacy_sync_pool : public application_specific_pool { public: - legacy_sync_pool(std::auto_ptr f) + legacy_sync_pool(std::unique_ptr f) { - fact_ = f; + fact_ = std::move(f); } application *new_application(cppcms::service &srv) { - std::auto_ptr a = (*fact_)(srv); + std::unique_ptr a = (*fact_)(srv); return a.release(); } private: - std::auto_ptr fact_; + std::unique_ptr fact_; }; class legacy_async_pool : public application_specific_pool @@ -454,9 +455,9 @@ applications_pool::~applications_pool() } -void applications_pool::mount(std::auto_ptr aps,mount_point const &mp) +void applications_pool::mount(std::unique_ptr aps,mount_point const &mp) { - booster::shared_ptr p(new impl::legacy_sync_pool(aps)); + booster::shared_ptr p(new impl::legacy_sync_pool(std::move(aps))); p->size(d->thread_count); p->flags(app::legacy); @@ -464,9 +465,9 @@ void applications_pool::mount(std::auto_ptr aps,mount_point const &mp) d->apps.push_back(_data::attachment(p,mp)); } -void applications_pool::mount(std::auto_ptr aps) +void applications_pool::mount(std::unique_ptr aps) { - mount(aps,mount_point()); + mount(std::move(aps),mount_point()); } void applications_pool::mount(booster::intrusive_ptr app) { diff --git a/src/cache_storage.cpp b/src/cache_storage.cpp index a582fcff..c791b462 100644 --- a/src/cache_storage.cpp +++ b/src/cache_storage.cpp @@ -122,8 +122,8 @@ template class mem_cache : public base_cache { typedef typename Setup::mutex_type mutex_type; typedef typename Setup::shared_mutex_type shared_mutex_type; - std::auto_ptr lru_mutex; - std::auto_ptr access_lock; + std::unique_ptr lru_mutex; + std::unique_ptr access_lock; typedef typename Setup::allocator allocator; typedef typename Setup::lock_guard lock_guard; typedef typename Setup::rdlock_guard rdlock_guard; diff --git a/src/copy_filter.cpp b/src/copy_filter.cpp index 6d0560ba..11ec6ab5 100644 --- a/src/copy_filter.cpp +++ b/src/copy_filter.cpp @@ -8,6 +8,8 @@ #define CPPCMS_SOURCE #include +#include + namespace cppcms { class copy_filter::tee_device : public booster::io_device{ public: @@ -37,8 +39,8 @@ namespace cppcms { real_output_stream_(output.rdbuf(©_buffer_)), detached_(false) { - std::auto_ptr device(new tee_device(real_output_stream_,data_)); - copy_buffer_.device(device); + std::unique_ptr device(new tee_device(real_output_stream_,data_)); + copy_buffer_.device(std::move(device)); } std::string copy_filter::detach() diff --git a/src/crypto.cpp b/src/crypto.cpp index 10bb2d78..88af3edc 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -14,6 +14,7 @@ #ifdef CPPCMS_HAVE_OPENSSL # include #endif +#include #include #include #include @@ -228,21 +229,21 @@ namespace crypto { } // anon - std::auto_ptr message_digest::md5() + std::unique_ptr message_digest::md5() { - std::auto_ptr d(new md5_digets()); - return d; + std::unique_ptr d(new md5_digets()); + return std::move(d); } - std::auto_ptr message_digest::sha1() + std::unique_ptr message_digest::sha1() { - std::auto_ptr d(new sha1_digets()); - return d; + std::unique_ptr d(new sha1_digets()); + return std::move(d); } - std::auto_ptr message_digest::create_by_name(std::string const &namein) + std::unique_ptr message_digest::create_by_name(std::string const &namein) { - std::auto_ptr d; + std::unique_ptr d; std::string name = namein; for(unsigned i=0;i digest,key const &k) : key_(k) + hmac::hmac(std::unique_ptr digest,key const &k) : key_(k) { if(!digest.get()) throw booster::invalid_argument("Has algorithm is not provided"); - md_ = digest; + md_ = std::move(digest); md_opad_.reset(md_->clone()); init(); } diff --git a/src/fastcgi_api.cpp b/src/fastcgi_api.cpp index eba8db64..6d961f5a 100644 --- a/src/fastcgi_api.cpp +++ b/src/fastcgi_api.cpp @@ -699,11 +699,11 @@ namespace cgi { return; } body_.resize(cur_size + rec_size); - std::auto_ptr > cb; + std::unique_ptr > cb; cb.reset(new on_header_read_binder(h,self())); async_read_from_socket( &body_[cur_size],rec_size, - cb); + std::move(cb)); } void on_body_read(booster::system::error_code const &e,handler const &h) { @@ -851,23 +851,23 @@ namespace cgi { } }; - std::auto_ptr fastcgi_api_tcp_socket_factory(cppcms::service &srv,std::string ip,int port,int backlog) + std::unique_ptr fastcgi_api_tcp_socket_factory(cppcms::service &srv,std::string ip,int port,int backlog) { - std::auto_ptr a(new socket_acceptor(srv,ip,port,backlog)); - return a; + std::unique_ptr a(new socket_acceptor(srv,ip,port,backlog)); + return std::move(a); } #if !defined(CPPCMS_WIN32) - std::auto_ptr fastcgi_api_unix_socket_factory(cppcms::service &srv,std::string socket,int backlog) + std::unique_ptr fastcgi_api_unix_socket_factory(cppcms::service &srv,std::string socket,int backlog) { - std::auto_ptr a(new socket_acceptor(srv,socket,backlog)); - return a; + std::unique_ptr a(new socket_acceptor(srv,socket,backlog)); + return std::move(a); } - std::auto_ptr fastcgi_api_unix_socket_factory(cppcms::service &srv,int backlog) + std::unique_ptr fastcgi_api_unix_socket_factory(cppcms::service &srv,int backlog) { - std::auto_ptr a(new socket_acceptor(srv,backlog)); - return a; + std::unique_ptr a(new socket_acceptor(srv,backlog)); + return std::move(a); } #endif diff --git a/src/hello_world.cpp b/src/hello_world.cpp index 8af098f1..9211d8b4 100644 --- a/src/hello_world.cpp +++ b/src/hello_world.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "hello_world_view.h" diff --git a/src/hmac_encryptor.cpp b/src/hmac_encryptor.cpp index 7cf6edc6..a9ba8754 100644 --- a/src/hmac_encryptor.cpp +++ b/src/hmac_encryptor.cpp @@ -14,6 +14,8 @@ #include #include +#include + namespace cppcms { namespace sessions { namespace impl { @@ -24,11 +26,11 @@ hmac_factory::hmac_factory(std::string const &algo,crypto::key const &k) : { } -std::auto_ptr hmac_factory::get() +std::unique_ptr hmac_factory::get() { - std::auto_ptr ptr; + std::unique_ptr ptr; ptr.reset(new hmac_cipher(algo_,key_)); - return ptr; + return std::move(ptr); } diff --git a/src/http_api.cpp b/src/http_api.cpp index b233f23b..f2bf8cd1 100644 --- a/src/http_api.cpp +++ b/src/http_api.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include "binder.h" @@ -747,13 +748,13 @@ namespace cgi { return new http(srv,ip_,port_,watchdog_,rewrite_); } - std::auto_ptr http_api_factory(cppcms::service &srv,std::string ip,int port,int backlog) + std::unique_ptr http_api_factory(cppcms::service &srv,std::string ip,int port,int backlog) { typedef socket_acceptor acceptor_type; - std::auto_ptr acc(new acceptor_type(srv,ip,port,backlog)); + std::unique_ptr acc(new acceptor_type(srv,ip,port,backlog)); acc->factory(http_creator(srv.get_io_service(),srv.settings(),ip,port)); - std::auto_ptr a(acc); - return a; + std::unique_ptr a(std::move(acc)); + return std::move(a); } diff --git a/src/http_context.cpp b/src/http_context.cpp index f745e5d5..d9b78955 100644 --- a/src/http_context.cpp +++ b/src/http_context.cpp @@ -27,6 +27,8 @@ #include "cached_settings.h" #include + +#include #include "binder.h" @@ -37,9 +39,9 @@ namespace http { std::locale locale; std::string skin; http::request request; - std::auto_ptr response; - std::auto_ptr cache; - std::auto_ptr session; + std::unique_ptr response; + std::unique_ptr cache; + std::unique_ptr session; booster::shared_ptr pool; booster::intrusive_ptr app; std::string matched; diff --git a/src/internal_file_server.cpp b/src/internal_file_server.cpp index fc90bc15..c382b56f 100644 --- a/src/internal_file_server.cpp +++ b/src/internal_file_server.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include diff --git a/src/make_key.cpp b/src/make_key.cpp index 9032d110..87f5b4d4 100644 --- a/src/make_key.cpp +++ b/src/make_key.cpp @@ -102,7 +102,7 @@ int main(int argc,char **argv) cppcms::json::value val; - std::auto_ptr digest = cppcms::crypto::message_digest::create_by_name(hmac); + std::unique_ptr digest = cppcms::crypto::message_digest::create_by_name(hmac); if(!digest.get()) { std::cerr << "Unsupported HMAC " << hmac << std::endl; return 1; @@ -110,7 +110,7 @@ int main(int argc,char **argv) if(!make_entry(val,"hmac",hmac,hmac_file,digest->digest_size())) return 1; if(!cbc.empty()) { - std::auto_ptr p = cppcms::crypto::cbc::create(cbc); + std::unique_ptr p = cppcms::crypto::cbc::create(cbc); if(!p.get()) { std::cerr << "Unsupported CBC " << cbc << std::endl; return 1; diff --git a/src/scgi_api.cpp b/src/scgi_api.cpp index ee2302b6..a97efe9e 100644 --- a/src/scgi_api.cpp +++ b/src/scgi_api.cpp @@ -12,6 +12,7 @@ #include "service_impl.h" #include "cppcms_error_category.h" #include +#include #include #include #include @@ -168,21 +169,21 @@ namespace cgi { - std::auto_ptr scgi_api_tcp_socket_factory(cppcms::service &srv,std::string ip,int port,int backlog) + std::unique_ptr scgi_api_tcp_socket_factory(cppcms::service &srv,std::string ip,int port,int backlog) { - std::auto_ptr a(new socket_acceptor(srv,ip,port,backlog)); - return a; + std::unique_ptr a(new socket_acceptor(srv,ip,port,backlog)); + return std::move(a); } #if !defined(CPPCMS_WIN32) - std::auto_ptr scgi_api_unix_socket_factory(cppcms::service &srv,std::string socket,int backlog) + std::unique_ptr scgi_api_unix_socket_factory(cppcms::service &srv,std::string socket,int backlog) { - std::auto_ptr a(new socket_acceptor(srv,socket,backlog)); - return a; + std::unique_ptr a(new socket_acceptor(srv,socket,backlog)); + return std::move(a); } - std::auto_ptr scgi_api_unix_socket_factory(cppcms::service &srv,int backlog) + std::unique_ptr scgi_api_unix_socket_factory(cppcms::service &srv,int backlog) { - std::auto_ptr a(new socket_acceptor(srv,backlog)); - return a; + std::unique_ptr a(new socket_acceptor(srv,backlog)); + return std::move(a); } #endif diff --git a/src/service.cpp b/src/service.cpp index 8124ec43..c675c24d 100644 --- a/src/service.cpp +++ b/src/service.cpp @@ -72,6 +72,7 @@ #include #include #include +#include #include #include #include @@ -762,7 +763,7 @@ int service::process_id() return impl_->id_; } -std::auto_ptr service::setup_acceptor(json::value const &v,int backlog,int port_shift) +std::unique_ptr service::setup_acceptor(json::value const &v,int backlog,int port_shift) { using namespace cppcms::impl::cgi; @@ -774,7 +775,7 @@ std::auto_ptr service::setup_acceptor(json::value c int port=0; bool tcp; - std::auto_ptr a; + std::unique_ptr a; if(socket.empty()) { ip=v.get("ip","127.0.0.1"); @@ -840,7 +841,7 @@ std::auto_ptr service::setup_acceptor(json::value c a->sndbuf(sndbuf); a->rcvbuf(rcvbuf); - return a; + return std::move(a); } void service::start_acceptor(bool after_fork) diff --git a/src/session_cookies.cpp b/src/session_cookies.cpp index a03517af..9192faea 100644 --- a/src/session_cookies.cpp +++ b/src/session_cookies.cpp @@ -15,6 +15,8 @@ #include #include +#include + namespace cppcms { namespace sessions { @@ -22,8 +24,8 @@ using namespace std; struct session_cookies::_data {}; -session_cookies::session_cookies(std::auto_ptr enc) : - encryptor_(enc) +session_cookies::session_cookies(std::unique_ptr enc) : + encryptor_(std::move(enc)) { } session_cookies::~session_cookies() diff --git a/src/session_dual.cpp b/src/session_dual.cpp index b9863eb5..14e5cb0f 100644 --- a/src/session_dual.cpp +++ b/src/session_dual.cpp @@ -11,6 +11,8 @@ #include #include +#include + using namespace std; namespace cppcms { @@ -18,8 +20,8 @@ namespace sessions { struct session_dual::_data {}; -session_dual::session_dual(std::auto_ptr enc,booster::shared_ptr storage,size_t limit) : - client_(new session_cookies(enc)), +session_dual::session_dual(std::unique_ptr enc,booster::shared_ptr storage,size_t limit) : + client_(new session_cookies(std::move(enc))), server_(new session_sid(storage)), data_size_limit_(limit) { diff --git a/src/session_pool.cpp b/src/session_pool.cpp index feb09e2a..d1613f5f 100644 --- a/src/session_pool.cpp +++ b/src/session_pool.cpp @@ -39,6 +39,8 @@ #include #include +#include + #include "cached_settings.h" namespace cppcms { @@ -177,7 +179,7 @@ void session_pool::init() throw cppcms_error("Can't use session encryption without MAC"); } - std::auto_ptr factory; + std::unique_ptr factory; if(!enc.empty()) { crypto::key k; @@ -225,11 +227,11 @@ void session_pool::init() } } - encryptor(factory); + encryptor(std::move(factory)); } if((location == "server" || location == "both") && !storage_.get()) { std::string stor=settings.get("session.server.storage"); - std::auto_ptr factory; + std::unique_ptr factory; #ifndef CPPCMS_NO_GZIP if(stor == "files") { std::string dir = settings.get("session.server.dir",""); @@ -302,20 +304,20 @@ void session_pool::init() #endif else throw cppcms_error("sessions_pool: unknown server side storage:"+stor); - storage(factory); + storage(std::move(factory)); } if(location == "server") { - std::auto_ptr f(new sid_factory(this)); - backend(f); + std::unique_ptr f(new sid_factory(this)); + backend(std::move(f)); } else if(location == "client") { - std::auto_ptr f(new cookies_factory(this)); - backend(f); + std::unique_ptr f(new cookies_factory(this)); + backend(std::move(f)); } else if(location == "both") { unsigned limit=settings.get("session.client_size_limit",2048); - std::auto_ptr f(new dual_factory(limit,this)); - backend(f); + std::unique_ptr f(new dual_factory(limit,this)); + backend(std::move(f)); } else if(location == "none") ; @@ -364,17 +366,17 @@ booster::shared_ptr session_pool::get() return p; } -void session_pool::backend(std::auto_ptr b) +void session_pool::backend(std::unique_ptr b) { - backend_=b; + backend_=std::move(b); } -void session_pool::encryptor(std::auto_ptr e) +void session_pool::encryptor(std::unique_ptr e) { - encryptor_=e; + encryptor_=std::move(e); } -void session_pool::storage(std::auto_ptr s) +void session_pool::storage(std::unique_ptr s) { - storage_=s; + storage_=std::move(s); } cppcms::impl::cached_settings const &session_pool::cached_settings() diff --git a/src/tcp_cache_server.cpp b/src/tcp_cache_server.cpp index b977aa55..54b54dbd 100644 --- a/src/tcp_cache_server.cpp +++ b/src/tcp_cache_server.cpp @@ -434,7 +434,7 @@ struct thread_functional { struct tcp_cache_service::_data { std::vector > io; - std::auto_ptr srv_cache; + std::unique_ptr srv_cache; booster::intrusive_ptr cache; std::vector > threads; booster::shared_ptr gc_thread; diff --git a/src/views_pool.cpp b/src/views_pool.cpp index 0dcb8a8d..d04c1028 100644 --- a/src/views_pool.cpp +++ b/src/views_pool.cpp @@ -29,6 +29,8 @@ #include #include +#include + namespace cppcms { namespace views { // class generator @@ -54,16 +56,16 @@ void generator::add_factory(std::string const &n,generator::view_factory_type *f views_[n]=factory; } -std::auto_ptr generator::create( std::string const &view_name, +std::unique_ptr generator::create( std::string const &view_name, std::ostream &output, base_content *content) const { - std::auto_ptr result; + std::unique_ptr result; views_type::const_iterator p = views_.find(view_name); if(p==views_.end()) - return result; + return std::move(result); result = p->second(output,content); - return result; + return std::move(result); } std::vector generator::enumerate() const @@ -142,7 +144,7 @@ base_view *pool::create_view(std::string const &skin,std::string const &template if(t==reg_skin.end()) throw cppcms_error("cppcms::view::pool: no suck view:" + template_name + " is registered for skin: " + skin); - std::auto_ptr v; + std::unique_ptr v; v = t->second->create(template_name,out,&content); if(!v.get()) throw cppcms_error("cppcms::views::pool: no such view " + template_name + " in the skin " + skin); diff --git a/tests/cache_backend_test.cpp b/tests/cache_backend_test.cpp index d9c83624..c37a0a8e 100644 --- a/tests/cache_backend_test.cpp +++ b/tests/cache_backend_test.cpp @@ -122,7 +122,7 @@ int main() std::cout << "Ok" << std::endl; #endif - std::auto_ptr srv1,srv2; + std::unique_ptr srv1,srv2; { try { std::cout << "Testing cache over ip, single server... "< #include +#include #include diff --git a/tests/cookie_test.cpp b/tests/cookie_test.cpp index 6598836f..b82e9ccb 100644 --- a/tests/cookie_test.cpp +++ b/tests/cookie_test.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "client.h" #include "test.h" diff --git a/tests/cppcms_service_test.cpp b/tests/cppcms_service_test.cpp index 17fafd52..7037210d 100644 --- a/tests/cppcms_service_test.cpp +++ b/tests/cppcms_service_test.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include diff --git a/tests/disco_test.cpp b/tests/disco_test.cpp index 59c60f1c..8659ab31 100644 --- a/tests/disco_test.cpp +++ b/tests/disco_test.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include "client.h" #include "test.h" diff --git a/tests/encryptor_test.cpp b/tests/encryptor_test.cpp index 34882bf3..7e6121cc 100644 --- a/tests/encryptor_test.cpp +++ b/tests/encryptor_test.cpp @@ -19,9 +19,9 @@ #include template -std::auto_ptr gen(std::string const &name,cppcms::crypto::key const &k) +std::unique_ptr gen(std::string const &name,cppcms::crypto::key const &k) { - std::auto_ptr fact(new EncryptorFactory(name,k)); + std::unique_ptr fact(new EncryptorFactory(name,k)); return fact->get(); } @@ -31,7 +31,7 @@ void run_test(std::string name,std::string k,bool is_signature = false) using cppcms::crypto::key; char c1=k[0]; char c2=k[31]; - std::auto_ptr enc = gen(name,key(k)); + std::unique_ptr enc = gen(name,key(k)); std::string cipher=enc->encrypt("Hello World"); std::string plain; TEST(enc->decrypt(cipher,plain)); @@ -118,13 +118,13 @@ void test_crypto() TEST(message_digest::md5()->digest_size() == 16); TEST(message_digest::sha1()->digest_size() == 20); { - std::auto_ptr d(message_digest::create_by_name("md5")); + std::unique_ptr d(message_digest::create_by_name("md5")); TEST(d->name() == std::string("md5")); TEST(get_diget(*d,"")=="d41d8cd98f00b204e9800998ecf8427e"); TEST(get_diget(*d,"Hello World!")=="ed076287532e86365e841e92bfc50d8c"); } { - std::auto_ptr d(message_digest::create_by_name("sha1")); + std::unique_ptr d(message_digest::create_by_name("sha1")); TEST(d->name() == std::string("sha1")); TEST(get_diget(*d,"")=="da39a3ee5e6b4b0d3255bfef95601890afd80709"); TEST(get_diget(*d,"Hello World!")=="2ef7bde608ce5404e97d5f042f95f89f1c232871"); @@ -143,7 +143,7 @@ void test_crypto() #if defined(CPPCMS_HAVE_GCRYPT) || defined(CPPCMS_HAVE_OPENSSL) std::cout << "-- testing shaXXX " << std::endl; { - std::auto_ptr d(message_digest::create_by_name("sha256")); + std::unique_ptr d(message_digest::create_by_name("sha256")); TEST(d->name() == std::string("sha256")); TEST(d->block_size() == 64); TEST(get_diget(*d,"Hello World")=="a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e"); diff --git a/tests/file_server_test.cpp b/tests/file_server_test.cpp index 50e535dd..19364474 100644 --- a/tests/file_server_test.cpp +++ b/tests/file_server_test.cpp @@ -17,6 +17,7 @@ #include #include "internal_file_server.h" #include +#include #include "client.h" #include "test.h" #ifdef CPPCMS_WIN_NATIVE diff --git a/tests/filter_test.cpp b/tests/filter_test.cpp index 7503f36e..b1151cb2 100644 --- a/tests/filter_test.cpp +++ b/tests/filter_test.cpp @@ -22,6 +22,7 @@ #include #include "client.h" #include +#include #include #include "test.h" diff --git a/tests/form_test.cpp b/tests/form_test.cpp index e2875a2b..5281fba2 100644 --- a/tests/form_test.cpp +++ b/tests/form_test.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "client.h" diff --git a/tests/forwarder_test.cpp b/tests/forwarder_test.cpp index 0b79fa75..119b64be 100644 --- a/tests/forwarder_test.cpp +++ b/tests/forwarder_test.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include "client.h" #include "test.h" #include diff --git a/tests/gzip_test.cpp b/tests/gzip_test.cpp index e6e9fa77..df7e7e85 100644 --- a/tests/gzip_test.cpp +++ b/tests/gzip_test.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "client.h" #include "test.h" diff --git a/tests/http_timeouts_test.cpp b/tests/http_timeouts_test.cpp index 205dbf3b..8762d821 100644 --- a/tests/http_timeouts_test.cpp +++ b/tests/http_timeouts_test.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include "client.h" #include "test.h" #include diff --git a/tests/jsonrpc_test.cpp b/tests/jsonrpc_test.cpp index 9c008b34..2b60a2bd 100644 --- a/tests/jsonrpc_test.cpp +++ b/tests/jsonrpc_test.cpp @@ -9,6 +9,8 @@ #include "test.h" #include +#include + #include "client.h" diff --git a/tests/pool_test.cpp b/tests/pool_test.cpp index 99e71906..9b7e8bd3 100644 --- a/tests/pool_test.cpp +++ b/tests/pool_test.cpp @@ -20,6 +20,7 @@ #include #include "client.h" #include +#include #include #include "test.h" diff --git a/tests/proto_test.cpp b/tests/proto_test.cpp index e250f31d..c6402be1 100644 --- a/tests/proto_test.cpp +++ b/tests/proto_test.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "client.h" #include "test.h" diff --git a/tests/response_test.cpp b/tests/response_test.cpp index 1dfbd8cc..cc111a2c 100644 --- a/tests/response_test.cpp +++ b/tests/response_test.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include "dummy_api.h" diff --git a/tests/secure_post_test.cpp b/tests/secure_post_test.cpp index e60ab31c..50edcde8 100644 --- a/tests/secure_post_test.cpp +++ b/tests/secure_post_test.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include "client.h" #include "test.h" diff --git a/tests/serialization_test.cpp b/tests/serialization_test.cpp index 49d6b550..6361c5c7 100644 --- a/tests/serialization_test.cpp +++ b/tests/serialization_test.cpp @@ -431,7 +431,7 @@ int main() test_ptr >(); test_ptr >(); test_ptr >(); - test_ptr >(); + test_ptr >(); std::cout << "Testing object serialization" << std::endl; { diff --git a/tests/session_interface_test.cpp b/tests/session_interface_test.cpp index 67cd69ff..b69e69c3 100644 --- a/tests/session_interface_test.cpp +++ b/tests/session_interface_test.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include "client.h" #include "test.h" diff --git a/tests/status_test.cpp b/tests/status_test.cpp index a673b28e..b1bdf32b 100644 --- a/tests/status_test.cpp +++ b/tests/status_test.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include "client.h" class unit_test : public cppcms::application { diff --git a/tests/storage_test.cpp b/tests/storage_test.cpp index 7718443b..c846e57d 100644 --- a/tests/storage_test.cpp +++ b/tests/storage_test.cpp @@ -125,7 +125,7 @@ int main() try { booster::shared_ptr storage; - std::auto_ptr storage_factory; + std::unique_ptr storage_factory; using namespace cppcms::sessions; std::cout << "Testing memory storage" << std::endl; diff --git a/tests/tc_test.cpp b/tests/tc_test.cpp index f9c6d44c..6e2811eb 100644 --- a/tests/tc_test.cpp +++ b/tests/tc_test.cpp @@ -17,6 +17,7 @@ #include "test.h" #include +#include #include int calls_done = 0; From fcd4c24ee0297d88266219b6d2087e53db8271be Mon Sep 17 00:00:00 2001 From: Petr Filipsky Date: Thu, 28 Jun 2018 21:22:10 +0200 Subject: [PATCH 2/3] Replace booster smart pointers with STL equivalents --- CMakeLists.txt | 2 +- booster/booster/bad_weak_ptr.h | 52 +- booster/booster/enable_shared_from_this.h | 77 +-- booster/booster/locale/generator.h | 4 +- booster/booster/log.h | 10 +- booster/booster/shared_ptr.h | 444 +----------------- booster/booster/smart_ptr/shared_count.h | 285 ----------- booster/booster/smart_ptr/sp_counted_base.h | 76 --- booster/booster/weak_ptr.h | 161 +------ booster/lib/locale/src/posix/codecvt.cpp | 2 +- .../src/shared/localization_backend.cpp | 4 +- booster/lib/locale/src/shared/message.cpp | 5 +- booster/lib/locale/src/shared/mo_lambda.cpp | 20 +- booster/lib/smart_ptr/src/sp_counted_base.cpp | 397 ---------------- .../lib/smart_ptr/test/test_sp_counter.cpp | 120 ++--- cppcms/application.h | 1 + private/string_map.h | 1 + src/application.cpp | 2 +- src/applications_pool.cpp | 1 + src/http_api.cpp | 2 +- tests/pool_test.cpp | 5 +- tests/storage_test.cpp | 2 +- 22 files changed, 114 insertions(+), 1559 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ce0d539..41a2001a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,7 +112,7 @@ if(CMAKE_COMPILER_IS_GNUCXX) int main() {}" GCC_IS_GCC4) - set(CXX_FLAGS "-Wall -Wextra") + set(CXX_FLAGS "-Wall -Wextra -std=c++14") set(C_FLAGS "-Wall -Wextra") if(CMAKE_SYSTEM_NAME STREQUAL "SunOS") diff --git a/booster/booster/bad_weak_ptr.h b/booster/booster/bad_weak_ptr.h index 85a85305..19c3e587 100644 --- a/booster/booster/bad_weak_ptr.h +++ b/booster/booster/bad_weak_ptr.h @@ -1,56 +1,12 @@ #ifndef BOOSTER_SMART_PTR_BAD_WEAK_PTR_HPP_INCLUDED #define BOOSTER_SMART_PTR_BAD_WEAK_PTR_HPP_INCLUDED -// -// boost/smart_ptr/bad_weak_ptr.hpp -// -// Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd. -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// +#include -#include +namespace booster { -#ifdef __BORLANDC__ -# pragma warn -8026 // Functions with excep. spec. are not expanded inline -#endif +using bad_weak_ptr = std::bad_weak_ptr; -namespace booster -{ - -// The standard library that comes with Borland C++ 5.5.1, 5.6.4 -// defines std::exception and its members as having C calling -// convention (-pc). When the definition of bad_weak_ptr -// is compiled with -ps, the compiler issues an error. -// Hence, the temporary #pragma option -pc below. - -#if defined(__BORLANDC__) && __BORLANDC__ <= 0x564 -# pragma option push -pc -#endif - -/// -/// An exeption that is throws in case of creating of shared_ptr from expired weak_ptr -/// -class bad_weak_ptr: public booster::exception -{ -public: - - virtual char const * what() const throw() - { - return "booster::bad_weak_ptr"; - } -}; - -#if defined(__BORLANDC__) && __BORLANDC__ <= 0x564 -# pragma option pop -#endif - -} // namespace boost - -#ifdef __BORLANDC__ -# pragma warn .8026 // Functions with excep. spec. are not expanded inline -#endif +} // namespace booster #endif // #ifndef BOOST_SMART_PTR_BAD_WEAK_PTR_HPP_INCLUDED diff --git a/booster/booster/enable_shared_from_this.h b/booster/booster/enable_shared_from_this.h index a775da80..882cc174 100644 --- a/booster/booster/enable_shared_from_this.h +++ b/booster/booster/enable_shared_from_this.h @@ -1,84 +1,11 @@ #ifndef BOOSTER_SMART_PTR_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED #define BOOSTER_SMART_PTR_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED -// -// enable_shared_from_this.hpp -// -// Copyright 2002, 2009 Peter Dimov -// -// Distributed under the Boost Software License, Version 1.0. -// See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt -// -// http://www.boost.org/libs/smart_ptr/enable_shared_from_this.html -// - -#include -#include -#include -#include - namespace booster { -/// -/// \brief This class is borrowed from boost -/// -/// For details see: http://www.boost.org/doc/libs/release/libs/smart_ptr -/// - -template class enable_shared_from_this -{ -protected: - - enable_shared_from_this() - { - } - - enable_shared_from_this(enable_shared_from_this const &) - { - } - - enable_shared_from_this & operator=(enable_shared_from_this const &) - { - return *this; - } - - ~enable_shared_from_this() - { - } - -public: - - shared_ptr shared_from_this() - { - shared_ptr p( weak_this_ ); - assert( p.get() == this ); - return p; - } - - shared_ptr shared_from_this() const - { - shared_ptr p( weak_this_ ); - assert( p.get() == this ); - return p; - } - -public: // actually private, but avoids compiler template friendship issues - - // Note: invoked automatically by shared_ptr; do not call - template void _internal_accept_owner( shared_ptr const * ppx, Y * py ) const - { - if( weak_this_.expired() ) - { - weak_this_ = shared_ptr( *ppx, py ); - } - } - -private: - - mutable weak_ptr weak_this_; -}; + template + using enable_shared_from_this = std::enable_shared_from_this; } // namespace boost diff --git a/booster/booster/locale/generator.h b/booster/booster/locale/generator.h index d9105bdd..ac67ed42 100644 --- a/booster/booster/locale/generator.h +++ b/booster/booster/locale/generator.h @@ -19,8 +19,8 @@ namespace booster { - template - class shared_ptr; + template + using shared_ptr = std::shared_ptr; /// /// \brief This is the main namespace that encloses all localization classes diff --git a/booster/booster/log.h b/booster/booster/log.h index 16fe278e..0cfb8255 100644 --- a/booster/booster/log.h +++ b/booster/booster/log.h @@ -21,10 +21,12 @@ namespace booster { -template -class shared_ptr; -template -class weak_ptr; +template +using shared_ptr = std::shared_ptr; + +template +using weak_ptr = std::weak_ptr; + /// /// \brief This namespace includes Booster.Log related classes diff --git a/booster/booster/shared_ptr.h b/booster/booster/shared_ptr.h index 782ee776..1a59bdf5 100644 --- a/booster/booster/shared_ptr.h +++ b/booster/booster/shared_ptr.h @@ -1,448 +1,18 @@ #ifndef BOOSTER_SMART_PTR_SHARED_PTR_HPP_INCLUDED #define BOOSTER_SMART_PTR_SHARED_PTR_HPP_INCLUDED -// -// shared_ptr.hpp -// -// (C) Copyright Greg Colvin and Beman Dawes 1998, 1999. -// Copyright (c) 2001-2008 Peter Dimov -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// See http://www.boost.org/libs/smart_ptr/shared_ptr.htm for documentation. -// -#include // for broken compiler workarounds - -#include -#include -#include -#include -#include -#include - -#include // for std::swap -#include // for std::less -#include // for std::bad_cast - -#include // for std::basic_ostream - -#ifdef BOOSTER_MSVC // moved here to work around VC++ compiler crash -# pragma warning(push) -# pragma warning(disable:4284) // odd return type for operator-> -#endif +#include namespace booster { -template class shared_ptr; -template class weak_ptr; -template class enable_shared_from_this; -template class enable_shared_from_this2; - -namespace detail -{ - -struct static_cast_tag {}; -struct const_cast_tag {}; -struct dynamic_cast_tag {}; -struct polymorphic_cast_tag {}; - -template struct shared_ptr_traits -{ - typedef T & reference; -}; - -template<> struct shared_ptr_traits -{ - typedef void reference; -}; - -template<> struct shared_ptr_traits -{ - typedef void reference; -}; - -template<> struct shared_ptr_traits -{ - typedef void reference; -}; - -template<> struct shared_ptr_traits -{ - typedef void reference; -}; - -// enable_shared_from_this support - -template< class X, class Y, class T > inline void sp_enable_shared_from_this( booster::shared_ptr const * ppx, Y const * py, booster::enable_shared_from_this< T > const * pe ) -{ - if( pe != 0 ) - { - pe->_internal_accept_owner( ppx, const_cast< Y* >( py ) ); - } -} - -template< class X, class Y, class T > inline void sp_enable_shared_from_this( booster::shared_ptr * ppx, Y const * py, booster::enable_shared_from_this2< T > const * pe ) -{ - if( pe != 0 ) - { - pe->_internal_accept_owner( ppx, const_cast< Y* >( py ) ); - } -} - -inline void sp_enable_shared_from_this( ... ) -{ -} - - -// rvalue auto_ptr support based on a technique by Dave Abrahams - -template< class T, class R > struct sp_enable_if_auto_ptr -{ -}; - -template< class T, class R > struct sp_enable_if_auto_ptr< std::auto_ptr< T >, R > -{ - typedef R type; -}; - -} // namespace detail - - -// -// shared_ptr -// -// An enhanced relative of scoped_ptr with reference counted copy semantics. -// The object pointed to is deleted when the last shared_ptr pointing to it -// is destroyed or reset. -// - -template class shared_ptr -{ -private: - - // Borland 5.5.1 specific workaround - typedef shared_ptr this_type; - -public: - - typedef T element_type; - typedef T value_type; - typedef T * pointer; - typedef typename booster::detail::shared_ptr_traits::reference reference; - - shared_ptr(): px(0), pn() // never throws in 1.30+ - { - } - - template - explicit shared_ptr( Y * p ): px( p ), pn( p ) // Y must be complete - { - booster::detail::sp_enable_shared_from_this( this, p, p ); - } - - // - // Requirements: D's copy constructor must not throw - // - // shared_ptr will release p by calling d(p) - // - - template shared_ptr(Y * p, D d): px(p), pn(p, d) - { - booster::detail::sp_enable_shared_from_this( this, p, p ); - } - - // As above, but with allocator. A's copy constructor shall not throw. - - template shared_ptr( Y * p, D d, A a ): px( p ), pn( p, d, a ) - { - booster::detail::sp_enable_shared_from_this( this, p, p ); - } - -// generated copy constructor, destructor are fine - - template - explicit shared_ptr(weak_ptr const & r): pn(r.pn) // may throw - { - // it is now safe to copy r.px, as pn(r.pn) did not throw - px = r.px; - } - - template - shared_ptr( weak_ptr const & r, booster::detail::sp_nothrow_tag ): px( 0 ), pn( r.pn, booster::detail::sp_nothrow_tag() ) // never throws - { - if( !pn.empty() ) - { - px = r.px; - } - } - - template - shared_ptr( shared_ptr const & r, typename detail::sp_enable_if_convertible::type = detail::sp_empty() ) - : px( r.px ), pn( r.pn ) // never throws - { - } - - // aliasing - template< class Y > - shared_ptr( shared_ptr const & r, T * p ): px( p ), pn( r.pn ) // never throws - { - } - - template - shared_ptr(shared_ptr const & r, booster::detail::static_cast_tag): px(static_cast(r.px)), pn(r.pn) - { - } - - template - shared_ptr(shared_ptr const & r, booster::detail::const_cast_tag): px(const_cast(r.px)), pn(r.pn) - { - } - - template - shared_ptr(shared_ptr const & r, booster::detail::dynamic_cast_tag): px(dynamic_cast(r.px)), pn(r.pn) - { - if(px == 0) // need to allocate new counter -- the cast failed - { - pn = booster::detail::shared_count(); - } - } - - template - shared_ptr(shared_ptr const & r, booster::detail::polymorphic_cast_tag): px(dynamic_cast(r.px)), pn(r.pn) - { - if(px == 0) - { - throw booster::bad_cast(); - } - } - - template - explicit shared_ptr(std::unique_ptr & r): px(r.get()), pn() - { - Y * tmp = r.get(); - pn = booster::detail::shared_count(r); - booster::detail::sp_enable_shared_from_this( this, tmp, tmp ); - } - - template - explicit shared_ptr( Ap r, typename booster::detail::sp_enable_if_auto_ptr::type = 0 ): px( r.get() ), pn() - { - typename Ap::element_type * tmp = r.get(); - pn = booster::detail::shared_count( r ); - booster::detail::sp_enable_shared_from_this( this, tmp, tmp ); - } - - - // assignment - - shared_ptr & operator=( shared_ptr const & r ) // never throws - { - this_type(r).swap(*this); - return *this; - } - - template - shared_ptr & operator=(shared_ptr const & r) // never throws - { - this_type(r).swap(*this); - return *this; - } - - - template - shared_ptr & operator=( std::unique_ptr & r ) - { - this_type(r).swap(*this); - return *this; - } - - template - typename booster::detail::sp_enable_if_auto_ptr< Ap, shared_ptr & >::type operator=( Ap r ) - { - this_type( r ).swap( *this ); - return *this; - } - -// Move support - - void reset() // never throws in 1.30+ - { - this_type().swap(*this); - } - - template void reset(Y * p) // Y must be complete - { - assert(p == 0 || p != px); // catch self-reset errors - this_type(p).swap(*this); - } - - template void reset( Y * p, D d ) - { - this_type( p, d ).swap( *this ); - } - - template void reset( Y * p, D d, A a ) - { - this_type( p, d, a ).swap( *this ); - } - - template void reset( shared_ptr const & r, T * p ) - { - this_type( r, p ).swap( *this ); - } - - reference operator* () const // never throws - { - assert(px != 0); - return *px; - } - - T * operator-> () const // never throws - { - assert(px != 0); - return px; - } - - T * get() const // never throws - { - return px; - } - -// implicit conversion to "bool" -#include - - bool unique() const // never throws - { - return pn.unique(); - } - - long use_count() const // never throws - { - return pn.use_count(); - } - - void swap(shared_ptr & other) // never throws - { - std::swap(px, other.px); - pn.swap(other.pn); - } - - template bool _internal_less(shared_ptr const & rhs) const - { - return pn < rhs.pn; - } - - void * _internal_get_deleter( detail::sp_typeinfo const & ti ) const - { - return pn.get_deleter( ti ); - } - - bool _internal_equiv( shared_ptr const & r ) const - { - return px == r.px && pn == r.pn; - } - -// Tasteless as this may seem, making all members public allows member templates -// to work in the absence of member template friends. (Matthew Langston) - -private: - - template friend class shared_ptr; - template friend class weak_ptr; - - T * px; // contained pointer - booster::detail::shared_count pn; // reference counter - -}; // shared_ptr - -template inline bool operator==(shared_ptr const & a, shared_ptr const & b) -{ - return a.get() == b.get(); -} - -template inline bool operator!=(shared_ptr const & a, shared_ptr const & b) -{ - return a.get() != b.get(); -} - -template inline bool operator<(shared_ptr const & a, shared_ptr const & b) -{ - return a._internal_less(b); -} - -template inline void swap(shared_ptr & a, shared_ptr & b) -{ - a.swap(b); -} - -template shared_ptr static_pointer_cast(shared_ptr const & r) -{ - return shared_ptr(r, booster::detail::static_cast_tag()); -} - -template shared_ptr const_pointer_cast(shared_ptr const & r) -{ - return shared_ptr(r, booster::detail::const_cast_tag()); -} - -template shared_ptr dynamic_pointer_cast(shared_ptr const & r) -{ - return shared_ptr(r, booster::detail::dynamic_cast_tag()); -} - -// shared_*_cast names are deprecated. Use *_pointer_cast instead. - -template shared_ptr shared_static_cast(shared_ptr const & r) -{ - return shared_ptr(r, booster::detail::static_cast_tag()); -} - -template shared_ptr shared_dynamic_cast(shared_ptr const & r) -{ - return shared_ptr(r, booster::detail::dynamic_cast_tag()); -} - -template shared_ptr shared_polymorphic_cast(shared_ptr const & r) -{ - return shared_ptr(r, booster::detail::polymorphic_cast_tag()); -} - -template shared_ptr shared_polymorphic_downcast(shared_ptr const & r) -{ - assert(dynamic_cast(r.get()) == r.get()); - return shared_static_cast(r); -} - -// get_pointer() enables boost::mem_fn to recognize shared_ptr - -template inline T * get_pointer(shared_ptr const & p) -{ - return p.get(); -} - -// operator<< - -template std::ostream & operator<< (std::ostream & os, shared_ptr const & p) -{ - os << p.get(); - return os; -} - -// get_deleter - -template D * get_deleter(shared_ptr const & p) -{ - return static_cast(p._internal_get_deleter(BOOSTER_SP_TYPEID(D))); -} - -} // namespace boost + template + using shared_ptr = std::shared_ptr; -#ifdef BOOSTER_MSVC -# pragma warning(pop) -#endif + using std::dynamic_pointer_cast; + using std::static_pointer_cast; + +} // namespace booster #endif // #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED diff --git a/booster/booster/smart_ptr/shared_count.h b/booster/booster/smart_ptr/shared_count.h index cb82b01f..1bf10399 100644 --- a/booster/booster/smart_ptr/shared_count.h +++ b/booster/booster/smart_ptr/shared_count.h @@ -1,289 +1,4 @@ #ifndef BOOSTER_SMART_PTR_DETAIL_SHARED_COUNT_HPP_INCLUDED #define BOOSTER_SMART_PTR_DETAIL_SHARED_COUNT_HPP_INCLUDED -// -// detail/shared_count.hpp -// -// Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd. -// Copyright 2004-2005 Peter Dimov -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// - -#ifdef __BORLANDC__ -# pragma warn -8027 // Functions containing try are not expanded inline -#endif - -#include -#include -#include -#include -#include -#include -#include // std::less -#include // std::bad_alloc - -namespace booster -{ - -namespace detail -{ - -struct sp_nothrow_tag {}; - -class weak_count; - -class shared_count -{ -private: - - sp_counted_base * pi_; - - friend class weak_count; - -public: - - shared_count(): pi_(0) // nothrow - { - } - - template explicit shared_count( Y * p ): pi_( 0 ) - { - try - { - pi_ = new sp_counted_impl_p( p ); - } - catch(...) - { - booster::checked_delete( p ); - throw; - } - } - - template shared_count( P p, D d ): pi_(0) - { - try - { - pi_ = new sp_counted_impl_pd(p, d); - } - catch(...) - { - d(p); // delete p - throw; - } - } - - template shared_count( P p, D d, A a ): pi_( 0 ) - { - typedef sp_counted_impl_pda impl_type; - typedef typename A::template rebind< impl_type >::other A2; - - A2 a2( a ); - - try - { - pi_ = a2.allocate( 1, static_cast< impl_type* >( 0 ) ); - new( static_cast< void* >( pi_ ) ) impl_type( p, d, a ); - } - catch(...) - { - d( p ); - - if( pi_ != 0 ) - { - a2.deallocate( static_cast< impl_type* >( pi_ ), 1 ); - } - - throw; - } - - } - - // auto_ptr is special cased to provide the strong guarantee - - template - explicit shared_count( std::unique_ptr & r ): pi_( new sp_counted_impl_p( r.get() ) ) - { - - r.release(); - } - - - ~shared_count() // nothrow - { - if( pi_ != 0 ) pi_->release(); - } - - shared_count(shared_count const & r): pi_(r.pi_) // nothrow - { - if( pi_ != 0 ) pi_->add_ref_copy(); - } - - explicit shared_count(weak_count const & r); // throws bad_weak_ptr when r.use_count() == 0 - shared_count( weak_count const & r, sp_nothrow_tag ); // constructs an empty *this when r.use_count() == 0 - - shared_count & operator= (shared_count const & r) // nothrow - { - sp_counted_base * tmp = r.pi_; - - if( tmp != pi_ ) - { - if( tmp != 0 ) tmp->add_ref_copy(); - if( pi_ != 0 ) pi_->release(); - pi_ = tmp; - } - - return *this; - } - - void swap(shared_count & r) // nothrow - { - sp_counted_base * tmp = r.pi_; - r.pi_ = pi_; - pi_ = tmp; - } - - long use_count() const // nothrow - { - return pi_ != 0? pi_->use_count(): 0; - } - - bool unique() const // nothrow - { - return use_count() == 1; - } - - bool empty() const // nothrow - { - return pi_ == 0; - } - - friend inline bool operator==(shared_count const & a, shared_count const & b) - { - return a.pi_ == b.pi_; - } - - friend inline bool operator<(shared_count const & a, shared_count const & b) - { - return std::less()( a.pi_, b.pi_ ); - } - - void * get_deleter( sp_typeinfo const & ti ) const - { - return pi_? pi_->get_deleter( ti ): 0; - } -}; - - -class weak_count -{ -private: - - sp_counted_base * pi_; - - friend class shared_count; - -public: - - weak_count(): pi_(0) // nothrow - { - } - - weak_count(shared_count const & r): pi_(r.pi_) // nothrow - { - if(pi_ != 0) pi_->weak_add_ref(); - } - - weak_count(weak_count const & r): pi_(r.pi_) // nothrow - { - if(pi_ != 0) pi_->weak_add_ref(); - } - - - ~weak_count() // nothrow - { - if(pi_ != 0) pi_->weak_release(); - } - - weak_count & operator= (shared_count const & r) // nothrow - { - sp_counted_base * tmp = r.pi_; - - if( tmp != pi_ ) - { - if(tmp != 0) tmp->weak_add_ref(); - if(pi_ != 0) pi_->weak_release(); - pi_ = tmp; - } - - return *this; - } - - weak_count & operator= (weak_count const & r) // nothrow - { - sp_counted_base * tmp = r.pi_; - - if( tmp != pi_ ) - { - if(tmp != 0) tmp->weak_add_ref(); - if(pi_ != 0) pi_->weak_release(); - pi_ = tmp; - } - - return *this; - } - - void swap(weak_count & r) // nothrow - { - sp_counted_base * tmp = r.pi_; - r.pi_ = pi_; - pi_ = tmp; - } - - long use_count() const // nothrow - { - return pi_ != 0? pi_->use_count(): 0; - } - - bool empty() const // nothrow - { - return pi_ == 0; - } - - friend inline bool operator==(weak_count const & a, weak_count const & b) - { - return a.pi_ == b.pi_; - } - - friend inline bool operator<(weak_count const & a, weak_count const & b) - { - return std::less()(a.pi_, b.pi_); - } -}; - -inline shared_count::shared_count( weak_count const & r ): pi_( r.pi_ ) -{ - if( pi_ == 0 || !pi_->add_ref_lock() ) - { - throw booster::bad_weak_ptr(); - } -} - -inline shared_count::shared_count( weak_count const & r, sp_nothrow_tag ): pi_( r.pi_ ) -{ - if( pi_ != 0 && !pi_->add_ref_lock() ) - { - pi_ = 0; - } -} - -} // namespace detail - -} // namespace boost - -#ifdef __BORLANDC__ -# pragma warn .8027 // Functions containing try are not expanded inline -#endif #endif // #ifndef BOOST_SMART_PTR_DETAIL_SHARED_COUNT_HPP_INCLUDED diff --git a/booster/booster/smart_ptr/sp_counted_base.h b/booster/booster/smart_ptr/sp_counted_base.h index fb0ebffa..33e3c96b 100644 --- a/booster/booster/smart_ptr/sp_counted_base.h +++ b/booster/booster/smart_ptr/sp_counted_base.h @@ -1,81 +1,5 @@ #ifndef BOOSTER_SMART_PTR_DETAIL_SP_COUNTED_BASE_SPIN_HPP_INCLUDED #define BOOSTER_SMART_PTR_DETAIL_SP_COUNTED_BASE_SPIN_HPP_INCLUDED -// -// detail/sp_counted_base_spin.hpp - spinlock pool atomic emulation -// -// Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd. -// Copyright 2004-2008 Peter Dimov -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// - -#include -#include - -#ifndef BOOSTER_WIN32 -#include -#endif - -namespace booster -{ - - namespace detail - { - - typedef union sp_counted_base_atomic { - int i; - unsigned int ui; - long int li; - unsigned long int uli; - long long int lli; - unsigned long long int ulli; - char at_least[8]; - } sp_counted_base_atomic_type; - - - class BOOSTER_API sp_counted_base - { - private: - - sp_counted_base( sp_counted_base const & ); - sp_counted_base & operator= ( sp_counted_base const & ); - - typedef sp_counted_base_atomic_type atomic_type; - - mutable atomic_type use_count_; // #shared - mutable atomic_type weak_count_; // #weak + (#shared != 0) -#ifndef BOOSTER_WIN32 - mutable pthread_mutex_t lock_; -#endif - - public: - - sp_counted_base(); - virtual ~sp_counted_base(); // nothrow - - // dispose() is called when use_count_ drops to zero, to release - // the resources managed by *this. - - virtual void dispose() = 0; // nothrow - - // destroy() is called when weak_count_ drops to zero. - - virtual void destroy(); // nothrow - virtual void * get_deleter( sp_typeinfo const & ti ) = 0; - void add_ref_copy(); - bool add_ref_lock(); // true on success - void release(); // nothrow - void weak_add_ref(); // nothrow - void weak_release(); // nothrow - long use_count() const; // nothrow - }; - - } // namespace detail - -} // namespace boost - #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_SPIN_HPP_INCLUDED // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/booster/booster/weak_ptr.h b/booster/booster/weak_ptr.h index 87c392e7..f2592fed 100644 --- a/booster/booster/weak_ptr.h +++ b/booster/booster/weak_ptr.h @@ -1,163 +1,14 @@ #ifndef BOOSTER_SMART_PTR_WEAK_PTR_HPP_INCLUDED #define BOOSTER_SMART_PTR_WEAK_PTR_HPP_INCLUDED -// -// weak_ptr.hpp -// -// Copyright (c) 2001, 2002, 2003 Peter Dimov -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// See http://www.boost.org/libs/smart_ptr/weak_ptr.htm for documentation. -// +#include +#include -#include // boost.TR1 include order fix -#include -#include +namespace booster { -#ifdef BOOSTER_MSVC // moved here to work around VC++ compiler crash -# pragma warning(push) -# pragma warning(disable:4284) // odd return type for operator-> -#endif +template +using weak_ptr = std::weak_ptr; -namespace booster -{ - -template class weak_ptr -{ -private: - - // Borland 5.5.1 specific workarounds - typedef weak_ptr this_type; - -public: - - typedef T element_type; - - weak_ptr(): px(0), pn() // never throws in 1.30+ - { - } - -// generated copy constructor, assignment, destructor are fine - - -// -// The "obvious" converting constructor implementation: -// -// template -// weak_ptr(weak_ptr const & r): px(r.px), pn(r.pn) // never throws -// { -// } -// -// has a serious problem. -// -// r.px may already have been invalidated. The px(r.px) -// conversion may require access to *r.px (virtual inheritance). -// -// It is not possible to avoid spurious access violations since -// in multithreaded programs r.px may be invalidated at any point. -// - - template - weak_ptr( weak_ptr const & r, typename detail::sp_enable_if_convertible::type = detail::sp_empty() ) - : px(r.lock().get()), pn(r.pn) // never throws - { - } - - - template - weak_ptr( shared_ptr const & r, typename detail::sp_enable_if_convertible::type = detail::sp_empty() ) - : px( r.px ), pn( r.pn ) // never throws - { - } - - template - weak_ptr & operator=(weak_ptr const & r) // never throws - { - px = r.lock().get(); - pn = r.pn; - return *this; - } - - template - weak_ptr & operator=(shared_ptr const & r) // never throws - { - px = r.px; - pn = r.pn; - return *this; - } - - shared_ptr lock() const // never throws - { - return shared_ptr( *this, booster::detail::sp_nothrow_tag() ); - } - - long use_count() const // never throws - { - return pn.use_count(); - } - - bool expired() const // never throws - { - return pn.use_count() == 0; - } - - bool _empty() const // extension, not in std::weak_ptr - { - return pn.empty(); - } - - void reset() // never throws in 1.30+ - { - this_type().swap(*this); - } - - void swap(this_type & other) // never throws - { - std::swap(px, other.px); - pn.swap(other.pn); - } - - void _internal_assign(T * px2, booster::detail::shared_count const & pn2) - { - px = px2; - pn = pn2; - } - - template bool _internal_less(weak_ptr const & rhs) const - { - return pn < rhs.pn; - } - -// Tasteless as this may seem, making all members public allows member templates -// to work in the absence of member template friends. (Matthew Langston) - -private: - - template friend class weak_ptr; - template friend class shared_ptr; - - T * px; // contained pointer - booster::detail::weak_count pn; // reference counter - -}; // weak_ptr - -template inline bool operator<(weak_ptr const & a, weak_ptr const & b) -{ - return a._internal_less(b); -} - -template void swap(weak_ptr & a, weak_ptr & b) -{ - a.swap(b); -} - -} // namespace boost - -#ifdef BOOSTER_MSVC -# pragma warning(pop) -#endif +} // namespace booster #endif // #ifndef BOOST_SMART_PTR_WEAK_PTR_HPP_INCLUDED diff --git a/booster/lib/locale/src/posix/codecvt.cpp b/booster/lib/locale/src/posix/codecvt.cpp index 61ffb0b7..06c698b2 100644 --- a/booster/lib/locale/src/posix/codecvt.cpp +++ b/booster/lib/locale/src/posix/codecvt.cpp @@ -221,7 +221,7 @@ namespace impl_posix { catch(std::exception const &e) { // Nothing to do, just retrun empty cvt } - return std::move(cvt); + return cvt; } #else // no iconv diff --git a/booster/lib/locale/src/shared/localization_backend.cpp b/booster/lib/locale/src/shared/localization_backend.cpp index 21b6f595..3ee6f408 100644 --- a/booster/lib/locale/src/shared/localization_backend.cpp +++ b/booster/lib/locale/src/shared/localization_backend.cpp @@ -53,11 +53,11 @@ namespace booster { for(unsigned i=0;i res(new actual_backend(backends,default_backends_)); - return std::move(res); + return res; } void add_backend(std::string const &name,std::unique_ptr backend_ptr) { - booster::shared_ptr sptr(backend_ptr); + booster::shared_ptr sptr(std::move(backend_ptr)); if(all_backends_.empty()) { all_backends_.push_back(std::make_pair(name,sptr)); for(unsigned i=0;i +#include #include "mo_hash.h" @@ -650,12 +651,12 @@ namespace booster { if(!plural.empty()) { std::unique_ptr ptr=lambda::compile(plural.c_str()); - plural_forms_[id] = ptr; + plural_forms_[id] = std::move(ptr); } if( mo_useable_directly(mo_encoding,*mo) ) { - mo_catalogs_[id]=mo; + mo_catalogs_[id]=std::move(mo); } else { converter cvt_value(locale_encoding,mo_encoding); diff --git a/booster/lib/locale/src/shared/mo_lambda.cpp b/booster/lib/locale/src/shared/mo_lambda.cpp index b30a6e39..952344cf 100644 --- a/booster/lib/locale/src/shared/mo_lambda.cpp +++ b/booster/lib/locale/src/shared/mo_lambda.cpp @@ -71,7 +71,7 @@ namespace { // anon #define UNOP(name,oper) \ struct name: public unary { \ - name(plural_ptr op) : unary(op) \ + name(plural_ptr op) : unary(std::move(op)) \ { \ }; \ virtual int operator()(int n) const \ @@ -81,7 +81,7 @@ namespace { // anon virtual name *clone() const \ { \ plural_ptr op1_copy(op1->clone()); \ - return new name(op1_copy); \ + return new name(std::move(op1_copy)); \ } \ }; @@ -89,7 +89,7 @@ namespace { // anon struct name : public binary \ { \ name(plural_ptr p1,plural_ptr p2) : \ - binary(p1,p2) \ + binary(std::move(p1),std::move(p2)) \ { \ } \ \ @@ -101,14 +101,14 @@ namespace { // anon { \ plural_ptr op1_copy(op1->clone()); \ plural_ptr op2_copy(op2->clone()); \ - return new name(op1_copy,op2_copy); \ + return new name(std::move(op1_copy),std::move(op2_copy)); \ } \ }; #define BINOPD(name,oper) \ struct name : public binary { \ name(plural_ptr p1,plural_ptr p2) : \ - binary(p1,p2) \ + binary(std::move(p1),std::move(p2)) \ { \ } \ virtual int operator()(int n) const \ @@ -121,7 +121,7 @@ namespace { // anon { \ plural_ptr op1_copy(op1->clone()); \ plural_ptr op2_copy(op2->clone()); \ - return new name(op1_copy,op2_copy); \ + return new name(std::move(op1_copy),std::move(op2_copy)); \ } \ }; @@ -291,7 +291,7 @@ namespace { // anon int o=t.get(); \ if((op2=hexpr()).get()==0) \ return plural_ptr(); \ - op1=bin_factory(o,op1,op2); \ + op1=bin_factory(o,std::move(op1),std::move(op2)); \ } \ return op1; \ } @@ -307,7 +307,7 @@ namespace { // anon if(res.get() && t.next()!=END) { return plural_ptr(); }; - return std::move(res); + return res; } private: @@ -321,7 +321,7 @@ namespace { // anon return plural_ptr(); if(t.get()!=')') return plural_ptr(); - return std::move(op); + return op; } else if(t.next()==NUM) { int value; @@ -385,7 +385,7 @@ namespace { // anon return plural_ptr(); } else { - return std::move(cond); + return cond; } return plural_ptr(new conditional(std::move(cond),std::move(case1),std::move(case2))); } diff --git a/booster/lib/smart_ptr/src/sp_counted_base.cpp b/booster/lib/smart_ptr/src/sp_counted_base.cpp index db367783..3314903d 100644 --- a/booster/lib/smart_ptr/src/sp_counted_base.cpp +++ b/booster/lib/smart_ptr/src/sp_counted_base.cpp @@ -1,399 +1,2 @@ -#define BOOSTER_SOURCE -// -// detail/sp_counted_base_spin.hpp - spinlock pool atomic emulation -// -// Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd. -// Copyright 2004-2008 Peter Dimov -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// - -#include -#include - -#undef SP_ATOMIC - - -#if defined BOOSTER_WIN32 - -/////////////// -// Windows -/////////////// - -# include -# define SP_ATOMIC - -namespace booster { - namespace detail { - - static bool atomic_cas(sp_counted_base_atomic_type volatile *pw,int old_value,int new_value) - { - return InterlockedCompareExchange(&pw->li,new_value,old_value)==old_value; - } - - static int atomic_get(sp_counted_base_atomic_type volatile *pw) - { - long v=pw->li; - while(!atomic_cas(pw,v,v)) { - v=pw->li; - } - return v; - } - - static void atomic_set(sp_counted_base_atomic_type volatile *pw,int v) - { - long vo=pw->li; - while(!atomic_cas(pw,vo,v)) { - vo=pw->li; - } - } - static int atomic_exchange_and_add(sp_counted_base_atomic_type volatile * pw, int dv) - { - long vo=pw->li,tmp; - for(;;){ - if((tmp=InterlockedCompareExchange(&pw->li,vo+dv,vo)) == vo) - break; - vo = tmp; - } - return tmp; - } - - static void atomic_increment(sp_counted_base_atomic_type volatile *pw) - { - InterlockedIncrement(&pw->li); - } - - } //details -} // booster - -#elif defined BOOSTER_HAVE_MAC_OS_X_ATOMIC - -//////////// -// Mac OS X -//////////// - -namespace booster { - namespace detail { - -# include -# define SP_ATOMIC - - static bool atomic_cas(sp_counted_base_atomic_type volatile *pw,int old_value,int new_value) - { - // Older versions get non-volatile parameter - return OSAtomicCompareAndSwap32(old_value,new_value,const_cast(&pw->i)); - } - static int atomic_get(sp_counted_base_atomic_type volatile *pw) - { - OSMemoryBarrier(); - return pw->i; - } - - static void atomic_set(sp_counted_base_atomic_type volatile *pw,int v) - { - pw->i=v; - OSMemoryBarrier(); - } - static int atomic_exchange_and_add(sp_counted_base_atomic_type volatile * pw, int dv) - { - // Older versions get non-volatile parameter - return OSAtomicAdd32(dv,const_cast(&pw->i))-dv; - } - static void atomic_increment(sp_counted_base_atomic_type volatile *pw) - { - atomic_exchange_and_add(pw,1); - } - } // detail -} // booster - - -#elif defined BOOSTER_HAVE_FREEBSD_ATOMIC - -//////////// -// FreeBSD -/////////// - -namespace booster { - namespace detail { - -# include -# include -# define SP_ATOMIC - - static bool atomic_cas(sp_counted_base_atomic_type volatile *pw,int old_value,int new_value) - { - return atomic_cmpset_int(&pw->ui,old_value,new_value); - } - static int atomic_get(sp_counted_base_atomic_type volatile *pw) - { - return atomic_load_acq_int(&pw->ui); - } - - static void atomic_set(sp_counted_base_atomic_type volatile *pw,int v) - { - atomic_store_rel_int(&pw->ui,v); - } - static int atomic_exchange_and_add(sp_counted_base_atomic_type volatile * pw, int dv) - { - return atomic_fetchadd_int(&pw->ui,dv); - } - static void atomic_increment(sp_counted_base_atomic_type volatile *pw) - { - atomic_exchange_and_add(pw,1); - } - } // detail -} // booster -#elif defined BOOSTER_HAVE_SOLARIS_ATOMIC -/////////////// -// Sun Solaris -/////////////// - -# include -# define SP_ATOMIC - -namespace booster { - namespace detail { - - - static bool atomic_cas(sp_counted_base_atomic_type volatile *pw,int old_value,int new_value) - { - return atomic_cas_uint(&pw->ui,unsigned(old_value),unsigned(new_value))==unsigned(old_value); - } - static int atomic_get(sp_counted_base_atomic_type volatile *pw) - { - membar_consumer(); - return pw->i; - } - - static void atomic_set(sp_counted_base_atomic_type volatile *pw,int v) - { - membar_producer(); - pw->i=v; - } - static int atomic_exchange_and_add(sp_counted_base_atomic_type volatile * pw, int dv) - { - return atomic_add_int_nv(&pw->ui,dv)-dv; - } - static void atomic_increment(sp_counted_base_atomic_type volatile *pw) - { - atomic_add_int(&pw->ui,1); - } - } // detail -} // booster - -#elif defined BOOSTER_HAS_GCC_SYNC -////////////////////////// -// GCC __sync_ -///////////////////////// - -# define SP_ATOMIC -namespace booster { - namespace detail { - - static int atomic_get(sp_counted_base_atomic_type volatile *pw) - { - __sync_synchronize(); - return pw->i; - } - static void atomic_set(sp_counted_base_atomic_type volatile *pw,int v) - { - pw->i=v; - __sync_synchronize(); - } - static bool atomic_cas(sp_counted_base_atomic_type volatile *pw,int old_value,int new_value) - { - return __sync_bool_compare_and_swap(&pw->i,old_value,new_value); - } - static int atomic_exchange_and_add(sp_counted_base_atomic_type volatile * pw, int dv) - { - return __sync_fetch_and_add(&pw->i,dv); - } - static void atomic_increment( sp_counted_base_atomic_type volatile * pw) - { - atomic_exchange_and_add(pw,1); - } - } -} - -#endif // Any atomic op - - -////////////// -// Implementation -//////////////// - -namespace booster -{ - - namespace detail - { - -#if defined SP_ATOMIC - - // We have full atomic operations support - - inline int atomic_conditional_increment( sp_counted_base_atomic_type * pw) - { - for(;;) { - int rv = atomic_get(pw); - if(rv == 0) - return 0; - if(atomic_cas(pw,rv,rv+1)) - return rv; - } - } - - sp_counted_base::sp_counted_base() - { - atomic_set(&use_count_,1); - atomic_set(&weak_count_,1); - } - - sp_counted_base::~sp_counted_base() // nothrow - { - } - - void sp_counted_base::add_ref_copy() - { - atomic_increment( &use_count_ ); - } - - bool sp_counted_base::add_ref_lock() // true on success - { - return atomic_conditional_increment( &use_count_ ) != 0; - } - - void sp_counted_base::release() // nothrow - { - if( atomic_exchange_and_add( &use_count_, -1 ) == 1 ) - { - dispose(); - weak_release(); - } - } - - void sp_counted_base::weak_add_ref() // nothrow - { - atomic_increment( &weak_count_); - } - - void sp_counted_base::weak_release() // nothrow - { - if( atomic_exchange_and_add( &weak_count_, -1) == 1 ) - { - destroy(); - } - } - - long sp_counted_base::use_count() const // nothrow - { - return atomic_get(&use_count_); - } - -#else // PTHREAD - - inline int atomic_exchange_and_add( sp_counted_base_atomic_type * pw, int dv, pthread_mutex_t *m) - { - pthread_mutex_lock(m); - int r = pw->i; - pw->i += dv; - pthread_mutex_unlock(m); - return r; - } - - inline void atomic_increment( sp_counted_base_atomic_type * pw , pthread_mutex_t *m) - { - pthread_mutex_lock(m); - ++(pw->i); - pthread_mutex_unlock(m); - } - - inline int atomic_conditional_increment( sp_counted_base_atomic_type * pw , pthread_mutex_t *m) - { - pthread_mutex_lock(m); - int rv = pw->i; - if( rv != 0 ) ++(pw->i); - pthread_mutex_unlock(m); - return rv; - } - - inline void atomic_set(sp_counted_base_atomic_type *pw,int v, pthread_mutex_t *m) - { - pthread_mutex_lock(m); - pw->i=v; - pthread_mutex_unlock(m); - } - - inline int atomic_get(sp_counted_base_atomic_type *pw, pthread_mutex_t *m) - { - pthread_mutex_lock(m); - int r=pw->i; - pthread_mutex_unlock(m); - return r; - } - - - sp_counted_base::sp_counted_base() - { - pthread_mutex_init(&lock_,0); - atomic_set(&use_count_,1,&lock_); - atomic_set(&weak_count_,1,&lock_); - } - - sp_counted_base::~sp_counted_base() // nothrow - { - pthread_mutex_destroy(&lock_); - } - - void sp_counted_base::add_ref_copy() - { - atomic_increment( &use_count_ ,&lock_); - } - - bool sp_counted_base::add_ref_lock() // true on success - { - return atomic_conditional_increment( &use_count_ ,&lock_) != 0; - } - - void sp_counted_base::release() // nothrow - { - if( atomic_exchange_and_add( &use_count_, -1 ,&lock_) == 1 ) - { - dispose(); - weak_release(); - } - } - - void sp_counted_base::weak_add_ref() // nothrow - { - atomic_increment( &weak_count_,&lock_ ); - } - - void sp_counted_base::weak_release() // nothrow - { - if( atomic_exchange_and_add( &weak_count_, -1 ,&lock_) == 1 ) - { - destroy(); - } - } - - long sp_counted_base::use_count() const // nothrow - { - return atomic_get(&use_count_,&lock_); - } - -#endif // pthreads - - void sp_counted_base::destroy() // nothrow - { - delete this; - } - - - } // namespace detail - -} // namespace boost // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/booster/lib/smart_ptr/test/test_sp_counter.cpp b/booster/lib/smart_ptr/test/test_sp_counter.cpp index 4e768ccc..b716900b 100644 --- a/booster/lib/smart_ptr/test/test_sp_counter.cpp +++ b/booster/lib/smart_ptr/test/test_sp_counter.cpp @@ -7,69 +7,71 @@ // #include "test.h" -#include -#include +// this class is not longer needed -class counted : public booster::detail::sp_counted_base { -public: - virtual void dispose() {} - virtual void *get_deleter(booster::detail::sp_typeinfo const &) { return 0; } - counted() { - counter++; - } - virtual ~counted() { - counter--; - } - static int counter; -}; +//#include +//#include -int counted::counter; +// class counted : public booster::detail::sp_counted_base { +// public: +// virtual void dispose() {} +// virtual void *get_deleter(booster::detail::sp_typeinfo const &) { return 0; } +// counted() { +// counter++; +// } +// virtual ~counted() { +// counter--; +// } +// static int counter; +// }; + +// int counted::counter; int main() { - try { - booster::detail::sp_counted_base *sp=new counted(); - TEST(counted::counter==1); - TEST(sp->use_count()==1); - sp->add_ref_copy(); - TEST(sp->use_count()==2); - sp->add_ref_copy(); - TEST(sp->use_count()==3); - sp->release(); - TEST(sp->use_count()==2); - sp->weak_add_ref(); - TEST(sp->use_count()==2); - TEST(sp->add_ref_lock()==true); - TEST(sp->use_count()==3); - sp->release(); - sp->release(); - TEST(sp->use_count()==1); - sp->release(); - TEST(counted::counter==1); - TEST(sp->use_count()==0); - TEST(counted::counter==1); - TEST(sp->add_ref_lock()==false); - TEST(counted::counter==1); - sp->weak_release(); - TEST(counted::counter==0); - sp=new counted(); - TEST(counted::counter==1); - sp->release(); - TEST(counted::counter==0); - sp=new counted(); - TEST(counted::counter==1); - sp->weak_add_ref(); - TEST(counted::counter==1); - sp->weak_release(); - TEST(counted::counter==1); - sp->release(); - TEST(counted::counter==0); - sp=0; - } - catch(std::exception const &e) { - std::cerr << "Fail" << e.what() << std::endl; - return 1; - } - std::cout << "Ok" << std::endl; + // try { + // booster::detail::sp_counted_base *sp=new counted(); + // TEST(counted::counter==1); + // TEST(sp->use_count()==1); + // sp->add_ref_copy(); + // TEST(sp->use_count()==2); + // sp->add_ref_copy(); + // TEST(sp->use_count()==3); + // sp->release(); + // TEST(sp->use_count()==2); + // sp->weak_add_ref(); + // TEST(sp->use_count()==2); + // TEST(sp->add_ref_lock()==true); + // TEST(sp->use_count()==3); + // sp->release(); + // sp->release(); + // TEST(sp->use_count()==1); + // sp->release(); + // TEST(counted::counter==1); + // TEST(sp->use_count()==0); + // TEST(counted::counter==1); + // TEST(sp->add_ref_lock()==false); + // TEST(counted::counter==1); + // sp->weak_release(); + // TEST(counted::counter==0); + // sp=new counted(); + // TEST(counted::counter==1); + // sp->release(); + // TEST(counted::counter==0); + // sp=new counted(); + // TEST(counted::counter==1); + // sp->weak_add_ref(); + // TEST(counted::counter==1); + // sp->weak_release(); + // TEST(counted::counter==1); + // sp->release(); + // TEST(counted::counter==0); + // sp=0; + // } + // catch(std::exception const &e) { + // std::cerr << "Fail" << e.what() << std::endl; + // return 1; + // } + // std::cout << "Ok" << std::endl; return 0; } diff --git a/cppcms/application.h b/cppcms/application.h index 94377df0..c2e4d21b 100644 --- a/cppcms/application.h +++ b/cppcms/application.h @@ -14,6 +14,7 @@ #include #include #include +#include #include namespace cppcms { diff --git a/private/string_map.h b/private/string_map.h index b4980cc0..fa94c11e 100644 --- a/private/string_map.h +++ b/private/string_map.h @@ -13,6 +13,7 @@ #include #include #include +#include #include namespace cppcms { diff --git a/src/application.cpp b/src/application.cpp index ea65c773..8e2eb3c7 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -125,7 +125,7 @@ bool application::has_context() bool application::owns_context() { - return root()->d->conn; + return !!root()->d->conn; } booster::shared_ptr application::release_context() diff --git a/src/applications_pool.cpp b/src/applications_pool.cpp index 4a492763..db9d4b15 100644 --- a/src/applications_pool.cpp +++ b/src/applications_pool.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git a/src/http_api.cpp b/src/http_api.cpp index f2bf8cd1..359999c8 100644 --- a/src/http_api.cpp +++ b/src/http_api.cpp @@ -78,7 +78,7 @@ namespace cgi { } private: - typedef std::set connections_type; + typedef std::set> connections_type; connections_type connections_; booster::aio::deadline_timer timer_; }; diff --git a/tests/pool_test.cpp b/tests/pool_test.cpp index 9b7e8bd3..6616d7e5 100644 --- a/tests/pool_test.cpp +++ b/tests/pool_test.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "client.h" #include #include @@ -166,9 +167,9 @@ class tester : public cppcms::application { counter::instance(request().get("id"))->print(response().out()); else if(name=="/unmount") { std::string id = request().get("id"); - bool exists_before = weak_pools[id].lock(); + bool exists_before = !weak_pools[id].expired(); service().applications_pool().unmount(weak_pools[id]); - bool exists_after = weak_pools[id].lock(); + bool exists_after = !weak_pools[id].expired(); response().out()<<"unmount=" << id << "\n" "before="< Date: Fri, 29 Jun 2018 11:24:47 +0200 Subject: [PATCH 3/3] Further cleanup - remaining std::auto_ptr - redundant std::move when returning from a function - (consider using std::unique_ptr instead of naked new) --- booster/booster/locale/generic_codecvt.h | 2 +- booster/booster/locale/util.h | 2 +- booster/booster/nowide/fstream.h | 9 ++++----- booster/lib/locale/src/icu/boundary.cpp | 2 +- booster/lib/locale/src/icu/codecvt.cpp | 2 +- booster/lib/locale/src/icu/formatter.cpp | 10 +++++----- booster/lib/locale/src/icu/formatter.h | 4 ++-- booster/lib/locale/src/icu/time_zone.cpp | 2 +- booster/lib/locale/src/posix/codecvt.cpp | 5 ++--- .../locale/src/shared/localization_backend.cpp | 2 +- .../lib/locale/src/util/codecvt_converter.cpp | 7 +++---- contrib/server_side/sessions/storage_test.cpp | 2 +- cppcms/applications_pool.h | 18 ++++++------------ cppcms/views_pool.h | 5 ++--- src/aes.cpp | 4 ++-- src/aes_encryptor.cpp | 4 +--- src/crypto.cpp | 8 +++----- src/fastcgi_api.cpp | 9 +++------ src/hmac_encryptor.cpp | 4 +--- src/http_api.cpp | 3 +-- src/scgi_api.cpp | 9 +++------ src/service.cpp | 2 +- src/session_win32_file_storage.cpp | 2 +- src/views_pool.cpp | 7 +++---- 24 files changed, 50 insertions(+), 74 deletions(-) diff --git a/booster/booster/locale/generic_codecvt.h b/booster/booster/locale/generic_codecvt.h index 82b306e3..f17c27c1 100644 --- a/booster/booster/locale/generic_codecvt.h +++ b/booster/booster/locale/generic_codecvt.h @@ -115,7 +115,7 @@ class generic_codecvt_base { /// { /// UErrorCode err = U_ZERO_ERROR; /// state_type ptr(ucnv_safeClone(converter_,0,0,&err,ucnv_close); -/// return std::move(ptr); +/// return ptr; /// } /// /// boost::locale::utf::code_point to_unicode(state_type &ptr,char const *&begin,char const *end) const diff --git a/booster/booster/locale/util.h b/booster/booster/locale/util.h index f63540fe..2d8a3c92 100644 --- a/booster/booster/locale/util.h +++ b/booster/booster/locale/util.h @@ -182,7 +182,7 @@ namespace util { /// character encodings like ISO-8859-1, koi8-r, windows-1255 and Unicode code points, /// /// If \a encoding is not supported, empty pointer is returned. You should check if - /// std::auto_ptr::get() != 0 + /// std::unique_ptr::get() != 0 /// BOOSTER_API std::unique_ptr create_simple_converter(std::string const &encoding); diff --git a/booster/booster/nowide/fstream.h b/booster/booster/nowide/fstream.h index a52b4b2c..ff9fa45e 100644 --- a/booster/booster/nowide/fstream.h +++ b/booster/booster/nowide/fstream.h @@ -146,8 +146,7 @@ namespace nowide { return 0; } } - std::auto_ptr dev(new details::stdio_iodev(f)); - device(dev); + device(std::unique_ptr(new details::stdio_iodev(f))); opened_ = true; return this; } @@ -272,7 +271,7 @@ namespace nowide { } private: - std::auto_ptr buf_; + std::unique_ptr buf_; }; /// @@ -332,7 +331,7 @@ namespace nowide { } private: - std::auto_ptr buf_; + std::unique_ptr buf_; }; /// @@ -392,7 +391,7 @@ namespace nowide { } private: - std::auto_ptr buf_; + std::unique_ptr buf_; }; diff --git a/booster/lib/locale/src/icu/boundary.cpp b/booster/lib/locale/src/icu/boundary.cpp index f776e440..4ec9d429 100644 --- a/booster/lib/locale/src/icu/boundary.cpp +++ b/booster/lib/locale/src/icu/boundary.cpp @@ -128,7 +128,7 @@ std::unique_ptr get_iterator(boundary_type t,icu::Locale con check_and_throw_icu_error(err); if(!bi.get()) throw booster::runtime_error("Failed to create break iterator"); - return std::move(bi); + return bi; } diff --git a/booster/lib/locale/src/icu/codecvt.cpp b/booster/lib/locale/src/icu/codecvt.cpp index 1fbeee4e..d431f5da 100644 --- a/booster/lib/locale/src/icu/codecvt.cpp +++ b/booster/lib/locale/src/icu/codecvt.cpp @@ -128,7 +128,7 @@ namespace impl_icu { { // no encoding so we return empty pointer } - return std::move(cvt); + return cvt; } std::locale create_codecvt(std::locale const &in,std::string const &encoding,character_facet_type type) diff --git a/booster/lib/locale/src/icu/formatter.cpp b/booster/lib/locale/src/icu/formatter.cpp index 300e1863..11f1af86 100644 --- a/booster/lib/locale/src/icu/formatter.cpp +++ b/booster/lib/locale/src/icu/formatter.cpp @@ -389,7 +389,7 @@ namespace locale { if(disp == posix) - return std::move(fmt); + return fmt; UErrorCode err=U_ZERO_ERROR; @@ -555,7 +555,7 @@ namespace locale { adf.reset(new icu::SimpleDateFormat(fmt,locale,err)); } if(U_FAILURE(err)) - return std::move(fmt); + return fmt; df = adf.get(); } @@ -570,7 +570,7 @@ namespace locale { break; } - return std::move(fmt); + return fmt; } @@ -590,7 +590,7 @@ namespace locale { #ifdef BOOSTER_HAS_CHAR16_T template<> - std::auto_ptr > formatter::create(std::ios_base &ios,icu::Locale const &l,std::string const &e) + std::unique_ptr > formatter::create(std::ios_base &ios,icu::Locale const &l,std::string const &e) { return generate_formatter(ios,l,e); } @@ -599,7 +599,7 @@ namespace locale { #ifdef BOOSTER_HAS_CHAR32_T template<> - std::auto_ptr > formatter::create(std::ios_base &ios,icu::Locale const &l,std::string const &e) + std::unique_ptr > formatter::create(std::ios_base &ios,icu::Locale const &l,std::string const &e) { return generate_formatter(ios,l,e); } diff --git a/booster/lib/locale/src/icu/formatter.h b/booster/lib/locale/src/icu/formatter.h index d99dd4ca..cb0d5634 100644 --- a/booster/lib/locale/src/icu/formatter.h +++ b/booster/lib/locale/src/icu/formatter.h @@ -111,7 +111,7 @@ namespace impl_icu { /// Specialization for real implementation /// template<> - std::auto_ptr > formatter::create(std::ios_base &ios,icu::Locale const &l,std::string const &e); + std::unique_ptr > formatter::create(std::ios_base &ios,icu::Locale const &l,std::string const &e); #endif #ifdef BOOSTER_HAS_CHAR32_T @@ -119,7 +119,7 @@ namespace impl_icu { /// Specialization for real implementation /// template<> - std::auto_ptr > formatter::create(std::ios_base &ios,icu::Locale const &l,std::string const &e); + std::unique_ptr > formatter::create(std::ios_base &ios,icu::Locale const &l,std::string const &e); #endif } // namespace impl_icu diff --git a/booster/lib/locale/src/icu/time_zone.cpp b/booster/lib/locale/src/icu/time_zone.cpp index 8859eaf9..6ab9b7c8 100644 --- a/booster/lib/locale/src/icu/time_zone.cpp +++ b/booster/lib/locale/src/icu/time_zone.cpp @@ -213,7 +213,7 @@ namespace booster { if(!time_zone.empty()) { return icu::TimeZone::createTimeZone(time_zone.c_str()); } - std::auto_ptr tz(icu::TimeZone::createDefault()); + std::unique_ptr tz(icu::TimeZone::createDefault()); icu::UnicodeString id; tz->getID(id); // Check if there is a bug? diff --git a/booster/lib/locale/src/posix/codecvt.cpp b/booster/lib/locale/src/posix/codecvt.cpp index 06c698b2..98f8233b 100644 --- a/booster/lib/locale/src/posix/codecvt.cpp +++ b/booster/lib/locale/src/posix/codecvt.cpp @@ -225,10 +225,9 @@ namespace impl_posix { } #else // no iconv - std::auto_ptr create_iconv_converter(std::string const &/*encoding*/) + std::unique_ptr create_iconv_converter(std::string const &/*encoding*/) { - std::auto_ptr cvt; - return cvt; + return std::unique_ptr(); } #endif diff --git a/booster/lib/locale/src/shared/localization_backend.cpp b/booster/lib/locale/src/shared/localization_backend.cpp index 3ee6f408..2147195f 100644 --- a/booster/lib/locale/src/shared/localization_backend.cpp +++ b/booster/lib/locale/src/shared/localization_backend.cpp @@ -231,7 +231,7 @@ namespace booster { #ifndef BOOSTER_LOCALE_NO_WINAPI_BACKEND backend.reset(impl_win::create_localization_backend()); - mgr.add_backend("winapi",backend); + mgr.add_backend("winapi",std::move(backend)); #endif #ifndef BOOSTER_LOCALE_NO_STD_BACKEND diff --git a/booster/lib/locale/src/util/codecvt_converter.cpp b/booster/lib/locale/src/util/codecvt_converter.cpp index a6422dd5..03534579 100644 --- a/booster/lib/locale/src/util/codecvt_converter.cpp +++ b/booster/lib/locale/src/util/codecvt_converter.cpp @@ -266,13 +266,12 @@ namespace util { std::unique_ptr res; if(check_is_simple_encoding(encoding)) res.reset(new simple_converter(encoding)); - return std::move(res); + return res; } std::unique_ptr create_utf8_converter() { - std::unique_ptr res(new utf8_converter()); - return std::move(res); + return std::unique_ptr(new utf8_converter()); } template @@ -299,7 +298,7 @@ namespace util { std::unique_ptr r; if(!thread_safe_) r.reset(cvt_->clone()); - return std::move(r); + return r; } utf::code_point to_unicode(std::unique_ptr &ptr,char const *&begin,char const *end) const diff --git a/contrib/server_side/sessions/storage_test.cpp b/contrib/server_side/sessions/storage_test.cpp index fe9309e2..c226f684 100644 --- a/contrib/server_side/sessions/storage_test.cpp +++ b/contrib/server_side/sessions/storage_test.cpp @@ -223,7 +223,7 @@ int main(int argc,char **argv) booster::shared_object obj(so); { booster::shared_ptr storage; - std::auto_ptr storage_factory; + std::unique_ptr storage_factory; cppcms::sessions::cppcms_session_storage_generator_type gen; obj.symbol(gen,"sessions_generator"); try { diff --git a/cppcms/applications_pool.h b/cppcms/applications_pool.h index 5efadf7e..00620c85 100644 --- a/cppcms/applications_pool.h +++ b/cppcms/applications_pool.h @@ -269,8 +269,7 @@ namespace cppcms { { std::unique_ptr operator()(service &s) const { - std::unique_ptr app(new T(s)); - return std::move(app); + return std::unique_ptr(new T(s)); } }; template @@ -280,8 +279,7 @@ namespace cppcms { P1 p1_; std::unique_ptr operator()(service &s) const { - std::unique_ptr app(new T(s,p1_)); - return std::move(app); + return std::unique_ptr(new T(s,p1_)); } }; template @@ -292,8 +290,7 @@ namespace cppcms { P2 p2_; std::unique_ptr operator()(service &s) const { - std::unique_ptr app(new T(s,p1_,p2_)); - return std::move(app); + return std::unique_ptr(new T(s,p1_,p2_)); } }; } // details @@ -309,8 +306,7 @@ namespace cppcms { template std::unique_ptr applications_factory() { - std::unique_ptr f(new details::simple_factory0); - return std::move(f); + return std::unique_ptr(new details::simple_factory0); } /// @@ -322,8 +318,7 @@ namespace cppcms { template std::unique_ptr applications_factory(P1 p1) { - std::unique_ptr f(new details::simple_factory1(p1)); - return std::move(f); + return std::unique_ptr(new details::simple_factory1(p1)); } /// @@ -335,8 +330,7 @@ namespace cppcms { template std::unique_ptr applications_factory(P1 p1,P2 p2) { - std::unique_ptr f(new details::simple_factory2(p1,p2)); - return std::move(f); + return std::unique_ptr(new details::simple_factory2(p1,p2)); } /// \cond INTERNAL diff --git a/cppcms/views_pool.h b/cppcms/views_pool.h index 8ef8b474..17979878 100644 --- a/cppcms/views_pool.h +++ b/cppcms/views_pool.h @@ -96,14 +96,13 @@ namespace cppcms { catch(std::bad_cast const &) { throw cppcms_error("cppcms::views::generator: an attempt to use content of invalid type"); } - return std::move(p); + return p; } template static std::unique_ptr unsafe_view_builder(std::ostream &stream,base_content *c) { - std::unique_ptr p(new View(stream,static_cast(*c))); - return std::move(p); + return std::unique_ptr(new View(stream,static_cast(*c))); } diff --git a/src/aes.cpp b/src/aes.cpp index 7b7dad6e..5ce09a4b 100644 --- a/src/aes.cpp +++ b/src/aes.cpp @@ -387,7 +387,7 @@ std::unique_ptr cbc::create(std::string const &name) else if(name=="aes256" || name=="aes-256" || name=="AES256" || name=="AES-256") res = cbc::create(aes256); - return std::move(res); + return res; } std::unique_ptr cbc::create(cbc::cbc_type type) @@ -408,7 +408,7 @@ std::unique_ptr cbc::create(cbc::cbc_type type) default: ; } - return std::move(res); + return res; } diff --git a/src/aes_encryptor.cpp b/src/aes_encryptor.cpp index fc21c7c3..fffb102e 100644 --- a/src/aes_encryptor.cpp +++ b/src/aes_encryptor.cpp @@ -80,9 +80,7 @@ aes_factory::aes_factory(std::string const &algo,crypto::key const &k) : std::unique_ptr aes_factory::get() { - std::unique_ptr ptr; - ptr.reset(new aes_cipher(cbc_,hmac_,cbc_key_,hmac_key_)); - return std::move(ptr); + return std::unique_ptr(new aes_cipher(cbc_,hmac_,cbc_key_,hmac_key_)); } diff --git a/src/crypto.cpp b/src/crypto.cpp index 88af3edc..71c2fb52 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -231,14 +231,12 @@ namespace crypto { std::unique_ptr message_digest::md5() { - std::unique_ptr d(new md5_digets()); - return std::move(d); + return std::unique_ptr(new md5_digets()); } std::unique_ptr message_digest::sha1() { - std::unique_ptr d(new sha1_digets()); - return std::move(d); + return std::unique_ptr(new sha1_digets()); } std::unique_ptr message_digest::create_by_name(std::string const &namein) @@ -274,7 +272,7 @@ namespace crypto { d.reset(new ssl_sha512()); #endif - return std::move(d); + return d; } key::key() : data_(0), size_(0) diff --git a/src/fastcgi_api.cpp b/src/fastcgi_api.cpp index 6d961f5a..1beb07c5 100644 --- a/src/fastcgi_api.cpp +++ b/src/fastcgi_api.cpp @@ -853,21 +853,18 @@ namespace cgi { std::unique_ptr fastcgi_api_tcp_socket_factory(cppcms::service &srv,std::string ip,int port,int backlog) { - std::unique_ptr a(new socket_acceptor(srv,ip,port,backlog)); - return std::move(a); + return std::unique_ptr(new socket_acceptor(srv,ip,port,backlog)); } #if !defined(CPPCMS_WIN32) std::unique_ptr fastcgi_api_unix_socket_factory(cppcms::service &srv,std::string socket,int backlog) { - std::unique_ptr a(new socket_acceptor(srv,socket,backlog)); - return std::move(a); + return std::unique_ptr(new socket_acceptor(srv,socket,backlog)); } std::unique_ptr fastcgi_api_unix_socket_factory(cppcms::service &srv,int backlog) { - std::unique_ptr a(new socket_acceptor(srv,backlog)); - return std::move(a); + return std::unique_ptr(new socket_acceptor(srv,backlog)); } #endif diff --git a/src/hmac_encryptor.cpp b/src/hmac_encryptor.cpp index a9ba8754..046ffc15 100644 --- a/src/hmac_encryptor.cpp +++ b/src/hmac_encryptor.cpp @@ -28,9 +28,7 @@ hmac_factory::hmac_factory(std::string const &algo,crypto::key const &k) : std::unique_ptr hmac_factory::get() { - std::unique_ptr ptr; - ptr.reset(new hmac_cipher(algo_,key_)); - return std::move(ptr); + return std::unique_ptr(new hmac_cipher(algo_,key_)); } diff --git a/src/http_api.cpp b/src/http_api.cpp index 359999c8..2b038a41 100644 --- a/src/http_api.cpp +++ b/src/http_api.cpp @@ -753,8 +753,7 @@ namespace cgi { typedef socket_acceptor acceptor_type; std::unique_ptr acc(new acceptor_type(srv,ip,port,backlog)); acc->factory(http_creator(srv.get_io_service(),srv.settings(),ip,port)); - std::unique_ptr a(std::move(acc)); - return std::move(a); + return acc; } diff --git a/src/scgi_api.cpp b/src/scgi_api.cpp index a97efe9e..2c9292ab 100644 --- a/src/scgi_api.cpp +++ b/src/scgi_api.cpp @@ -171,19 +171,16 @@ namespace cgi { std::unique_ptr scgi_api_tcp_socket_factory(cppcms::service &srv,std::string ip,int port,int backlog) { - std::unique_ptr a(new socket_acceptor(srv,ip,port,backlog)); - return std::move(a); + return std::unique_ptr(new socket_acceptor(srv,ip,port,backlog)); } #if !defined(CPPCMS_WIN32) std::unique_ptr scgi_api_unix_socket_factory(cppcms::service &srv,std::string socket,int backlog) { - std::unique_ptr a(new socket_acceptor(srv,socket,backlog)); - return std::move(a); + return std::unique_ptr(new socket_acceptor(srv,socket,backlog)); } std::unique_ptr scgi_api_unix_socket_factory(cppcms::service &srv,int backlog) { - std::unique_ptr a(new socket_acceptor(srv,backlog)); - return std::move(a); + return std::unique_ptr(new socket_acceptor(srv,backlog)); } #endif diff --git a/src/service.cpp b/src/service.cpp index c675c24d..9e9898ee 100644 --- a/src/service.cpp +++ b/src/service.cpp @@ -841,7 +841,7 @@ std::unique_ptr service::setup_acceptor(json::value a->sndbuf(sndbuf); a->rcvbuf(rcvbuf); - return std::move(a); + return a; } void service::start_acceptor(bool after_fork) diff --git a/src/session_win32_file_storage.cpp b/src/session_win32_file_storage.cpp index ce3fba33..45dbb6ab 100644 --- a/src/session_win32_file_storage.cpp +++ b/src/session_win32_file_storage.cpp @@ -212,7 +212,7 @@ bool session_file_storage::read_all(HANDLE h,void *vbuf,int n) void session_file_storage::gc() { - std::auto_ptr<_WIN32_FIND_DATAW> entry(new _WIN32_FIND_DATAW); + std::unique_ptr<_WIN32_FIND_DATAW> entry(new _WIN32_FIND_DATAW); HANDLE d=INVALID_HANDLE_VALUE; std::string search_path = path_ + "/*"; try{ diff --git a/src/views_pool.cpp b/src/views_pool.cpp index d04c1028..3ba73573 100644 --- a/src/views_pool.cpp +++ b/src/views_pool.cpp @@ -62,10 +62,9 @@ std::unique_ptr generator::create( std::string const &view_name, { std::unique_ptr result; views_type::const_iterator p = views_.find(view_name); - if(p==views_.end()) - return std::move(result); - result = p->second(output,content); - return std::move(result); + if(p!=views_.end()) + result = p->second(output,content); + return result; } std::vector generator::enumerate() const