"tutorials/git@developer.sourcefind.cn:OpenDAS/dgl.git" did not exist on "7ab10348ed226904e1d032454605465991723944"
Commit 74f9f2fb authored by elelel's avatar elelel Committed by Davis E. King
Browse files

Replace shared_ptr/weak_ptr with STL's versions (#588)

* Replace shared_ptr/weak_ptr with stdlib counterparts

* Fix ptr usage through tests compilation

* Bring back dlib smart ptrs as legacy

* Include scoped_ptr directly

* Add explanation about smart_ptr deprecation
parent fe3e86a1
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#define DLIB_AnY_H_ #define DLIB_AnY_H_
#include "any_abstract.h" #include "any_abstract.h"
#include "../smart_pointers.h" #include "../smart_pointers/scoped_ptr.h"
#include <typeinfo> #include <typeinfo>
namespace dlib namespace dlib
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#define DLIB_AnY_DECISION_FUNCTION_Hh_ #define DLIB_AnY_DECISION_FUNCTION_Hh_
#include "any.h" #include "any.h"
#include "../smart_pointers.h"
#include "any_decision_function_abstract.h" #include "any_decision_function_abstract.h"
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#define DLIB_AnY_FUNCTION_Hh_ #define DLIB_AnY_FUNCTION_Hh_
#include "any.h" #include "any.h"
#include "../smart_pointers.h"
#include "any_function_abstract.h" #include "any_function_abstract.h"
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#define DLIB_AnY_TRAINER_H_ #define DLIB_AnY_TRAINER_H_
#include "any.h" #include "any.h"
#include "../smart_pointers.h"
#include "any_decision_function.h" #include "any_decision_function.h"
......
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
#include "bayes_utils_abstract.h" #include "bayes_utils_abstract.h"
#include <algorithm>
#include <ctime>
#include <vector>
#include "../string.h" #include "../string.h"
#include "../map.h" #include "../map.h"
#include "../matrix.h" #include "../matrix.h"
...@@ -13,11 +17,8 @@ ...@@ -13,11 +17,8 @@
#include "../set.h" #include "../set.h"
#include "../algs.h" #include "../algs.h"
#include "../noncopyable.h" #include "../noncopyable.h"
#include "../smart_pointers.h" #include "../smart_pointers/scoped_ptr.h"
#include "../graph.h" #include "../graph.h"
#include <vector>
#include <algorithm>
#include <ctime>
namespace dlib namespace dlib
{ {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <string> #include <string>
#include "../pipe.h" #include "../pipe.h"
#include "../threads.h" #include "../threads.h"
#include "../smart_pointers.h" #include "../smart_pointers/scoped_ptr.h"
#include "../serialize.h" #include "../serialize.h"
#include "../sockets.h" #include "../sockets.h"
#include "../sockstreambuf.h" #include "../sockstreambuf.h"
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#define DLIB_BSP_CPph_ #define DLIB_BSP_CPph_
#include "bsp.h" #include "bsp.h"
#include <memory>
#include <stack> #include <stack>
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -330,7 +331,7 @@ namespace dlib ...@@ -330,7 +331,7 @@ namespace dlib
bool bsp_context:: bool bsp_context::
receive_data ( receive_data (
shared_ptr<std::vector<char> >& item, std::shared_ptr<std::vector<char> >& item,
unsigned long& sending_node_id unsigned long& sending_node_id
) )
{ {
......
...@@ -6,13 +6,14 @@ ...@@ -6,13 +6,14 @@
#include "bsp_abstract.h" #include "bsp_abstract.h"
#include "../sockets.h" #include "../sockets.h"
#include "../array.h" #include "../array.h"
#include "../smart_pointers.h" #include "../smart_pointers/scoped_ptr.h"
#include "../sockstreambuf.h" #include "../sockstreambuf.h"
#include "../string.h" #include "../string.h"
#include "../serialize.h" #include "../serialize.h"
#include "../map.h" #include "../map.h"
#include "../ref.h" #include "../ref.h"
#include "../vectorstream.h" #include "../vectorstream.h"
#include <memory>
#include <queue> #include <queue>
#include <vector> #include <vector>
...@@ -207,7 +208,7 @@ namespace dlib ...@@ -207,7 +208,7 @@ namespace dlib
struct msg_data struct msg_data
{ {
shared_ptr<std::vector<char> > data; std::shared_ptr<std::vector<char> > data;
unsigned long sender_id; unsigned long sender_id;
char msg_type; char msg_type;
dlib::uint64 epoch; dlib::uint64 epoch;
...@@ -420,7 +421,7 @@ namespace dlib ...@@ -420,7 +421,7 @@ namespace dlib
) )
{ {
unsigned long id; unsigned long id;
shared_ptr<std::vector<char> > temp; std::shared_ptr<std::vector<char> > temp;
if (receive_data(temp,id)) if (receive_data(temp,id))
throw dlib::socket_error("Call to bsp_context::receive() got an unexpected message."); throw dlib::socket_error("Call to bsp_context::receive() got an unexpected message.");
} }
...@@ -459,7 +460,7 @@ namespace dlib ...@@ -459,7 +460,7 @@ namespace dlib
unsigned long& sending_node_id unsigned long& sending_node_id
) )
{ {
shared_ptr<std::vector<char> > temp; std::shared_ptr<std::vector<char> > temp;
if (receive_data(temp, sending_node_id)) if (receive_data(temp, sending_node_id))
{ {
vectorstream sin(*temp); vectorstream sin(*temp);
...@@ -496,7 +497,7 @@ namespace dlib ...@@ -496,7 +497,7 @@ namespace dlib
!*/ !*/
bool receive_data ( bool receive_data (
shared_ptr<std::vector<char> >& item, std::shared_ptr<std::vector<char> >& item,
unsigned long& sending_node_id unsigned long& sending_node_id
); );
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <map> #include <map>
#include "../smart_pointers.h" #include <memory>
namespace dlib namespace dlib
{ {
...@@ -105,7 +105,7 @@ namespace dlib ...@@ -105,7 +105,7 @@ namespace dlib
// Make a separate ostringstream for each option group. We are going to write // Make a separate ostringstream for each option group. We are going to write
// the output for each group to a separate ostringstream so that we can keep // the output for each group to a separate ostringstream so that we can keep
// them grouped together in the final output. // them grouped together in the final output.
std::map<string,shared_ptr<ostringstream> > groups; std::map<string,std::shared_ptr<ostringstream> > groups;
this->reset(); this->reset();
while(this->move_next()) while(this->move_next())
{ {
...@@ -173,7 +173,7 @@ namespace dlib ...@@ -173,7 +173,7 @@ namespace dlib
out << _dT(ct,"Options:"); out << _dT(ct,"Options:");
// Now print everything out // Now print everything out
typename std::map<string,shared_ptr<ostringstream> >::iterator i; typename std::map<string,std::shared_ptr<ostringstream> >::iterator i;
for (i = groups.begin(); i != groups.end(); ++i) for (i = groups.begin(); i != groups.end(); ++i)
{ {
// print the group name if we have one // print the group name if we have one
......
...@@ -3,12 +3,13 @@ ...@@ -3,12 +3,13 @@
#ifndef DLIB_DIRECTED_GRAPH_KERNEl_1_ #ifndef DLIB_DIRECTED_GRAPH_KERNEl_1_
#define DLIB_DIRECTED_GRAPH_KERNEl_1_ #define DLIB_DIRECTED_GRAPH_KERNEl_1_
#include <memory>
#include <vector>
#include "../serialize.h" #include "../serialize.h"
#include "../noncopyable.h" #include "../noncopyable.h"
#include "../std_allocator.h" #include "../std_allocator.h"
#include "../smart_pointers.h"
#include "../algs.h" #include "../algs.h"
#include <vector>
#include "directed_graph_kernel_abstract.h" #include "directed_graph_kernel_abstract.h"
#include "../is_kind.h" #include "../is_kind.h"
...@@ -357,18 +358,18 @@ namespace dlib ...@@ -357,18 +358,18 @@ namespace dlib
private: private:
friend class directed_graph_kernel_1; friend class directed_graph_kernel_1;
typedef std_allocator<node_type*,mem_manager> alloc_type; typedef std_allocator<node_type*,mem_manager> alloc_type;
typedef std_allocator<shared_ptr<E>,mem_manager> alloc_edge_type; typedef std_allocator<std::shared_ptr<E>,mem_manager> alloc_edge_type;
std::vector<node_type*,alloc_type> parents; std::vector<node_type*,alloc_type> parents;
std::vector<node_type*,alloc_type> children; std::vector<node_type*,alloc_type> children;
std::vector<shared_ptr<E>,alloc_edge_type> edge_parents; std::vector<std::shared_ptr<E>,alloc_edge_type> edge_parents;
std::vector<shared_ptr<E>,alloc_edge_type> edge_children; std::vector<std::shared_ptr<E>,alloc_edge_type> edge_children;
unsigned long idx; unsigned long idx;
}; };
private: private:
typedef std_allocator<shared_ptr<node_type>,mem_manager> alloc_type; typedef std_allocator<std::shared_ptr<node_type>,mem_manager> alloc_type;
typedef std::vector<shared_ptr<node_type>, alloc_type> vector_type; typedef std::vector<std::shared_ptr<node_type>, alloc_type> vector_type;
vector_type nodes; vector_type nodes;
}; };
...@@ -574,7 +575,7 @@ namespace dlib ...@@ -574,7 +575,7 @@ namespace dlib
p.children.push_back(&c); p.children.push_back(&c);
c.parents.push_back(&p); c.parents.push_back(&p);
p.edge_children.push_back(shared_ptr<E>(new E)); p.edge_children.push_back(std::shared_ptr<E>(new E));
c.edge_parents.push_back(p.edge_children.back()); c.edge_parents.push_back(p.edge_children.back());
} }
catch (...) catch (...)
...@@ -632,7 +633,7 @@ namespace dlib ...@@ -632,7 +633,7 @@ namespace dlib
{ {
try try
{ {
shared_ptr<node_type> n(new node_type); std::shared_ptr<node_type> n(new node_type);
n->idx = nodes.size(); n->idx = nodes.size();
nodes.push_back(n); nodes.push_back(n);
return n->idx; return n->idx;
......
...@@ -3,12 +3,13 @@ ...@@ -3,12 +3,13 @@
#ifndef DLIB_GRAPH_KERNEl_1_ #ifndef DLIB_GRAPH_KERNEl_1_
#define DLIB_GRAPH_KERNEl_1_ #define DLIB_GRAPH_KERNEl_1_
#include <memory>
#include <vector>
#include "../serialize.h" #include "../serialize.h"
#include "../noncopyable.h" #include "../noncopyable.h"
#include "../std_allocator.h" #include "../std_allocator.h"
#include "../smart_pointers.h"
#include "../algs.h" #include "../algs.h"
#include <vector>
#include "graph_kernel_abstract.h" #include "graph_kernel_abstract.h"
#include "../is_kind.h" #include "../is_kind.h"
...@@ -291,16 +292,16 @@ namespace dlib ...@@ -291,16 +292,16 @@ namespace dlib
private: private:
friend class graph_kernel_1; friend class graph_kernel_1;
typedef std_allocator<node_type*,mem_manager> alloc_type; typedef std_allocator<node_type*,mem_manager> alloc_type;
typedef std_allocator<shared_ptr<E>,mem_manager> alloc_edge_type; typedef std_allocator<std::shared_ptr<E>,mem_manager> alloc_edge_type;
std::vector<node_type*,alloc_type> neighbors; std::vector<node_type*,alloc_type> neighbors;
std::vector<shared_ptr<E>,alloc_edge_type> edges; std::vector<std::shared_ptr<E>,alloc_edge_type> edges;
unsigned long idx; unsigned long idx;
}; };
private: private:
typedef std_allocator<shared_ptr<node_type>,mem_manager> alloc_type; typedef std_allocator<std::shared_ptr<node_type>,mem_manager> alloc_type;
typedef std::vector<shared_ptr<node_type>, alloc_type> vector_type; typedef std::vector<std::shared_ptr<node_type>, alloc_type> vector_type;
vector_type nodes; vector_type nodes;
}; };
...@@ -506,7 +507,7 @@ namespace dlib ...@@ -506,7 +507,7 @@ namespace dlib
n1.neighbors.push_back(&n2); n1.neighbors.push_back(&n2);
shared_ptr<E> e(new E); std::shared_ptr<E> e(new E);
n1.edges.push_back(e); n1.edges.push_back(e);
// don't add this twice if this is an edge from node_index1 back to itself // don't add this twice if this is an edge from node_index1 back to itself
...@@ -571,7 +572,7 @@ namespace dlib ...@@ -571,7 +572,7 @@ namespace dlib
{ {
try try
{ {
shared_ptr<node_type> n(new node_type); std::shared_ptr<node_type> n(new node_type);
n->idx = nodes.size(); n->idx = nodes.size();
nodes.push_back(n); nodes.push_back(n);
return n->idx; return n->idx;
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "../image_transforms/assign_image.h" #include "../image_transforms/assign_image.h"
#include "../array.h" #include "../array.h"
#include "style.h" #include "style.h"
#include "../smart_pointers.h" #include "../smart_pointers/scoped_ptr.h"
#include "../unicode.h" #include "../unicode.h"
#include <cctype> #include <cctype>
#include "../any.h" #include "../any.h"
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "../sequence.h" #include "../sequence.h"
#include "../dir_nav.h" #include "../dir_nav.h"
#include "../queue.h" #include "../queue.h"
#include "../smart_pointers.h" #include "../smart_pointers/scoped_ptr.h"
#include "style.h" #include "style.h"
#include "../string.h" #include "../string.h"
#include "../misc_api.h" #include "../misc_api.h"
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
#ifndef DLIB_JPEG_IMPORT #ifndef DLIB_JPEG_IMPORT
#define DLIB_JPEG_IMPORT #define DLIB_JPEG_IMPORT
#include <vector>
#include "jpeg_loader_abstract.h" #include "jpeg_loader_abstract.h"
#include "../smart_pointers.h"
#include "image_loader.h" #include "image_loader.h"
#include "../pixel.h" #include "../pixel.h"
#include "../dir_nav.h" #include "../dir_nav.h"
#include <vector>
namespace dlib namespace dlib
{ {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#define DLIB_PNG_IMPORT #define DLIB_PNG_IMPORT
#include "png_loader_abstract.h" #include "png_loader_abstract.h"
#include "../smart_pointers.h" #include "../smart_pointers/scoped_ptr.h"
#include "image_loader.h" #include "image_loader.h"
#include "../pixel.h" #include "../pixel.h"
#include "../dir_nav.h" #include "../dir_nav.h"
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "../assert.h" #include "../assert.h"
#include "../uintn.h" #include "../uintn.h"
#include "../map.h" #include "../map.h"
#include "../smart_pointers.h" #include "../smart_pointers/scoped_ptr.h"
#include "../member_function_pointer.h" #include "../member_function_pointer.h"
#include <streambuf> #include <streambuf>
#include <vector> #include <vector>
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include "../matrix.h" #include "../matrix.h"
#include "../smart_pointers.h" #include "../smart_pointers/scoped_ptr.h"
#include "optimization_bobyqa_abstract.h" #include "optimization_bobyqa_abstract.h"
#include "optimization.h" #include "optimization.h"
......
...@@ -151,6 +151,7 @@ ...@@ -151,6 +151,7 @@
#include <deque> #include <deque>
#include <complex> #include <complex>
#include <map> #include <map>
#include <memory>
#include <set> #include <set>
#include <limits> #include <limits>
#include "uintn.h" #include "uintn.h"
...@@ -160,7 +161,6 @@ ...@@ -160,7 +161,6 @@
#include "unicode.h" #include "unicode.h"
#include "byte_orderer.h" #include "byte_orderer.h"
#include "float_details.h" #include "float_details.h"
#include "smart_pointers/shared_ptr.h"
namespace dlib namespace dlib
{ {
...@@ -1490,7 +1490,7 @@ namespace dlib ...@@ -1490,7 +1490,7 @@ namespace dlib
} }
private: private:
shared_ptr<std::ofstream> fout; std::shared_ptr<std::ofstream> fout;
}; };
class proxy_deserialize class proxy_deserialize
...@@ -1513,7 +1513,7 @@ namespace dlib ...@@ -1513,7 +1513,7 @@ namespace dlib
} }
private: private:
shared_ptr<std::ifstream> fin; std::shared_ptr<std::ifstream> fin;
}; };
inline proxy_serialize serialize(const std::string& filename) inline proxy_serialize serialize(const std::string& filename)
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "../algs.h" #include "../algs.h"
#include "../set.h" #include "../set.h"
#include "../logger.h" #include "../logger.h"
#include "../smart_pointers.h" #include "../smart_pointers/scoped_ptr.h"
namespace dlib namespace dlib
......
...@@ -3,6 +3,16 @@ ...@@ -3,6 +3,16 @@
#ifndef DLIB_SMART_POINTERs_H_ #ifndef DLIB_SMART_POINTERs_H_
#define DLIB_SMART_POINTERs_H_ #define DLIB_SMART_POINTERs_H_
// This is legacy smart pointer code that will likely to stop working under default
// compiler flags when C++17 becomes the default standard in the compilers.
// Please consider migrating your code to contemporary smart pointers from C++
// standard library. The warning below will help to detect if the deprecated code
// was included from library's clients.
#if (defined(__GNUC__) && ((__GNUC__ >= 4 && __GNUC_MINOR__ >= 8) || (__GNUC__ > 4))) || \
(defined(__clang__) && ((__clang_major__ >= 3 && __clang_minor__ >= 4)))
#pragma GCC warning "smart_pointers.h is included which will fail to compile under C++17"
#endif
#include "smart_pointers/scoped_ptr.h" #include "smart_pointers/scoped_ptr.h"
#include "smart_pointers/shared_ptr.h" #include "smart_pointers/shared_ptr.h"
#include "smart_pointers/weak_ptr.h" #include "smart_pointers/weak_ptr.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment