testHashSTL.cxx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*============================================================================
  2. KWSys - Kitware System Library
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "kwsysPrivate.h"
  11. #include KWSYS_HEADER(hash_map.hxx)
  12. #include KWSYS_HEADER(hash_set.hxx)
  13. #include KWSYS_HEADER(ios/iostream)
  14. // Work-around CMake dependency scanning limitation. This must
  15. // duplicate the above list of headers.
  16. #if 0
  17. # include "hash_map.hxx.in"
  18. # include "hash_set.hxx.in"
  19. # include "hashtable.hxx.in"
  20. # include "kwsys_ios_iostream.h.in"
  21. #endif
  22. #if defined(_MSC_VER)
  23. # pragma warning (disable:4786)
  24. #endif
  25. #if defined(__sgi) && !defined(__GNUC__)
  26. # pragma set woff 1468 /* inline function cannot be explicitly instantiated */
  27. #endif
  28. template class kwsys::hash_map<const char*, int>;
  29. template class kwsys::hash_set<int>;
  30. bool test_hash_map()
  31. {
  32. typedef kwsys::hash_map<const char*, int> mtype;
  33. mtype m;
  34. const char* keys[] = {"hello", "world"};
  35. m[keys[0]] = 1;
  36. m.insert(mtype::value_type(keys[1], 2));
  37. int sum = 0;
  38. for(mtype::iterator mi = m.begin(); mi != m.end(); ++mi)
  39. {
  40. kwsys_ios::cout << "Found entry [" << mi->first << "," << mi->second << "]"
  41. << kwsys_ios::endl;
  42. sum += mi->second;
  43. }
  44. return sum == 3;
  45. }
  46. bool test_hash_set()
  47. {
  48. typedef kwsys::hash_set<int> stype;
  49. stype s;
  50. s.insert(1);
  51. s.insert(2);
  52. int sum = 0;
  53. for(stype::iterator si = s.begin(); si != s.end(); ++si)
  54. {
  55. kwsys_ios::cout << "Found entry [" << *si << "]" << kwsys_ios::endl;
  56. sum += *si;
  57. }
  58. return sum == 3;
  59. }
  60. int testHashSTL(int, char*[])
  61. {
  62. bool result = true;
  63. result = test_hash_map() && result;
  64. result = test_hash_set() && result;
  65. return result? 0:1;
  66. }