↑ Collapse diff ↑
Ignore white space 6 line context
1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2
 *
3
 * This file is a part of LEMON, a generic C++ optimization library.
4
 *
5
 * Copyright (C) 2003-2008
6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8
 *
9
 * Permission to use, modify and distribute this software is granted
10
 * provided that this copyright notice appears in all copies. For
11
 * precise terms see the accompanying LICENSE file.
12
 *
13
 * This software is provided "AS IS" with no warranty of any kind,
14
 * express or implied, and with no claim as to its suitability for any
15
 * purpose.
16
 *
17
 */
18

	
19
/*!
20

	
21
\page named-param Named Parameters
22

	
23
\section named-func-param Named Function Parameters
24

	
25
Several modern languages provide a convenient way to refer the
26
function parameters by name also when you call the function. It is
27
especially comfortable in case of a function having tons of parameters
28
with natural default values. Sadly, C++ lack this amenity.
29

	
30
However, with a crafty trick and with some little
31
inconvenience, it is possible to emulate is.
32
The example below shows how to do it.
33

	
34
\code
35
class namedFn
36
{
37
  int _id;
38
  double _val;
39
  int _dim;
40

	
41
  public:
42
  namedFn() : _id(0), _val(1), _dim(2) {}
43
  namedFn& id(int p)     { _id  = p ; return *this; }
44
  namedFn& val(double p) { _val = p ; return *this; }
45
  namedFn& dim(int p)    { _dim = p ; return *this; }
46

	
47
  run() {
48
    std::cout << "Here comes the function itself\n" <<
49
              << "With parameters "
50
              << _id << ", " << _val << ", " << _dim << std::endl;
51
  }
52
};
53
\endcode
54

	
55
Then you can use it like this.
56

	
57
\code
58
namedFn().id(3).val(2).run();
59
\endcode
60

	
61
The trick is obvious, each "named parameter" changes one component of
62
the underlying class, then gives back a reference to it. Finally,
63
<tt>run()</tt> executes the algorithm itself.
64

	
65
\note Although it is a class, namedFn is used pretty much like as it were
66
a function. That it why we called it namedFn instead of \c NamedFn.
67

	
68
\note In fact, the final <tt>.run()</tt> could be made unnecessary,
69
because the algorithm could also be implemented in the destructor of
70
\c namedFn instead. This however would make it impossible to implement
71
functions with return values, and would also cause serious problems when
72
implementing \ref named-templ-func-param "named template parameters".
73
<b>Therefore, by convention, <tt>.run()</tt> must be used
74
explicitly to execute a function having named parameters
75
everywhere in LEMON.</b>
76

	
77
\section named-templ-func-param Named Function Template Parameters
78

	
79
A named parameter can also be a template function. The usage is
80
exactly the same, but the implementation behind is a kind of black
81
magic and they are the dirtiest part of the LEMON code.
82

	
83
You will probably never need to know how it works, but if you really
84
committed, have a look at \ref lemon/graph_to_eps.h for an example.
85

	
86
\section traits-classes Traits Classes
87

	
88
A similar game can also be played when defining classes. In this case
89
the type of the class attributes can be changed. Initially we have to
90
define a special class called <em>Traits Class</em> defining the
91
default type of the attributes. Then the types of these attributes can
92
be changed in the same way as described in the next section.
93

	
94
See \ref lemon::DijkstraDefaultTraits for an
95
example how a traits class implementation looks like.
96

	
97
\section named-templ-param Named Class Template Parameters
98

	
99
If we would like to change the type of an attribute in a class that
100
was instantiated by using a traits class as a template parameter, and
101
the class contains named parameters, we do not have to instantiate again
102
the class with new traits class, but instead adaptor classes can
103
be used as shown in the following example.
104

	
105
\code
106
Dijkstra<>::SetPredMap<NullMap<Node,Arc> >::Create
107
\endcode
108

	
109
It can also be used in conjunction with other named template
110
parameters in arbitrary order.
111

	
112
\code
113
Dijkstra<>::SetDistMap<MyMap>::SetPredMap<NullMap<Node,Arc> >::Create
114
\endcode
115

	
116
The result will be an instantiated Dijkstra class, in which the
117
DistMap and the PredMap is modified.
118

	
119
*/
Ignore white space 6 line context
1
#! /usr/bin/env python
2

	
3
import sys
4
import os
5

	
6
if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]:
7
    print """
8
This utility just prints the length of the longest path
9
in the revision graph from revison 0 to the current one.
10
"""
11
    exit(0)
12
plist = os.popen("hg parents --template='{rev}\n'").readlines()
13
if len(plist)>1:
14
    print "You are in the process of merging"
15
    exit(1)
16
PAR = int(plist[0])
17

	
18
f = os.popen("hg log -r 0:tip --template='{rev} {parents}\n'").readlines()
19
REV = -1
20
lengths=[]
21
for l in f:
22
    REV+=1
23
    s = l.split()
24
    rev = int(s[0])
25
    if REV != rev:
26
        print "Something is seriously wrong"
27
        exit(1)
28
    if len(s) == 1:
29
        par1 = par2 = rev - 1
30
    elif len(s) == 2:
31
        par1 = par2 = int(s[1].split(":")[0])
32
    else:
33
        par1 = int(s[1].split(":")[0])
34
        par2 = int(s[2].split(":")[0])
35
    if rev == 0:
36
        lengths.append(0)
37
    else:
38
        lengths.append(max(lengths[par1],lengths[par2])+1)
39
print lengths[PAR]
Ignore white space 6 line context
... ...
@@ -2,13 +2,4 @@
2 2

	
3
#EXECUTE_PROCESS(
4
#  COMMAND hg id -i
5
#  OUTPUT_VARIABLE HG_REVISION
6
#  OUTPUT_STRIP_TRAILING_WHITESPACE)
7

	
8 3
SET(PROJECT_NAME "LEMON")
9
SET(PROJECT_VERSION_MAJOR "0")
10
SET(PROJECT_VERSION_MINOR "99")
11
SET(PROJECT_VERSION_PATCH "0")
12
SET(PROJECT_VERSION
13
  "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
4
SET(PROJECT_VERSION "hg-tip" CACHE STRING "The version string.")
14 5

	
... ...
@@ -41,5 +32,2 @@
41 32

	
42
  SET(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
43
  SET(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
44
  SET(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
45 33
  SET(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
... ...
@@ -47,5 +35,5 @@
47 35
  SET(CPACK_PACKAGE_INSTALL_DIRECTORY
48
    "${PROJECT_NAME} ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
36
    "${PROJECT_NAME} ${PROJECT_VERSION}")
49 37
  SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
50
    "${PROJECT_NAME} ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
38
    "${PROJECT_NAME} ${PROJECT_VERSION}")
51 39

	
Show white space 6 line context
1
20XX-XX-XX Version 1.0 released
2

	
3
	This is the first stable release of LEMON. Compared to the 0.x
4
	release series, it features a considerably smaller but more
5
	matured set of tools. The API has also completely revised and
6
	changed in several places.
7

	
8
	* The major name changes compared to the 0.x series
9
          * Graph -> Digraph, UGraph -> Graph
10
          * Edge -> Arc, UEdge -> Edge
11
	  * source(UEdge)/target(UEdge) -> u(Edge)/v(Edge)
12
	* Other improvements
13
	  * Better documentation
14
	  * Reviewed and cleaned up codebase
15
	  * CMake based build system (along with the autotools based one)
16
	* Contents of the library (ported from 0.x)
17
	  * Algorithms
18
       	    * breadth-first search (bfs.h)
19
       	    * depth-first search (dfs.h)
20
       	    * Dijkstra's algorithm (dijkstra.h)
21
       	    * Kruskal's algorithm (kruskal.h)
22
    	  * Data structures
23
       	    * graph data structures (list_graph.h, smart_graph.h)
24
       	    * path data structures (path.h)
25
       	    * binary heap data structure (bin_heap.h)
26
       	    * union-find data structures (unionfind.h)
27
       	    * miscellaneous property maps (maps.h)
28
       	    * two dimensional vector and bounding box (dim2.h)
29
          * Concepts
30
       	    * graph structure concepts (concepts/digraph.h, concepts/graph.h,
31
              concepts/graph_components.h)
32
       	    * concepts for other structures (concepts/heap.h, concepts/maps.h,
33
	      concepts/path.h)
34
    	  * Tools
35
       	    * Mersenne twister random number generator (random.h)
36
       	    * tools for measuring cpu and wall clock time (time_measure.h)
37
       	    * tools for counting steps and events (counter.h)
38
       	    * tool for parsing command line arguments (arg_parser.h)
39
       	    * tool for visualizing graphs (graph_to_eps.h)
40
       	    * tools for reading and writing data in LEMON Graph Format
41
              (lgf_reader.h, lgf_writer.h)
42
            * tools to handle the anomalies of calculations with
43
	      floating point numbers (tolerance.h)
44
            * tools to manage RGB colors (color.h)
45
    	  * Infrastructure
46
       	    * extended assertion handling (assert.h)
47
       	    * exception classes and error handling (error.h)
48
      	    * concept checking (concept_check.h)
49
       	    * commonly used mathematical constants (math.h)
Ignore white space 6 line context
... ...
@@ -3,5 +3,11 @@
3 3
dnl Version information.
4
m4_define([lemon_version_number], [])
4
m4_define([lemon_version_number],
5
	[m4_normalize(esyscmd([echo ${LEMON_VERSION}]))])
6
dnl m4_define([lemon_version_number], [])
7
m4_define([lemon_hg_path], [m4_normalize(esyscmd([./scripts/chg-len.py]))])
5 8
m4_define([lemon_hg_revision], [m4_normalize(esyscmd([hg id -i]))])
6
m4_define([lemon_version], [ifelse(lemon_version_number(), [], [lemon_hg_revision()], [lemon_version_number()])])
9
m4_define([lemon_version], [ifelse(lemon_version_number(),
10
			   [],
11
			   [lemon_hg_path().lemon_hg_revision()],
12
			   [lemon_version_number()])])
7 13

	
Ignore white space 6 line context
... ...
@@ -8,2 +8,3 @@
8 8
	doc/mainpage.dox \
9
	doc/named-param.dox \
9 10
	doc/namespaces.dox \
Ignore white space 6 line context
... ...
@@ -18,4 +18,4 @@
18 18

	
19
#ifndef LEMON_ARG_PARSER
20
#define LEMON_ARG_PARSER
19
#ifndef LEMON_ARG_PARSER_H
20
#define LEMON_ARG_PARSER_H
21 21

	
... ...
@@ -384,2 +384,2 @@
384 384

	
385
#endif // LEMON_ARG_PARSER
385
#endif // LEMON_ARG_PARSER_H
Ignore white space 6 line context
... ...
@@ -29,4 +29,5 @@
29 29

	
30
  inline void assert_fail_log(const char *file, int line, const char *function,
31
                              const char *message, const char *assertion)
30
  inline void assert_fail_abort(const char *file, int line,
31
                                const char *function, const char* message,
32
                                const char *assertion)
32 33
  {
... ...
@@ -39,9 +40,2 @@
39 40
    std::cerr << std::endl;
40
  }
41

	
42
  inline void assert_fail_abort(const char *file, int line,
43
                                const char *function, const char* message,
44
                                const char *assertion)
45
  {
46
    assert_fail_log(file, line, function, message, assertion);
47 41
    std::abort();
... ...
@@ -65,7 +59,5 @@
65 59
#undef LEMON_ASSERT
66
#undef LEMON_FIXME
67 60
#undef LEMON_DEBUG
68 61

	
69
#if (defined(LEMON_ASSERT_LOG) ? 1 : 0) +               \
70
  (defined(LEMON_ASSERT_ABORT) ? 1 : 0) +               \
62
#if (defined(LEMON_ASSERT_ABORT) ? 1 : 0) +               \
71 63
  (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) > 1
... ...
@@ -74,4 +66,3 @@
74 66

	
75
#if ((defined(LEMON_ASSERT_LOG) ? 1 : 0) +              \
76
     (defined(LEMON_ASSERT_ABORT) ? 1 : 0) +            \
67
#if ((defined(LEMON_ASSERT_ABORT) ? 1 : 0) +            \
77 68
     (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) == 1 ||     \
... ...
@@ -84,6 +75,3 @@
84 75

	
85
#if defined LEMON_ASSERT_LOG
86
#  undef LEMON_ASSERT_HANDLER
87
#  define LEMON_ASSERT_HANDLER ::lemon::assert_fail_log
88
#elif defined LEMON_ASSERT_ABORT
76
#if defined LEMON_ASSERT_ABORT
89 77
#  undef LEMON_ASSERT_HANDLER
... ...
@@ -109,4 +97,6 @@
109 97
#    define LEMON_FUNCTION_NAME (__FUNCSIG__)
98
#  elif __STDC_VERSION__ >= 199901L
99
#    define LEMON_FUNCTION_NAME (__func__)
110 100
#  else
111
#    define LEMON_FUNCTION_NAME (__func__)
101
#    define LEMON_FUNCTION_NAME ("<unknown>")
112 102
#  endif
... ...
@@ -120,8 +110,8 @@
120 110
///
121
/// Macro for assertion with customizable message.  \param exp An
122
/// expression that must be convertible to \c bool.  If it is \c
123
/// false, then an assertion is raised. The concrete behaviour depends
124
/// on the settings of the assertion system.  \param msg A <tt>const
125
/// char*</tt> parameter, which can be used to provide information
126
/// about the circumstances of the failed assertion.
111
/// Macro for assertion with customizable message.  
112
/// \param exp An expression that must be convertible to \c bool.  If it is \c
113
/// false, then an assertion is raised. The concrete behaviour depends on the
114
/// settings of the assertion system.
115
/// \param msg A <tt>const char*</tt> parameter, which can be used to provide
116
/// information about the circumstances of the failed assertion.
127 117
///
... ...
@@ -139,13 +129,8 @@
139 129
///
140
/// The LEMON assertion system has a wide range of customization
141
/// properties. As a default behaviour the failed assertion prints a
142
/// short log message to the standard error and aborts the execution.
130
/// As a default behaviour the failed assertion prints a short log message to
131
/// the standard error and aborts the execution.
143 132
///
144
/// The following modes can be used in the assertion system:
145
///
146
/// - \c LEMON_ASSERT_LOG The failed assertion prints a short log
147
///   message to the standard error and continues the execution.
148
/// - \c LEMON_ASSERT_ABORT This mode is similar to the \c
149
///   LEMON_ASSERT_LOG, but it aborts the program. It is the default
150
///   behaviour.
133
/// However, the following modes can be used in the assertion system:
134
/// - \c LEMON_ASSERT_ABORT The failed assertion prints a short log message to
135
///   the standard error and aborts the program. It is the default behaviour.
151 136
/// - \c LEMON_ASSERT_CUSTOM The user can define own assertion handler
... ...
@@ -177,18 +162,2 @@
177 162
///
178
/// \brief Macro for mark not yet implemented features.
179
///
180
/// Macro for mark not yet implemented features and outstanding bugs.
181
/// It is close to be the shortcut of the following code:
182
/// \code
183
///   LEMON_ASSERT(false, msg);
184
/// \endcode
185
///
186
/// \see LEMON_ASSERT
187
#  define LEMON_FIXME(msg)                                              \
188
  (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME,        \
189
                        ::lemon::_assert_bits::cstringify(msg),         \
190
                        static_cast<const char*>(0)))
191

	
192
/// \ingroup exceptions
193
///
194 163
/// \brief Macro for internal assertions
... ...
@@ -224,3 +193,2 @@
224 193
#    define LEMON_ASSERT(exp, msg)  (static_cast<void>(0))
225
#    define LEMON_FIXME(msg) (static_cast<void>(0))
226 194
#    define LEMON_DEBUG(exp, msg) (static_cast<void>(0))
... ...
@@ -233,7 +201,2 @@
233 201
                             #exp), 0)))
234
#    define LEMON_FIXME(msg)                                            \
235
       (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME,   \
236
                             ::lemon::_assert_bits::cstringify(msg),    \
237
                             static_cast<const char*>(0)))
238

	
239 202
#    if LEMON_ENABLE_DEBUG
Ignore white space 6 line context
... ...
@@ -105,2 +105,3 @@
105 105

	
106
  private:
106 107
    /// \brief Constructor to copy a map of the same map type.
... ...
@@ -152,2 +153,3 @@
152 153

	
154
  public:
153 155
    /// \brief The destructor of the map.
Ignore white space 6 line context
... ...
@@ -229,2 +229,3 @@
229 229

	
230
    private:
230 231
      NodeMap& operator=(const NodeMap& cmap) {
... ...
@@ -253,2 +254,3 @@
253 254

	
255
    private:
254 256
      ArcMap& operator=(const ArcMap& cmap) {
... ...
@@ -610,2 +612,3 @@
610 612

	
613
    private:
611 614
      NodeMap& operator=(const NodeMap& cmap) {
... ...
@@ -634,2 +637,3 @@
634 637

	
638
    private:
635 639
      ArcMap& operator=(const ArcMap& cmap) {
... ...
@@ -659,2 +663,3 @@
659 663

	
664
    private:
660 665
      EdgeMap& operator=(const EdgeMap& cmap) {
Ignore white space 6 line context
... ...
@@ -64,2 +64,3 @@
64 64

	
65
  private:
65 66
    MapExtender& operator=(const MapExtender& cmap) {
... ...
@@ -74,2 +75,3 @@
74 75

	
76
  public:
75 77
    class MapIt : public Item {
... ...
@@ -202,2 +204,3 @@
202 204

	
205
  private:
203 206
    SubMapExtender& operator=(const SubMapExtender& cmap) {
... ...
@@ -216,2 +219,3 @@
216 219

	
220
  public:
217 221
    class MapIt : public Item {
Ignore white space 6 line context
... ...
@@ -102,2 +102,3 @@
102 102

	
103
  private:
103 104
    /// \brief Copy constructor
Ignore white space 6 line context
... ...
@@ -436,2 +436,3 @@
436 436

	
437
      private:
437 438
        ///Copy constructor
... ...
@@ -458,2 +459,3 @@
458 459
        ArcMap(const Digraph&, T) { }
460
      private:
459 461
        ///Copy constructor
Ignore white space 6 line context
... ...
@@ -514,2 +514,3 @@
514 514

	
515
      private:
515 516
        ///Copy constructor
... ...
@@ -537,2 +538,3 @@
537 538
        ArcMap(const Graph&, T) { }
539
      private:
538 540
        ///Copy constructor
... ...
@@ -560,2 +562,3 @@
560 562
        EdgeMap(const Graph&, T) { }
563
      private:
561 564
        ///Copy constructor
Ignore white space 6 line context
... ...
@@ -1007,2 +1007,4 @@
1007 1007
      GraphMap(const Graph&, const Value&) {}
1008

	
1009
    private:
1008 1010
      /// \brief Copy constructor.
... ...
@@ -1023,2 +1025,3 @@
1023 1025

	
1026
    public:
1024 1027
      template<typename _Map>
... ...
@@ -1032,9 +1035,10 @@
1032 1035
          // Copy constructor.
1033
          _Map b(c);
1036
          // _Map b(c);
1034 1037

	
1035
          ReadMap<Key, Value> cmap;
1036
          b = cmap;
1038
          // ReadMap<Key, Value> cmap;
1039
          // b = cmap;
1037 1040

	
1041
          ignore_unused_variable_warning(a);
1038 1042
          ignore_unused_variable_warning(a2);
1039
          ignore_unused_variable_warning(b);
1043
          // ignore_unused_variable_warning(b);
1040 1044
        }
... ...
@@ -1084,2 +1088,3 @@
1084 1088

	
1089
      private:
1085 1090
        /// \brief Copy constructor.
... ...
@@ -1121,2 +1126,3 @@
1121 1126

	
1127
      private:
1122 1128
        /// \brief Copy constructor.
... ...
@@ -1217,2 +1223,3 @@
1217 1223

	
1224
      private:
1218 1225
        /// \brief Copy constructor.
Ignore white space 6 line context
... ...
@@ -49,6 +49,2 @@
49 49

	
50
void fixme_disable() {
51
  LEMON_FIXME("fixme_disable() is fixme!");
52
}
53

	
54 50
void check_assertion_disable() {
... ...
@@ -56,3 +52,2 @@
56 52
  assertion_text_disable();
57
  fixme_disable();
58 53
}
... ...
@@ -80,6 +75,2 @@
80 75

	
81
void fixme_custom() {
82
  LEMON_FIXME("fixme_custom() is fixme!");
83
}
84

	
85 76
void check_assertion_custom() {
... ...
@@ -87,4 +78,3 @@
87 78
  assertion_text_custom();
88
  fixme_custom();
89
  check(cnt == 2, "The custom assert handler does not work");
79
  check(cnt == 1, "The custom assert handler does not work");
90 80
}
Ignore white space 6 line context
... ...
@@ -214,6 +214,6 @@
214 214

	
215
    map = constMap<Node>(12);
216
    for (NodeIt it(G); it != INVALID; ++it) {
217
      check(map[it] == 12, "Wrong operator[].");
218
    }
215
    // map = constMap<Node>(12);
216
    // for (NodeIt it(G); it != INVALID; ++it) {
217
    //   check(map[it] == 12, "Wrong operator[].");
218
    // }
219 219
  }
... ...
@@ -244,6 +244,6 @@
244 244

	
245
    map = constMap<Arc>(12);
246
    for (ArcIt it(G); it != INVALID; ++it) {
247
      check(map[it] == 12, "Wrong operator[].");
248
    }
245
    // map = constMap<Arc>(12);
246
    // for (ArcIt it(G); it != INVALID; ++it) {
247
    //   check(map[it] == 12, "Wrong operator[].");
248
    // }
249 249
  }
... ...
@@ -274,6 +274,6 @@
274 274

	
275
    map = constMap<Edge>(12);
276
    for (EdgeIt it(G); it != INVALID; ++it) {
277
      check(map[it] == 12, "Wrong operator[].");
278
    }
275
    // map = constMap<Edge>(12);
276
    // for (EdgeIt it(G); it != INVALID; ++it) {
277
    //   check(map[it] == 12, "Wrong operator[].");
278
    // }
279 279
  }
0 comments (0 inline)