//
// Copyright (C) 1991 Texas Instruments Incorporated.
//
// Permission is granted to any individual or institution to use, copy, modify,
// and distribute this software, provided that this complete copyright and
// permission notice is maintained, intact, in all copies and supporting
// documentation.
//
// Texas Instruments Incorporated provides this software "as is" without
// express or implied warranty.
//
// Created: MBN 09/01/89 -- Initial design and implementation
// Updated: LGO 12/04/89 -- Efficiency re-write
// Updated: MJF 03/12/90 -- Added group names to RAISE
// Updated: MJF 07/31/90 -- Added terse print
//
// The  Range class implements non-type specific  common  functionality for the
// parameterized Range<Type>. In this manner, code replication is  reduced. The
// Range<Type> class  supports  arbitrary user-defined ranges  for  a  type  of
// object or built-in data type. This allows other higher level data structures
// such as Vector to be parameterized over a  range of values  for some type so
// that   the  programmer  does  not have  to add  bounds  checking code to the
// application.  A Vector of positive integers, for  example, would be  easy to
// declare, facilitating bounds checking restricted to the code that implements
// the type, not the vector.
//
// The inclusive upper and lower bounds for the range are stored in two private
// static data slots for the class as a  whole.  In addition, a single instance
// private  data slot holds the instance  value. There are  three constructors.
// The first is a simple  empty constructor. The second  is a constructor  that
// also accepts an  initial value. And the third  is a constructor that takes a
// reference to another Range<Type> object and copies the value.
//
// All methods are implemented as  small inline  functions to provide efficient
// encapsulation of objects, including built-in types such as  int. Methods are
// provided to set and get the lower and upper bounds for the  class as a whole
// and set the  value of the  instance data  slot. Assignment of  one object to
// another is supported by the overloaded operator=  methods.  Operator() is an
// inline  method to  return  the value of  the  instance  object.  Finally, an
// implicit conversion from a Range<Type> object to a Type value is provided to
// allow for mixed expressions.
//

#ifndef BASE_RANGEH				// If no Range class
#include <cool/Base_Range.h>				// Include header file
#endif

// set_low_error -- Raise exception for Range::set() constructor
// Input:           Character string indicating type and value
// Output:          None

void Range::set_low_error (const char* type, const char* value) CONST {
  RAISE (Error, SYM(Range), SYM(Under_Lower_Limit),
	 "Range<%s>::set(): Value %s less than lower-limit", type, value);
}


// set_upper_error -- Raise exception for Range::set() constructor
// Input:             Character string indicating type and value
// Output:            None

void Range::set_upper_error (const char* type, const char* value) CONST {
  RAISE (Error, SYM(Range), SYM(Over_Upper_Limit),
	 "Range<%s>::set(): Value %s greater than upper-limit", type, value);
}


// print --  terse print function for Range
// Input:    reference to output stream
// Output:   none

void Range::print(ostream& os) {
  os << form("/* Range %lx */", (long) this);
}
