head     1.23;
branch   ;
access   ;
symbols  ;
locks    ; strict;
comment  @// @;


1.23
date     92.07.01.17.14.10;  author fischer;  state Exp;
branches ;
next     1.22;

1.22
date     92.06.29.03.43.32;  author fischer;  state Exp;
branches ;
next     1.21;

1.21
date     92.06.28.05.18.00;  author fischer;  state Exp;
branches ;
next     1.20;

1.20
date     92.06.27.05.07.29;  author fischer;  state Exp;
branches ;
next     1.19;

1.19
date     92.06.17.15.22.29;  author thoth;  state Exp;
branches ;
next     1.18;

1.18
date     92.06.16.13.57.19;  author thoth;  state Exp;
branches ;
next     1.17;

1.17
date     92.06.10.11.55.41;  author thoth;  state Exp;
branches ;
next     1.16;

1.16
date     92.06.09.12.28.05;  author fischer;  state Exp;
branches ;
next     1.15;

1.15
date     92.06.08.02.52.38;  author fischer;  state Exp;
branches ;
next     1.14;

1.14
date     92.06.02.01.45.52;  author fischer;  state Exp;
branches ;
next     1.13;

1.13
date     92.05.27.07.46.40;  author fischer;  state Exp;
branches ;
next     1.12;

1.12
date     92.05.26.07.43.51;  author fischer;  state Exp;
branches ;
next     1.11;

1.11
date     92.05.22.07.13.50;  author fischer;  state Exp;
branches ;
next     1.10;

1.10
date     92.05.21.20.24.32;  author thoth;  state Exp;
branches ;
next     1.9;

1.9
date     92.05.21.15.10.55;  author thoth;  state Exp;
branches ;
next     1.8;

1.8
date     92.05.21.12.05.23;  author thoth;  state Exp;
branches ;
next     1.7;

1.7
date     92.05.21.08.07.58;  author fischer;  state Exp;
branches ;
next     1.6;

1.6
date     92.05.20.06.29.29;  author fischer;  state Exp;
branches ;
next     1.5;

1.5
date     92.05.18.15.15.42;  author thoth;  state Exp;
branches ;
next     1.4;

1.4
date     92.05.18.14.22.36;  author thoth;  state Exp;
branches ;
next     1.3;

1.3
date     92.05.18.11.14.07;  author thoth;  state Exp;
branches ;
next     1.2;

1.2
date     92.05.16.13.57.59;  author thoth;  state Exp;
branches ;
next     1.1;

1.1
date     92.05.16.13.48.28;  author thoth;  state Exp;
branches ;
next     ;


desc
@this is the header file for Coord, the image
algebra coordinate type.
@


1.23
log
@Added Rob's simpler const constructor and operator= as inlines.
@
text
@// Emacs: -*- C++ -*-

#ifndef Coord_h_
#define Coord_h_

//
// $Log:	Coord.h,v $
// Revision 1.22  92/06/29  03:43:32  fischer
// Added real Coord &operator= code, uncommented the ~Coord(). Just in case.
// 
// Revision 1.21  92/06/28  05:18:00  fischer
// Made promote accept const NumericType args, made it const member function.
// 
// Revision 1.20  92/06/27  05:07:29  fischer
// Changed ouput operator << to use pass by ref for Coord so I 
// could get a look at what was happening in the (slightly busted)
// debugger.
// 
// Revision 1.19  92/06/17  15:22:29  thoth
// added input and string conversion operations.
// 
// Revision 1.18  92/06/16  13:57:19  thoth
// updated to follow new enum constant conventions
// removed operations that only make sense on integers
// 
// Revision 1.17  92/06/10  11:55:41  thoth
// updated some more, to reflect new conventions.
// 
// Revision 1.16  92/06/09  12:28:05  fischer
// Made most Coord operators non-member friends to get
// automatic type coercion.
// 
// Revision 1.15  92/06/08  02:52:38  fischer
// Simplified switch statements (removed Complex: and Rational:
// cases).  No extra break statements needed to be added (stylistic
// nit). Since Integer is the base type,  removed most calls to
// int(foo) $ int(bar)  where $ is some binary op,  replacing them
// with foo.value.i & bar.value.i.  This should result in substantial
// savings,  but will necessitate careful rewrite should a ``lower''
// type such as Char or Boolean be added to Coord.
// 
// Revision 1.14  92/06/02  01:45:52  fischer
// Made assignment operators const Coord&.  Removed 
// Removed !, &&, and ||.
// 
// Revision 1.13  92/05/27  07:46:40  fischer
// Added && and || as one arg friend functions, which is
// only way to preserve special semantics. Added bitwise
// compound assignment.  Changed bitwise operators to work
// between Coords, except for shift operators which now
// use signed ints.
// 
// Revision 1.13  1992/05/26  11:30:30  fischer
// Added more arithmetic and bitwise operators. Just a few to go.
//
// Revision 1.12  1992/05/24  11:44:53  fischer
// Added destructive assignment operations, pre- and post-
// increment and decrement.  Found << *will* work with gcc 2.0.
// None of this will work correctly with gcc 2.1 (overloading
// broken when application uses it).
//
// Revision 1.11  1992/05/22  07:13:50  fischer
// Got overloading to work by simple expedient of using math.ufl.edu
// version of g++:  gcc-2.0.
// Changed Coord arithmetic operators to assume result_type()
// is taking care of uninitialized Coord types (tag==None) via throw.
// Added default: to switches so Rob can rest easy about new
// NumericTypes.  Added *,/,+,%,-.  Lots more to go. Since we now
// have NumericType abstraction,  changed stuff like this->tag to
// this->type():  because these are inline functions, there should be little
// overhead, but we need to check with some timing tests.
// Changed Coord.val name to Coord.value name since I can never remember
// these damn c-style abbreviations.   .
//
// Revision 1.10  92/05/21  20:24:32  thoth
// switched to // comments for rcs log
// 
// Revision 1.9  92/05/21  15:10:55  thoth
// add addition operator.  Use of this operator
// causes the compiler to hang.
// declared some methods const (unmodifying).
// 
// Revision 1.8  92/05/21  12:05:23  thoth
// *** empty log message ***
// 
// Revision 1.7  92/05/21  08:07:58  fischer
// Started rework of CoordType to IA::NumericType
// so all classes can access.
// 
// Revision 1.6  92/05/20  06:29:29  fischer
// created a scheme to get around thoth's scheme:
// removed it.
// 
// Revision 1.5  92/05/18  15:15:42  thoth
// created a scheme to get around g++2.1's busted overloading
// and type conversion.
// 
// Revision 1.4  92/05/18  14:22:36  thoth
// modified conditional surrounding operator int and float.
// this gives readers a clue as to why they aren't available.
// 
// Revision 1.3  92/05/18  11:14:07  thoth
// minor frobs, added type converter,
// added tag retrieval method.
// 
// Revision 1.2  92/05/16  13:57:59  thoth
// added log goo
// 
// Revision 1.1  92/05/16  13:48:28  thoth
// Initial revision
//

// TO DO:: input <<
// TO DO:: check for self assignment special cases. 

#include <iostream.h>
#include "ia.h"

class Coord {
    NumericType	tag;
    union CoordValue {
	int	i;
	float	f;
    } value;


public:
    // constructors

    Coord() {tag=NONE;}
    Coord(int i)  {tag=INTEGER; value.i = i;}
    Coord(float f) {tag=REAL; value.f = f;}

    // Forsman sez gratuitous.
    //
    ~Coord(){}		
    Coord(const Coord& coordinate)	
    { this->tag = coordinate.tag; this->value = coordinate.value; }
    Coord &operator=(const Coord& coordinate)
    { this->tag = coordinate.tag; this->value = coordinate.value; return *this; }

    // Destructive arithmetic.
    
    Coord& operator++ ();
    Coord& operator-- ();

    operator int() const;
    operator float() const;

    // Some arithmetic operations.

    friend Coord operator+ (const Coord&, const Coord&);
    friend Coord operator* (const Coord&, const Coord&);
    friend Coord operator- (const Coord&);
    friend Coord operator- (const Coord&, const Coord&);
    friend Coord operator/ (const Coord&, const Coord&);

    //  It was decided that operations that only make sense on integers
    // would not be defined for Coords.  Coords may be implicitly converted
    // to integers just as efficiently as we can do it in a member function.

//     friend Coord operator% (const Coord&, const Coord&);
// 
//     // Bitwise functions.
// 
//     friend Coord operator~  (const Coord&);
//     friend Coord operator<< (const Coord&, unsigned int);
//     friend Coord operator>> (const Coord&, unsigned int);
//     friend Coord operator&  (const Coord&, const Coord&);
//     friend Coord operator^  (const Coord&, const Coord&);
//     friend Coord operator|  (const Coord&, const Coord&);

    // Comparisons.
    
    friend char operator <  (const Coord&, const Coord&);
    friend char operator <= (const Coord&, const Coord&);
    friend char operator == (const Coord&, const Coord&);
    friend char operator >= (const Coord&, const Coord&);
    friend char operator >  (const Coord&, const Coord&);
    friend char operator != (const Coord&, const Coord&);

    // Compound assignments

    const Coord& operator+=  (const Coord&);
    const Coord& operator*=  (const Coord&);
    const Coord& operator-=  (const Coord&);
    const Coord& operator/=  (const Coord&);
    const Coord& operator%=  (const Coord&);

    // however, implicit conversion to int does not help us for these functions

    const Coord& operator<<= (int);
    const Coord& operator>>= (int);

    const Coord& operator&=  (const Coord&);
    const Coord& operator^=  (const Coord&);
    const Coord& operator|=  (const Coord&);

    // Type functions.

    NumericType type() const {return this->tag;}

    Coord promote (const NumericType) const;

    friend ostream& operator<<(ostream&, Coord&);
    friend istream& operator>>(istream&, Coord&);
};

Coord atoCoord(const char *s);

#endif
@


1.22
log
@Added real Coord &operator= code, uncommented the ~Coord(). Just in case.
@
text
@d8 3
d137 4
a140 2
    Coord(const Coord&);	
    Coord &operator=(const Coord&);	
@


1.21
log
@Made promote accept const NumericType args, made it const member function.
@
text
@d8 3
d133 1
a133 1
    // ~Coord(){}		
d135 1
a135 1
    // const Coord &operator=(const Coord&);	
a139 1
    Coord& operator++ (int);	// no difference in gcc 2.0
@


1.20
log
@Changed ouput operator << to use pass by ref for Coord so I 
could get a look at what was happening in the (slightly busted)
debugger.
@
text
@d8 5
d196 1
a196 1
    Coord promote (NumericType);
@


1.19
log
@added input and string conversion operations.
@
text
@d8 3
d126 1
a126 1
    // Coord(const Coord&);	
d193 1
a193 1
    friend ostream& operator<<(ostream&, Coord);
@


1.18
log
@updated to follow new enum constant conventions
removed operations that only make sense on integers
@
text
@d8 4
d191 1
d194 1
@


1.17
log
@updated some more, to reflect new conventions.
@
text
@d8 3
a101 1
    /*IA::*/
d112 3
a114 3
    Coord() {tag=None;}
    Coord(int i)  {tag=Integer; value.i = i;}
    Coord(float f) {tag=Float; value.f = f;}
d116 1
a116 1
    // Forsman: gratuitous.
a137 1
    friend Coord operator% (const Coord&, const Coord&);
d139 3
a141 1
    // Bitwise functions.
d143 10
a152 6
    friend Coord operator~  (const Coord&);
    friend Coord operator<< (const Coord&, unsigned int);
    friend Coord operator>> (const Coord&, unsigned int);
    friend Coord operator&  (const Coord&, const Coord&);
    friend Coord operator^  (const Coord&, const Coord&);
    friend Coord operator|  (const Coord&, const Coord&);
d170 2
@


1.16
log
@Made most Coord operators non-member friends to get
automatic type coercion.
@
text
@d8 4
d96 1
a96 1
#include <ia.h>
@


1.15
log
@Simplified switch statements (removed Complex: and Rational:
cases).  No extra break statements needed to be added (stylistic
nit). Since Integer is the base type,  removed most calls to
int(foo) $ int(bar)  where $ is some binary op,  replacing them
with foo.value.i & bar.value.i.  This should result in substantial
savings,  but will necessitate careful rewrite should a ``lower''
type such as Char or Boolean be added to Coord.
@
text
@d8 9
d110 2
a111 2
    // Forsman sez: gratuitous

d127 6
a132 6
    Coord operator+ (const Coord&) const;
    Coord operator* (const Coord&) const;
    Coord operator- () const;
    Coord operator- (const Coord&) const;
    Coord operator/ (const Coord&) const;
    Coord operator% (const Coord&) const;
d136 6
a141 6
    Coord operator~  () const;
    Coord operator<< (int) const;
    Coord operator>> (int) const;
    Coord operator&  (const Coord&) const;
    Coord operator^  (const Coord&) const;
    Coord operator|  (const Coord&) const;
d143 1
a143 1
    // Comparisons
@


1.14
log
@Made assignment operators const Coord&.  Removed 
Removed !, &&, and ||.
@
text
@d1 1
a1 1
// This may look like C code, emacs, but it is really -*- C++ -*-
d8 4
d108 1
a108 1

d110 1
a112 4
    // Conversions. Bob says int() may be a mistake, especially
    // since it's lack would cause  ``if (Coord(0.75))'' to fail, 
    // instead of giving false.

d134 2
a135 3
    // An alternate version that works in gcc-2.0, 2.1:
    // friend Coord operator+ (const Coord&, const Coord&);

d143 1
a143 2
    // Deprecated?
    // friend char operator !  (const Coord&);
a144 26
    // Cannot seem to get acceptable semantics out of this code.
    // Problem is that r.h.s is evaluated unecessarily in (false && whatever) case.
    // I assume there would be  a similar problem in  (true || whatever).
    // This is true if any of the following code is included:
    //
    //     char operator || ();
    //     char operator && ();
    //     char operator || (const Coord&);
    //     char operator && (const Coord&);
    //
    //     friend char operator || (const Coord&, const Coord&);
    //     friend char operator && (const Coord&, const Coord&);
    //
    //  Below is the only method that works,  but -- it causes float 
    //  Coords to be first cast to int.  (the two arg friend interpret 
    //  the floats correctly, but gets the semanitcs wrong). Sigh.  
    //  Perhaps we should pull out the int() method entirely as Rob suggests.
    //
    //  In hindsight, I think the following only ``works'' by having absolutely
    //  no effect whatsoever.
    //
    // friend char operator || (const Coord&);
    // friend char operator && (const Coord&);

    // Compound assignments.

d158 1
a158 1
    // components
a161 2
    // type promotion

a163 4
    // I/O.  TO DO:: input.
    // Gcc 2.1 cannot overload << (or anything else); use this instead:
    // void output(ostream &o) const;
    
@


1.13
log
@Added && and || as one arg friend functions, which is
only way to preserve special semantics. Added bitwise
compound assignment.  Changed bitwise operators to work
between Coords, except for shift operators which now
use signed ints.
@
text
@d1 2
d7 8
a14 1
// $Log: Coord.h,v $
a141 1
    friend char operator !  (const Coord&);
d143 3
d163 6
a169 3
    friend char operator || (const Coord&);
    friend char operator && (const Coord&);

d172 5
a176 5
    Coord& operator+=  (const Coord&);
    Coord& operator*=  (const Coord&);
    Coord& operator-=  (const Coord&);
    Coord& operator/=  (const Coord&);
    Coord& operator%=  (const Coord&);
d178 2
a179 2
    Coord& operator<<= (int);
    Coord& operator>>= (int);
d181 3
a183 3
    Coord& operator&=  (const Coord&);
    Coord& operator^=  (const Coord&);
    Coord& operator|=  (const Coord&);
a201 4

// Local variables:
// eval: (c++-mode)
// End:
@


1.12
log
@*** empty log message ***
@
text
@d66 2
a67 2
// TO DO:: logical operators &&, ||,  input <<,
// TO DO:: Oh, yeah, bitwise compound assignments.
a93 8
    // Compound assignments.

    Coord& operator+= (const Coord&);
    Coord& operator*= (const Coord&);
    Coord& operator-= (const Coord&);
    Coord& operator/= (const Coord&);
    Coord& operator%= (const Coord&);

d99 3
a101 1
    // Conversions.
d117 6
a122 2
    Coord operator~ () const;
    Coord operator<< (unsigned int) const;   // Unsigned int only allowed here.
a123 5
    Coord operator>> (unsigned int) const;   // Why? Because I *say* so, Allison.
    Coord operator&  (unsigned int) const;
    Coord operator^  (unsigned int) const;
    Coord operator|  (unsigned int) const;

a126 5
    // Gcc 2.1 cannot overload << (or anything else); use this instead:
    // void output(ostream &o) const;
    
    friend ostream& operator<<(ostream&, Coord);

d133 1
a133 1
    friend char operator !  (const Coord&, const Coord&);
d135 36
d178 6
@


1.11
log
@Got overloading to work by simple expedient of using math.ufl.edu
version of g++:  gcc-2.0.  
Changed Coord arithmetic operators to assume result_type()
is taking care of uninitialized Coord types (tag==None) via throw.
Added default: to switches so Rob can rest easy about new 
NumericTypes.  Added *,/,+,%,-.  Lots more to go. Since we now
have NumericType abstraction,  changed stuff like this->tag to
this->type():  because these are inline functions, there should be little 
overhead, but we need to check with some timing tests.
Changed Coord.val name to Coord.value name since I can never remember
these damn c-style abbreviations.   .
@
text
@d5 23
a27 1
// $Log:	Coord.h,v $
d66 2
d82 2
d85 1
a85 1
    Coord(int i) {tag=Integer; value.i = i;}
d88 1
a88 3
    // ~Coord(){}		gratuitous
    // Coord(const Coord&);	gratuitous
    // const Coord &operator=(const Coord&);	gratuitous
d90 19
d112 1
a112 6
    Coord operator+(const Coord&) const;
    Coord operator*(const Coord&) const;
    Coord operator-() const;
    Coord operator-(const Coord&) const;
    Coord operator/(const Coord&) const;
    Coord operator%(const Coord&) const;
d114 18
a131 1
    // an alternate version that also works in gcc-2.0:
d134 4
a137 3
    // this interferes with other operator<<s in gcc-2.1.
    // not checked for gcc-2.0.
    // friend ostream &operator<<(ostream&, Coord);
d139 7
a145 1
    void output(ostream &o) const;
d147 7
a153 1
    NumericType type() const {return tag;}
@


1.10
log
@switched to // comments for rcs log
@
text
@d6 3
d54 3
a56 1
    } val;
d59 3
a61 2
    Coord(int i) {tag=Integer; val.i = i;}
    Coord(float f) {tag=Float; val.f = f;}
d69 6
a74 4
    // neither of these can be used by a program or the 
    // compiler will hang.
    // Coord operator+(const Coord&) const;
    Coord plus(const Coord&) const;
d76 5
a80 1
    // this interferes with other operator<<s
d82 1
@


1.9
log
@add addition operator.  Use of this operator
causes the compiler to hang.
declared some methods const (unmodifying).
@
text
@d4 37
a40 32
/*
 * $Log:	Coord.h,v $
 * Revision 1.8  92/05/21  12:05:23  thoth
 * *** empty log message ***
 * 
 * Revision 1.7  92/05/21  08:07:58  fischer
 * Started rework of CoordType to IA::NumericType
 * so all classes can access.
 * 
 * Revision 1.6  92/05/20  06:29:29  fischer
 * created a scheme to get around thoth's scheme:
 * removed it.
 * 
 * Revision 1.5  92/05/18  15:15:42  thoth
 * created a scheme to get around g++2.1's busted overloading
 * and type conversion.
 * 
 * Revision 1.4  92/05/18  14:22:36  thoth
 * modified conditional surrounding operator int and float.
 * this gives readers a clue as to why they aren't available.
 * 
 * Revision 1.3  92/05/18  11:14:07  thoth
 * minor frobs, added type converter,
 * added tag retrieval method.
 * 
 * Revision 1.2  92/05/16  13:57:59  thoth
 * added log goo
 * 
 * Revision 1.1  92/05/16  13:48:28  thoth
 * Initial revision
 *
 */
@


1.8
log
@*** empty log message ***
@
text
@d6 3
d55 2
a56 2
    operator int(); 
    operator float();
d58 4
a61 1
    //    operator +();
d63 1
a63 2
    // 
    //
d65 1
d67 1
a67 3
    void output(ostream &o);

    NumericType type() {return tag;}
@


1.7
log
@Started rework of CoordType to IA::NumericType
so all classes can access.
@
text
@d6 4
a70 1
// eval: (joe-style)
@


1.6
log
@created a scheme to get around thoth's scheme:
removed it.
@
text
@d6 4
d35 1
a35 1
    CoordType	tag;
d51 3
a53 2
    // Part of Rob's reworking...throughs out the baby as 
    // well as the bathwater - Fischer
a55 2
    // int to_int();
    // float to_float();
d58 2
a59 1
    CoordType type() {return tag;}
@


1.5
log
@created a scheme to get around g++2.1's busted overloading
and type conversion.
@
text
@d6 4
d43 11
a53 7
#if OVERLOADINGWORKS
    operator int() { return this->to_int(); }
    operator float() { return this->to_float(); }
    friend ostream &operator<<(ostream&, Coord);
#else
    int to_int();
    float to_float();
a54 1
#endif
@


1.4
log
@modified conditional surrounding operator int and float.
this gives readers a clue as to why they aren't available.
@
text
@d6 4
d42 2
a43 1
#endif
d46 2
a48 1
    friend ostream &operator<<(ostream&, Coord);
@


1.3
log
@minor frobs, added type converter,
added tag retrieval method.
@
text
@d6 4
d35 1
a35 1
#if 1
@


1.2
log
@added log goo
@
text
@d6 3
d31 4
d37 1
@


1.1
log
@Initial revision
@
text
@d5 3
a7 1
 * $Log$
@
