common.h 2.86 KB
Newer Older
Robert Ricci's avatar
Robert Ricci committed
1
/*
Robert Ricci's avatar
Robert Ricci committed
2
 * Copyright (c) 2000-2010 University of Utah and the Flux Group.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * 
 * {{{EMULAB-LICENSE
 * 
 * This file is part of the Emulab network testbed software.
 * 
 * This file is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 * 
 * This file is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this file.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * }}}
Robert Ricci's avatar
Robert Ricci committed
22 23
 */

24 25
#ifndef __COMMON_H
#define __COMMON_H
Mac Newbold's avatar
Mac Newbold committed
26

27 28
#include "port.h"

29
#include <utility>
30
#include "fstring.h"
31

32 33
#include <boost/graph/adjacency_list.hpp>

34 35 36 37 38 39 40 41
/*
 * Exit vaules from assign
 */

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

// No valid solution was found, but one may exist
42
// No violation-free solution was found after annealing.
43 44 45 46 47
#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
48

49 50 51 52
// 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

53
#ifdef NEW_GCC
54 55 56
namespace __gnu_cxx
{
#endif
57 58 59 60 61 62 63 64 65
#ifdef __clang__
    template<> struct std::hash< std::string >
    {
        size_t operator()( const std::string& x ) const
        {
            return hash< const char* >()( x.c_str() );
        }
    };
#else
66 67 68 69 70 71 72
    template<> struct hash< std::string >
    {
        size_t operator()( const std::string& x ) const
        {
            return hash< const char* >()( x.c_str() );
        }
    };
73
#endif
74
#ifdef NEW_GCC
75
}
76 77 78
#endif


79 80
enum edge_data_t {edge_data};
enum vertex_data_t {vertex_data};
Mac Newbold's avatar
Mac Newbold committed
81

82 83 84 85
namespace boost {
  BOOST_INSTALL_PROPERTY(edge,data);
  BOOST_INSTALL_PROPERTY(vertex,data);
}
Mac Newbold's avatar
Mac Newbold committed
86

87 88 89
/*
 * Used to count the number of nodes in each ptype and vtype
 */
90 91
typedef hash_map<fstring,int> name_count_map;
typedef hash_map<fstring,vector<fstring> > name_list_map;
92

93 94 95
/*
 * A hash function for pointers
 */
96 97 98 99 100 101
template <class T> struct hashptr {
  size_t operator()(T const &A) const {
    return (size_t) A;
  }
};

102 103 104 105 106 107 108 109 110
/*
 * Misc. debugging stuff
 */
#ifdef ROB_DEBUG
#define RDEBUG(a) a
#else
#define RDEBUG(a)
#endif

111 112 113 114
/*
 * 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
 */
115
#ifdef NEW_GCC
116 117 118 119 120
#define HASH_MAP <ext/hash_map>
#else
#define HASH_MAP
#endif

121 122 123
// For use in functions that want to return a score/violations pair
typedef pair<double,int> score_and_violations;

124
#endif