Commit 6ca47308 authored by Brad King's avatar Brad King

ENH: Adding SGI hash_map and hash_set implementation ported from STL to KWSys....

ENH: Adding SGI hash_map and hash_set implementation ported from STL to KWSys.  This also adds try-compiles for KWSYS_STL_HAS_ALLOCATOR_REBIND, KWSYS_CXX_HAS_FULL_SPECIALIZATION, KWSYS_CXX_HAS_MEMBER_TEMPLATES, and KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS.
parent 5d07a5fe
......@@ -179,6 +179,8 @@ SET(KWSYS_PLATFORM_CXX_TEST_DEFINES
-DKWSYS_STL_HAVE_STD=${KWSYS_STL_HAVE_STD})
KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_STRING_HAVE_NEQ_CHAR
"Checking whether stl string has operator!= for char*" DIRECT)
KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ALLOCATOR_REBIND
"Checking for rebind member of stl allocator" DIRECT)
IF(KWSYS_IOS_USE_ANSI)
# ANSI streams always have string operators.
SET(KWSYS_STL_STRING_HAVE_OSTREAM 1)
......@@ -192,6 +194,13 @@ ELSE(KWSYS_IOS_USE_ANSI)
ENDIF(KWSYS_IOS_USE_ANSI)
SET(KWSYS_PLATFORM_CXX_TEST_DEFINES)
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS
"Checking whether \"<>\" is needed for template friends" INVERT)
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_MEMBER_TEMPLATES
"Checking for member template support" DIRECT)
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_FULL_SPECIALIZATION
"Checking for standard template specialization syntax" DIRECT)
IF(UNIX)
KWSYS_PLATFORM_CXX_TEST(KWSYS_STAT_HAS_ST_MTIM
"Checking whether struct stat has st_mtim member" DIRECT)
......@@ -229,7 +238,7 @@ INCLUDE_DIRECTORIES(${KWSYS_HEADER_ROOT})
# give standard names by which they may be included.
SET(KWSYS_STL_HEADER_EXTRA_string 1)
FOREACH(header algorithm deque iterator list map numeric queue set stack string
utility vector)
utility vector memory functional)
# Configure the header wrapper.
SET(KWSYS_STL_HEADER "${header}")
IF(KWSYS_STL_HEADER_EXTRA_${header})
......@@ -277,7 +286,7 @@ ENDFOREACH(header)
# selected components. Initialize with required components.
SET(KWSYS_CLASSES)
SET(KWSYS_H_FILES Configure SharedForward)
SET(KWSYS_HXX_FILES Configure)
SET(KWSYS_HXX_FILES Configure hashtable hash_fun hash_map hash_set)
# Enforce component dependencies.
IF(KWSYS_USE_SystemTools)
......@@ -456,10 +465,12 @@ ENDIF(KWSYS_USE_Process)
# Setup testing if not being built as part of another project.
IF(KWSYS_STANDALONE)
ADD_EXECUTABLE(testIOS testIOS.cxx)
ADD_EXECUTABLE(testhash testhash.cxx)
ADD_EXECUTABLE(testProcess testProcess.c)
ADD_EXECUTABLE(test1 test1.cxx)
ADD_EXECUTABLE(testCommandLineArguments testCommandLineArguments.cxx)
TARGET_LINK_LIBRARIES(testIOS ${KWSYS_NAMESPACE})
TARGET_LINK_LIBRARIES(testhash ${KWSYS_NAMESPACE})
TARGET_LINK_LIBRARIES(testProcess ${KWSYS_NAMESPACE}_c)
TARGET_LINK_LIBRARIES(test1 ${KWSYS_NAMESPACE})
TARGET_LINK_LIBRARIES(testCommandLineArguments ${KWSYS_NAMESPACE})
......
......@@ -63,6 +63,39 @@
# define @KWSYS_NAMESPACE@_ios @KWSYS_NAMESPACE@_ios
#endif
/* Whether the compiler supports null template arguments. */
#define @KWSYS_NAMESPACE@_CXX_HAS_NULL_TEMPLATE_ARGS @KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS@
/* Define the null template arguments macro. */
#if @KWSYS_NAMESPACE@_CXX_HAS_NULL_TEMPLATE_ARGS
# define @KWSYS_NAMESPACE@_CXX_NULL_TEMPLATE_ARGS <>
#else
# define @KWSYS_NAMESPACE@_CXX_NULL_TEMPLATE_ARGS
#endif
/* Whether the compiler supports member templates. */
#define @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES @KWSYS_CXX_HAS_MEMBER_TEMPLATES@
/* Whether the compiler supports standard full specialization syntax. */
#define @KWSYS_NAMESPACE@_CXX_HAS_FULL_SPECIALIZATION @KWSYS_CXX_HAS_FULL_SPECIALIZATION@
/* Define the specialization definition macro. */
#if @KWSYS_NAMESPACE@_CXX_HAS_FULL_SPECIALIZATION
# define @KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION template <>
#else
# define @KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
#endif
/* Define typename keyword macro for use in declarations. */
#if defined(_MSC_VER) && _MSC_VER < 1300
# define @KWSYS_NAMESPACE@_CXX_DECL_TYPENAME
#else
# define @KWSYS_NAMESPACE@_CXX_DECL_TYPENAME typename
#endif
/* Whether the stl allocator has rebind. */
#define @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_REBIND @KWSYS_STL_HAS_ALLOCATOR_REBIND@
/* Whether struct stat has the st_mtim member for high resolution times. */
#define @KWSYS_NAMESPACE@_STAT_HAS_ST_MTIM @KWSYS_STAT_HAS_ST_MTIM@
......@@ -84,6 +117,12 @@
# define KWSYS_STL_STRING_HAVE_OSTREAM @KWSYS_NAMESPACE@_STL_STRING_HAVE_OSTREAM
# define KWSYS_STL_STRING_HAVE_ISTREAM @KWSYS_NAMESPACE@_STL_STRING_HAVE_ISTREAM
# define KWSYS_STL_STRING_HAVE_NEQ_CHAR @KWSYS_NAMESPACE@_STL_STRING_HAVE_NEQ_CHAR
# define KWSYS_CXX_NULL_TEMPLATE_ARGS @KWSYS_NAMESPACE@_CXX_NULL_TEMPLATE_ARGS
# define KWSYS_CXX_HAS_MEMBER_TEMPLATES @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES
# define KWSYS_CXX_HAS_FULL_SPECIALIZATION @KWSYS_NAMESPACE@_CXX_HAS_FULL_SPECIALIZATION
# define KWSYS_CXX_DEFINE_SPECIALIZATION @KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
# define KWSYS_CXX_DECL_TYPENAME @KWSYS_NAMESPACE@_CXX_DECL_TYPENAME
# define KWSYS_STL_HAS_ALLOCATOR_REBIND @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_REBIND
#endif
#endif
/*=========================================================================
Program: KWSys - Kitware System Library
Module: hash_fun.hxx.in
Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
/*
* Copyright (c) 1996
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef @KWSYS_NAMESPACE@_hash_fun_hxx
#define @KWSYS_NAMESPACE@_hash_fun_hxx
#include <@KWSYS_NAMESPACE@/Configure.hxx>
namespace @KWSYS_NAMESPACE@
{
template <class _Key> struct hash { };
inline size_t _stl_hash_string(const char* __s)
{
unsigned long __h = 0;
for ( ; *__s; ++__s)
__h = 5*__h + *__s;
return size_t(__h);
}
@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
struct hash<char*> {
size_t operator()(const char* __s) const { return _stl_hash_string(__s); }
};
@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
struct hash<const char*> {
size_t operator()(const char* __s) const { return _stl_hash_string(__s); }
};
@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
struct hash<char> {
size_t operator()(char __x) const { return __x; }
};
@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
struct hash<unsigned char> {
size_t operator()(unsigned char __x) const { return __x; }
};
@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
struct hash<signed char> {
size_t operator()(unsigned char __x) const { return __x; }
};
@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
struct hash<short> {
size_t operator()(short __x) const { return __x; }
};
@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
struct hash<unsigned short> {
size_t operator()(unsigned short __x) const { return __x; }
};
@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
struct hash<int> {
size_t operator()(int __x) const { return __x; }
};
@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
struct hash<unsigned int> {
size_t operator()(unsigned int __x) const { return __x; }
};
@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
struct hash<long> {
size_t operator()(long __x) const { return __x; }
};
@KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
struct hash<unsigned long> {
size_t operator()(unsigned long __x) const { return __x; }
};
} // namespace @KWSYS_NAMESPACE@
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// Setup for tests that use result of stl namespace test.
#if defined(KWSYS_STL_HAVE_STD)
# if KWSYS_STL_HAVE_STD
# define kwsys_stl std
# else
# define kwsys_stl
# endif
#endif
#ifdef TEST_KWSYS_STL_HAVE_STD
#include <list>
void f(std::list<int>*) {}
......@@ -31,11 +40,6 @@ int main() { return 0; }
#endif
#ifdef TEST_KWSYS_STL_STRING_HAVE_OSTREAM
# if KWSYS_STL_HAVE_STD
# define kwsys_stl std
# else
# define kwsys_stl
# endif
# include <iostream.h>
# include <string>
void f(ostream& os, const kwsys_stl::string& s) { os << s; }
......@@ -43,11 +47,6 @@ int main() { return 0; }
#endif
#ifdef TEST_KWSYS_STL_STRING_HAVE_ISTREAM
# if KWSYS_STL_HAVE_STD
# define kwsys_stl std
# else
# define kwsys_stl
# endif
# include <iostream.h>
# include <string>
void f(istream& is, kwsys_stl::string& s) { is >> s; }
......@@ -55,16 +54,73 @@ int main() { return 0; }
#endif
#ifdef TEST_KWSYS_STL_STRING_HAVE_NEQ_CHAR
# if KWSYS_STL_HAVE_STD
# define kwsys_stl std
# else
# define kwsys_stl
# endif
# include <string>
bool f(const kwsys_stl::string& s) { return s != ""; }
int main() { return 0; }
#endif
#ifdef TEST_KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS
template <class T> class A;
template <class T> int f(A<T>&);
template <class T> class A
{
public:
// "friend int f<>(A<T>&)" would conform
friend int f(A<T>&);
private:
int x;
};
template <class T> int f(A<T>& a) { return a.x = 0; }
template int f(A<int>&);
int main()
{
A<int> a;
return f(a);
}
#endif
#ifdef TEST_KWSYS_CXX_HAS_MEMBER_TEMPLATES
template <class U>
class A
{
public:
U* ptr;
template <class V> U m(V* p) { return *ptr = *p; }
};
int main()
{
A<int> a;
short s = 0;
return a.m(&s);
}
#endif
#ifdef TEST_KWSYS_CXX_HAS_FULL_SPECIALIZATION
template <class T> struct A {};
template <> struct A<int*>
{
static int f() { return 0; }
};
int main() { return A<int*>::f(); }
#endif
#ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_REBIND
#include <memory>
template <class T, class Alloc>
void f(const T&, const Alloc&)
{
typedef typename Alloc::template rebind<T>::other alloc_type;
};
int main()
{
f(0, std::allocator<char>());
return 0;
}
#endif
#ifdef TEST_KWSYS_STAT_HAS_ST_MTIM
#include <sys/types.h>
#include <sys/stat.h>
......
#include <kwsys/hash_map.hxx>
#include <kwsys/hash_set.hxx>
#include <kwsys/ios/iostream>
#if defined(_MSC_VER)
# pragma warning (disable:4786)
#endif
template class kwsys::hash_map<const char*, int>;
template class kwsys::hash_set<int>;
bool test_hash_map()
{
typedef kwsys::hash_map<const char*, int> mtype;
mtype m;
const char* keys[] = {"hello", "world"};
m[keys[0]] = 1;
m.insert(mtype::value_type(keys[1], 2));
int sum = 0;
for(mtype::iterator mi = m.begin(); mi != m.end(); ++mi)
{
kwsys_ios::cout << "Found entry [" << mi->first << "," << mi->second << "]"
<< kwsys_ios::endl;
sum += mi->second;
}
return sum == 3;
}
bool test_hash_set()
{
typedef kwsys::hash_set<int> stype;
stype s;
s.insert(1);
s.insert(2);
int sum = 0;
for(stype::iterator si = s.begin(); si != s.end(); ++si)
{
kwsys_ios::cout << "Found entry [" << *si << "]" << kwsys_ios::endl;
sum += *si;
}
return sum == 3;
}
int main()
{
bool result = true;
result = test_hash_map() && result;
result = test_hash_set() && result;
return result? 0:1;
}
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