\end_document replaces \the_end.
[lyx.git] / src / lyxgluelength.C
blobc7c90432293f931ee3363c06b256f65244ee42bb
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-2001 The LyX Team.
8  *
9  * ====================================================== */
11 #include <config.h>
13 #include "lyxgluelength.h"
14 #include "lengthcommon.h"
16 #include "Lsstream.h"
19 LyXGlueLength::LyXGlueLength(LyXLength const & len)
20         : len_(len)
24 LyXGlueLength::LyXGlueLength(LyXLength const & len, LyXLength const & plus,
25                 LyXLength const & minus)
26         : len_(len), plus_(plus), minus_(minus)
30 LyXGlueLength::LyXGlueLength(string const & data)
32         isValidGlueLength(data, this);
36 string const LyXGlueLength::asString() const
38         ostringstream buffer;
40         buffer << len_.value();
42         if (plus_.zero() && minus_.zero()) {
43                 buffer << unit_name[len_.unit()];
44                 return STRCONV(buffer.str());
45         }
47         // just len and plus
48         if (minus_.zero()) {
49                 if (len_.unit() != plus_.unit())
50                         buffer << unit_name[len_.unit()];
51                 buffer << '+' << plus_.value();
52                 buffer << unit_name[plus_.unit()];
53                 return STRCONV(buffer.str());
54         }
56         // just len and minus
57         if (plus_.zero()) {
58                 if (len_.unit() != minus_.unit())
59                         buffer << unit_name[len_.unit()];
60                 buffer << '-' << minus_.value();
61                 buffer << unit_name[minus_.unit()];
62                 return STRCONV(buffer.str());
63         }
65         // ok, len, plus AND minus
67         // len+-
68         if (minus_ == plus_) {
69                 if (len_.unit() != minus_.unit())
70                         buffer << unit_name[len_.unit()];
71                 buffer << "+-" << minus_.value();
72                 buffer << unit_name[minus_.unit()];
73                 return STRCONV(buffer.str());
74         }
76         // this is so rare a case, why bother minimising units ?
78         buffer << unit_name[len_.unit()];
79         buffer << '+' << plus_.value() << unit_name[plus_.unit()];
80         buffer << '-' << minus_.value() << unit_name[minus_.unit()];
82         return STRCONV(buffer.str());
86 string const LyXGlueLength::asLatexString() const
88         ostringstream buffer;
90         buffer << len_.value() << unit_name[len_.unit()];
92         if (!plus_.zero())
93                 buffer << " plus " << plus_.value() << unit_name[plus_.unit()];
94         if (!minus_.zero())
95                 buffer << " minus " << minus_.value() << unit_name[minus_.unit()];
96         return STRCONV(buffer.str());
100 LyXLength const & LyXGlueLength::len() const
102         return len_;
106 LyXLength const & LyXGlueLength::plus() const
108         return plus_;
112 LyXLength const & LyXGlueLength::minus() const
114         return minus_;
118 bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
120         return l1.len() == l2.len()
121                  && l1.plus() == l2.plus()
122                  && l1.minus() == l2.minus();
126 bool operator!=(LyXGlueLength const & l1, LyXGlueLength const & l2)
128         return !(l1 == l2);