Back to index

texmacs  1.0.7.15
space.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : space.cpp
00004 * DESCRIPTION: spacing
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "space.hpp"
00013 
00014 /******************************************************************************
00015 * Constructors
00016 ******************************************************************************/
00017 
00018 space_rep::space_rep (SI min2, SI def2, SI max2) {
00019   min= min2;
00020   def= def2;
00021   max= max2;
00022 }
00023 
00024 space_rep::space_rep (SI def2) {
00025   min= def= max= def2;
00026 }
00027 
00028 space::space (SI min, SI def, SI max) {
00029   rep= tm_new<space_rep> (min, def, max);
00030 }
00031 
00032 space::space (SI def) {
00033   rep= tm_new<space_rep> (def);
00034 }
00035 
00036 space::operator tree () {
00037   return tree (TUPLE,
00038               as_string (rep->min),
00039               as_string (rep->def),
00040               as_string (rep->max));
00041 }
00042 
00043 /******************************************************************************
00044 * The routines which are provided
00045 ******************************************************************************/
00046 
00047 bool
00048 operator == (space spc1, space spc2) {
00049   return
00050     (spc1->min == spc2->min) &&
00051     (spc1->def == spc2->def) &&
00052     (spc1->max == spc2->max);
00053 }
00054 
00055 bool
00056 operator != (space spc1, space spc2) {
00057   return
00058     (spc1->min != spc2->min) ||
00059     (spc1->def != spc2->def) ||
00060     (spc1->max != spc2->max);
00061 }
00062 
00063 tm_ostream&
00064 operator << (tm_ostream& out, space spc) {
00065   out << "[ " << spc->min << ", " << spc->def << ", " << spc->max << " ]";
00066   return out;
00067 }
00068 
00069 space
00070 copy (space spc) {
00071   return space (spc->min, spc->def, spc->max);
00072 }
00073 
00074 space
00075 operator + (space spc1, space spc2) {
00076   return space (spc1->min + spc2->min,
00077               spc1->def + spc2->def,
00078               spc1->max + spc2->max);
00079 }
00080 
00081 space
00082 operator - (space spc1, space spc2) {
00083   return space (spc1->min - spc2->min,
00084               spc1->def - spc2->def,
00085               spc1->max - spc2->max);
00086 }
00087 
00088 space
00089 operator * (int i, space spc) {
00090   return space (i*spc->min, i*spc->def, i*spc->max);
00091 }
00092 
00093 space
00094 operator / (space spc, int i) {
00095   return space (spc->min/i, spc->def/i, spc->max/i);
00096 }
00097 
00098 space
00099 max (space spc1, space spc2) {
00100   return space (max (spc1->min, spc2->min),
00101               max (spc1->def, spc2->def),
00102               max (spc1->max, spc2->max));
00103 }