common.h 2.31 KB
Newer Older
Robert Ricci's avatar
Robert Ricci committed
1 2
/*
 * EMULAB-COPYRIGHT
Robert Ricci's avatar
Robert Ricci committed
3
 * Copyright (c) 2000-2010 University of Utah and the Flux Group.
Robert Ricci's avatar
Robert Ricci committed
4 5 6
 * All rights reserved.
 */

7 8
#ifndef __COMMON_H
#define __COMMON_H
Mac Newbold's avatar
Mac Newbold committed
9

10 11
#include "port.h"

12 13 14 15
/*
 * We have to do these includes differently depending on which version of gcc
 * we're compiling with
 */
16
#ifdef NEW_GCC
17
#include <ext/hash_map>
Robert Ricci's avatar
Robert Ricci committed
18 19 20 21 22
#ifdef NEWER_GCC
  #include <backward/hash_fun.h>
#else
  #include <ext/hash_fun.h>
#endif
23

24
using namespace __gnu_cxx;
25
#define RANDOM() random()
26 27
#else
#include <hash_map>
28
#define RANDOM() std::random()
29 30
#endif

31
#include <utility>
32 33
#include "port.h"
#include "fstring.h"
34

35 36
#include <boost/graph/adjacency_list.hpp>

37 38 39 40 41 42 43 44
/*
 * Exit vaules from assign
 */

// A solution with no violations was found
#define EXIT_SUCCESS 0

// No valid solution was found, but one may exist
45
// No violation-free solution was found after annealing.
46 47 48 49 50
#define EXIT_RETRYABLE 1

// It is not possible to map the given top file into the given ptop file,
// so there's no point in re-running assign.
#define EXIT_UNRETRYABLE 2
51

52 53 54 55
// An internal error occured, or there was a problem with the input - for
// example, the top or ptop file does not exist or cannot be parsed
#define EXIT_FATAL -1

56
#ifdef NEW_GCC
57 58 59 60 61 62 63 64 65 66
namespace __gnu_cxx
{
#endif
    template<> struct hash< std::string >
    {
        size_t operator()( const std::string& x ) const
        {
            return hash< const char* >()( x.c_str() );
        }
    };
67
#ifdef NEW_GCC
68
}
69 70 71
#endif


72 73
enum edge_data_t {edge_data};
enum vertex_data_t {vertex_data};
Mac Newbold's avatar
Mac Newbold committed
74

75 76 77 78
namespace boost {
  BOOST_INSTALL_PROPERTY(edge,data);
  BOOST_INSTALL_PROPERTY(vertex,data);
}
Mac Newbold's avatar
Mac Newbold committed
79

80 81 82
/*
 * Used to count the number of nodes in each ptype and vtype
 */
83 84
typedef hash_map<fstring,int> name_count_map;
typedef hash_map<fstring,vector<fstring> > name_list_map;
85

86 87 88
/*
 * A hash function for pointers
 */
89 90 91 92 93 94
template <class T> struct hashptr {
  size_t operator()(T const &A) const {
    return (size_t) A;
  }
};

95 96 97 98 99 100 101 102 103
/*
 * Misc. debugging stuff
 */
#ifdef ROB_DEBUG
#define RDEBUG(a) a
#else
#define RDEBUG(a)
#endif

104 105 106 107
/*
 * Needed for the transition from gcc 2.95 to 3.x - the new gcc puts some
 * non-standard (ie. SGI) STL extensions in different place
 */
108
#ifdef NEW_GCC
109 110 111 112 113
#define HASH_MAP <ext/hash_map>
#else
#define HASH_MAP
#endif

114 115 116
// For use in functions that want to return a score/violations pair
typedef pair<double,int> score_and_violations;

117
#endif