From bf4116faae559f05e2b65d7256a7c1cc3a03795e Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sun, 9 Aug 2015 10:21:46 +0200 Subject: [PATCH] clean up autoconf of unordered_xx, prepare change to shared_ptr --- src/common/autoconfig.h.in | 8 ++++++++ src/common/conf_post.h | 28 ++++++++++++++++++++++++++++ src/common/rclconfig.h | 4 ++-- src/common/textsplit.cpp | 4 ++-- src/common/unordered_defs.h | 19 ------------------- src/configure.ac | 16 ++++++++++++++++ src/rcldb/rclabstract.cpp | 5 ++--- src/rcldb/rclquery.cpp | 4 +++- src/unac/unac.c | 3 ++- src/utils/refcntr.h | 1 + src/utils/smallut.cpp | 9 +++++---- 11 files changed, 69 insertions(+), 32 deletions(-) create mode 100644 src/common/conf_post.h delete mode 100644 src/common/unordered_defs.h diff --git a/src/common/autoconfig.h.in b/src/common/autoconfig.h.in index cac3c918..e6ced0ff 100644 --- a/src/common/autoconfig.h.in +++ b/src/common/autoconfig.h.in @@ -48,6 +48,12 @@ /* Define to 1 if you have the `setrlimit' function. */ #undef HAVE_SETRLIMIT +/* Has std::shared_ptr */ +#undef HAVE_SHARED_PTR_STD + +/* Has std::tr1::shared_ptr */ +#undef HAVE_SHARED_PTR_TR1 + /* Define to 1 if you have the header file. */ #undef HAVE_SPAWN_H @@ -171,3 +177,5 @@ /* Define for large files, on AIX-style hosts. */ #undef _LARGE_FILES + +#include "conf_post.h" diff --git a/src/common/conf_post.h b/src/common/conf_post.h new file mode 100644 index 00000000..71373d50 --- /dev/null +++ b/src/common/conf_post.h @@ -0,0 +1,28 @@ +#ifdef HAVE_CXX0X_UNORDERED +# define UNORDERED_MAP_INCLUDE +# define UNORDERED_SET_INCLUDE +# define STD_UNORDERED_MAP std::unordered_map +# define STD_UNORDERED_SET std::unordered_set +#elif defined(HAVE_TR1_UNORDERED) +# define UNORDERED_MAP_INCLUDE +# define UNORDERED_SET_INCLUDE +# define STD_UNORDERED_MAP std::tr1::unordered_map +# define STD_UNORDERED_SET std::tr1::unordered_set +#else +# define UNORDERED_MAP_INCLUDE +# define UNORDERED_SET_INCLUDE +# define STD_UNORDERED_MAP std::map +# define STD_UNORDERED_SET std::set +#endif + +#ifdef HAVE_SHARED_PTR_STD +# define MEMORY_INCLUDE +# define STD_SHARED_PTR std::shared_ptr +#elif defined(HAVE_SHARED_PTR_TR1) +# define MEMORY_INCLUDE +# define STD_SHARED_PTR std::tr1::shared_ptr +#else +# define MEMORY_INCLUDE "refcntr.h" +# define STD_SHARED_PTR RefCntr +#endif + diff --git a/src/common/rclconfig.h b/src/common/rclconfig.h index 7be82b08..be26eaa1 100644 --- a/src/common/rclconfig.h +++ b/src/common/rclconfig.h @@ -16,13 +16,14 @@ */ #ifndef _RCLCONFIG_H_INCLUDED_ #define _RCLCONFIG_H_INCLUDED_ +#include "autoconfig.h" #include #include #include #include #include -#include "unordered_defs.h" +#include UNORDERED_SET_INCLUDE using std::string; using std::vector; @@ -30,7 +31,6 @@ using std::pair; using std::set; using std::map; - #include "conftree.h" #include "smallut.h" diff --git a/src/common/textsplit.cpp b/src/common/textsplit.cpp index c41c7ce6..72a1272a 100644 --- a/src/common/textsplit.cpp +++ b/src/common/textsplit.cpp @@ -24,8 +24,7 @@ #include #include #include -#include "unordered_defs.h" -using namespace std; +#include UNORDERED_SET_INCLUDE #include "textsplit.h" #include "debuglog.h" @@ -33,6 +32,7 @@ using namespace std; #include "utf8iter.h" #include "uproplist.h" +using namespace std; /** * Splitting a text into words. The code in this file works with utf-8 diff --git a/src/common/unordered_defs.h b/src/common/unordered_defs.h deleted file mode 100644 index e82ae0c6..00000000 --- a/src/common/unordered_defs.h +++ /dev/null @@ -1,19 +0,0 @@ - -#include "autoconfig.h" - -#ifdef HAVE_CXX0X_UNORDERED -# include -# include -# define STD_UNORDERED_MAP std::unordered_map -# define STD_UNORDERED_SET std::unordered_set -#elif defined(HAVE_TR1_UNORDERED) -# include -# include -# define STD_UNORDERED_MAP std::tr1::unordered_map -# define STD_UNORDERED_SET std::tr1::unordered_set -#else -# include -# include -# define STD_UNORDERED_MAP std::map -# define STD_UNORDERED_SET std::set -#endif diff --git a/src/configure.ac b/src/configure.ac index c97b92bb..4c660e8d 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -1,5 +1,6 @@ AC_INIT([Recoll], m4_esyscmd_s(cat VERSION)) AC_CONFIG_HEADERS([common/autoconfig.h]) +AH_BOTTOM([#include "conf_post.h"]) AC_PREREQ(2.53) AC_CONFIG_SRCDIR(index/recollindex.cpp) @@ -41,6 +42,21 @@ AC_CHECK_HEADER(tr1/unordered_map,[AC_DEFINE([HAVE_TR1_UNORDERED], [],["Have tr1"])],[]) AC_CHECK_HEADER(unordered_map,[AC_DEFINE([HAVE_CXX0X_UNORDERED], [],["Have C++0x"])],[]) +AC_TRY_COMPILE([ + #include + ],[ + std::shared_ptr ptr; + ], rcl_shared_ptr_std="1", rcl_shared_ptr_std="0") +AC_TRY_COMPILE([ + #include + ],[ + std::tr1::shared_ptr ptr; + ], rcl_shared_ptr_tr1="1", rcl_shared_ptr_tr1="0") +if test X$rcl_shared_ptr_std = X1; then + AC_DEFINE(HAVE_SHARED_PTR_STD, [], [Has std::shared_ptr]) +elif test X$rcl_shared_ptr_tr1 = X1; then + AC_DEFINE(HAVE_SHARED_PTR_TR1, [], [Has std::tr1::shared_ptr]) +fi AC_LANG_POP([C++]) AC_CHECK_HEADERS([sys/mount.h sys/statfs.h sys/statvfs.h sys/vfs.h], [], [], diff --git a/src/rcldb/rclabstract.cpp b/src/rcldb/rclabstract.cpp index 98b2cb3d..9d9f7f2b 100644 --- a/src/rcldb/rclabstract.cpp +++ b/src/rcldb/rclabstract.cpp @@ -19,9 +19,6 @@ #include #include -#include "unordered_defs.h" - -using namespace std; #include "debuglog.h" #include "rcldb.h" @@ -33,6 +30,8 @@ using namespace std; #include "utf8iter.h" #include "hldata.h" +using namespace std; + namespace Rcl { // This is used as a marker inside the abstract frag lists, but // normally doesn't remain in final output (which is built with a diff --git a/src/rcldb/rclquery.cpp b/src/rcldb/rclquery.cpp index fdf811c7..70cd0cb0 100644 --- a/src/rcldb/rclquery.cpp +++ b/src/rcldb/rclquery.cpp @@ -14,6 +14,7 @@ * Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "autoconfig.h" #include #include @@ -21,7 +22,6 @@ #include #include -using namespace std; #include "xapian.h" @@ -37,6 +37,8 @@ using namespace std; #include "searchdata.h" #include "unacpp.h" +using namespace std; + namespace Rcl { // This is used as a marker inside the abstract frag lists, but // normally doesn't remain in final output (which is built with a diff --git a/src/unac/unac.c b/src/unac/unac.c index 8356e6ae..2f4df79c 100644 --- a/src/unac/unac.c +++ b/src/unac/unac.c @@ -31,7 +31,8 @@ #include #include #include -#include "unordered_defs.h" +#include UNORDERED_MAP_INCLUDE + using std::string; #include "smallut.h" diff --git a/src/utils/refcntr.h b/src/utils/refcntr.h index 003fcab1..4255bd77 100644 --- a/src/utils/refcntr.h +++ b/src/utils/refcntr.h @@ -2,6 +2,7 @@ #define _REFCNTR_H_ // See Stroustrup C++ 3rd ed, p. 783 +// This is only used if std::shared_ptr is not available template class RefCntr { X *rep; int *pcount; diff --git a/src/utils/smallut.cpp b/src/utils/smallut.cpp index 6d84e999..c148e74c 100644 --- a/src/utils/smallut.cpp +++ b/src/utils/smallut.cpp @@ -16,9 +16,8 @@ */ #ifndef TEST_SMALLUT -#ifdef HAVE_CONFIG_H #include "autoconfig.h" -#endif + #include #include #include @@ -34,14 +33,16 @@ #include #include #include -#include "unordered_defs.h" -using namespace std; +#include UNORDERED_MAP_INCLUDE +#include UNORDERED_SET_INCLUDE #include "smallut.h" #include "utf8iter.h" #include "hldata.h" #include "cstr.h" +using namespace std; + void map_ss_cp_noshr(const map s, map *d) { for (map::const_iterator it= s.begin();