Adaptagrams
commondefs.h
1 /*
2  * vim: ts=4 sw=4 et tw=0 wm=0
3  *
4  * libcola - A library providing force-directed network layout using the
5  * stress-majorization method subject to separation constraints.
6  *
7  * Copyright (C) 2006-2008 Monash University
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  * See the file LICENSE.LGPL distributed with the library.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18  *
19 */
20 
21 #ifndef _COMMONDEFS_H
22 #define _COMMONDEFS_H
23 
24 /* Notes to compilation using MSVC.
25 
26  Compiler options:
27  /Zc:forScope
28 */
29 #if defined(_MSC_VER)
30 // Microsoft Visual C++ (MS VC) specific code goes here
31 #include <float.h>
32 #include <malloc.h> // Contains _alloca
33 namespace std {
34 inline bool isnan(double const &x) { return _isnan(x) != 0; }
35 inline bool isinf(double const &x) { return !(_finite(x) || _isnan(x)); }
36 } // end std
37 
38 #endif
39 
40 #include "libvpsc/assertions.h"
41 #include <valarray>
42 
43 namespace cola {
44 
45 /*
46  * resolve overlaps:
47  * None: not at all
48  * Horizontal: only horizontally
49  * Both: resolve in either Horizontal or Vertical direction
50  * depending on which leads to less displacement
51  */
52 enum NonOverlapConstraintsMode { None, Horizontal, Both };
53 
54 class FixedList {
55 public:
56  FixedList(const unsigned n) : array(std::valarray<bool>(n)),allFixed(false)
57  {
58  array=false;
59  }
60  void set(const unsigned i, const bool value=true) {
61  COLA_ASSERT(i<array.size());
62  array[i]=value;
63  }
64  bool check(const unsigned i) const {
65  if(allFixed||i>=array.size()) {
66  return false;
67  }
68  return array[i];
69  }
70  void unsetAll() {
71  array=false;
72  }
73  void fixAll(bool val) {
74  allFixed=val;
75  }
76 private:
77  std::valarray<bool> array;
78  bool allFixed;
79 };
80 
81 /*
82  * templated delete functor for use in for_each loop over vector
83  */
84 struct delete_object
85 {
86  template <typename T>
87  void operator()(T *ptr){ delete ptr;}
88 };
89 /*
90  * Sum over the results of calling operation for each member in the
91  * iterator. Handier than std::accumulate because we can use with
92  * mem_fun to pass in a getter method.
93  */
94 template <class InputIterator, class T, class Operation >
95 T sum_over(InputIterator beg, InputIterator end, T init, Operation op)
96 {
97  for ( ; beg != end; ++beg)
98  init = init + op(*beg);
99  return init;
100 }
101 } // namespace cola
102 
103 #endif
libcola: Force-directed network layout subject to separation constraints library. ...
Definition: box.cpp:25