]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/include/direction.hh
Run grand-replace (issue 3765)
[lilypond.git] / flower / include / direction.hh
index 417c34146143aeb4d0518de8afc35e93ee82c83f..6c6b9a7d0221ef8d0ae7cd21b58ec636634cad61 100644 (file)
@@ -1,9 +1,20 @@
 /*
-  direction.hh -- declare Direction
+  This file is part of LilyPond, the GNU music typesetter.
 
-  source file of the GNU LilyPond music typesetter
+  Copyright (C) 1997--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
-  (c) 1997--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  LilyPond is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  LilyPond 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 General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifndef DIRECTION_HH
 #include "axis.hh"
 
 enum Direction
-  {
-    UP = 1,
-    DOWN=-1,
-    LEFT=-1,
-    RIGHT = 1,
-    MIN=-1,
-    MAX = 1,
-    CENTER = 0,
-    SMALLER=-1,
-    BIGGER = 1,
-    START = -1,
-    STOP = 1,
-
-    /*
-      This is necessary to safely write loops,
-      since
-
-      dir <= RIGHT
-
-      is otherwise transformed into true unconditionally.
-    */
-    DIRECTION_LIMIT = 2,
-    DIRECTION_NEG_LIMIT = -2,
-  };
+{
+  UP = 1,
+  DOWN = -1,
+  LEFT = -1,
+  RIGHT = 1,
+  MIN = -1,
+  MAX = 1,
+  CENTER = 0,
+  SMALLER = -1,
+  BIGGER = 1,
+  START = -1,
+  STOP = 1,
+
+  /*
+    This is necessary to safely write loops,
+    since
+
+    dir <= RIGHT
+
+    is otherwise transformed into true unconditionally.
+  */
+  DIRECTION_LIMIT = 2,
+  DIRECTION_NEG_LIMIT = -2,
+};
 
 inline Direction
 other_dir (Direction const d)
@@ -49,7 +60,7 @@ operator - (Direction const d)
   return other_dir (d);
 }
 
-// huh?
+// to be deleted soon (after coping with issues 2491 and 2493
 inline Direction
 flip (Direction *i)
 {
@@ -60,11 +71,26 @@ flip (Direction *i)
   return *i;
 }
 
+#define UP_and_DOWN(d) \
+  Direction d = UP; d != CENTER; d = (d == UP ? DOWN : CENTER)
+
+#define DOWN_and_UP(d) \
+  Direction d = DOWN; d != CENTER; d = (d == DOWN ? UP : CENTER)
+
+#define LEFT_and_RIGHT(d) \
+  Direction d = LEFT; d != CENTER; d = (d == LEFT ? RIGHT : CENTER)
+
 /**
    if d > 0: the max operator
    if d < 0: the min operator
 */
-template<class T> T minmax (Direction d, T, T);
+template<class T> T minmax (Direction d, T a, T b)
+{
+  if (d == UP)
+    return max (a, b);
+  else
+    return min (a, b);
+}
 
 // String direction_string (Direction, Axis);