X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Finclude%2Fdirection.hh;h=0d36c0f7c7cca5ff25fb0a41f6917f52e1d01a83;hb=b872748c6aa8bb721ced458691b38ac2fac5dfc8;hp=ceff68fe5506dc135e5cfebba40f0e4b203f79bc;hpb=5b4b0d6e9a197e8f9eb085b7c2ad78b8be3e5cfc;p=lilypond.git diff --git a/flower/include/direction.hh b/flower/include/direction.hh index ceff68fe55..0d36c0f7c7 100644 --- a/flower/include/direction.hh +++ b/flower/include/direction.hh @@ -1,71 +1,79 @@ /* - 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--2015 Han-Wen Nienhuys - (c) 1997--2008 Han-Wen Nienhuys + 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 . */ #ifndef DIRECTION_HH #define DIRECTION_HH +#include #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, - }; - -inline Direction -other_dir (Direction const d) { - return (Direction) (-d); -} + UP = 1, + DOWN = -1, + LEFT = -1, + RIGHT = 1, + MIN = -1, + MAX = 1, + CENTER = 0, + SMALLER = -1, + BIGGER = 1, + START = -1, + STOP = 1, -inline Direction -operator - (Direction const d) -{ - return other_dir (d); -} + /* + This is necessary to safely write loops, + since + + dir <= RIGHT + + is otherwise transformed into true unconditionally. + */ + DIRECTION_LIMIT = 2, + DIRECTION_NEG_LIMIT = -2, +}; -// huh? inline Direction -flip (Direction *i) +operator - (Direction d) { - if (*i == (Direction)1) - *i = (Direction) - 1; - else if (*i == (Direction) - 1) - *i = (Direction)1; - return *i; + return Direction (- static_cast (d)); // cast avoids recursion } +#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 T minmax (Direction d, T, T); - -// String direction_string (Direction, Axis); +template T minmax (Direction d, T a, T b) +{ + if (d == UP) + return max (a, b); + else + return min (a, b); +} #endif // DIRECTION_HH