Chapter 8. Units Module

8.1. Requirements

This chapter is $Revision: 1.1 $ $Date: 2003/01/05 00:00:29 $.

8.1.7. Business Object Definition

					
# $RCSfile: units.html,v $ - quantities and units of measure
#                  
# Copyright (C) 2001 Free Software Foundation, Inc.
#
# This file is part of GNU Enterprise.
#
# GNU Enterprise 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 2, or (at your option)
# any later version.
# 
# GNU Enterprise 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 GNU Enterprise; see the file COPYING.  If not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA.
#
# This file originally written by Neil Tiffin (neilt@gnue.org).
#
# $Revision: 1.1 $ $Date: 2003/01/05 00:00:29 $ $Author: psu_gnue $
#

module unit
{
  # -------------------------------------------------------------------------
  # unit - unit of measure
  # -------------------------------------------------------------------------
  class unit
  {                       # keeps track of the different units
    char   code<8>;       #   of measure
    char   descr<35>;      # used in GNUe.
    int16  decimals = 0;  # default decimals for this unit
    
  };
  
  # -------------------------------------------------------------------------
  # quantity - 
  # -------------------------------------------------------------------------
  type quantity
  {                            # this definition allows us to abstract
                               # quantities as needed
                               # for example if value = 456192
    int64       value = 0;     # only integer quantities
    int16       decimals = 2;  # and decimals = 3
                               # then value is really 456.192
    unit::unit  *unit;         # pointer to unit
                               #   for example "kg"
                                 
    float get_float();           # 
    text  get_text();            # for example "456.192 kg"
    void  set_float(float val);  #
  };    

  # -------------------------------------------------------------------------
  # conversion_unit - Storage for all of the conversion factors.  Only used
  # by unit::conversion.  Should never be used directly.
  # -------------------------------------------------------------------------
  class conversion_unit
  {
    unit::quantity  amount;
  };
  
  # -------------------------------------------------------------------------
  # conversion - convert between different units.
  # -------------------------------------------------------------------------
  class conversion
  { 
    unit::conversion_unit  [] units;
    
              # returns t or f if can or cannot do conversion
    char can_convert( text source_unit, text result_unit );
              # returns resulting amount
    text convert( text source_unit, text source_amount, text result_unit);
  };
};