(***********************************************************************)
(*                                                                     *)
(*                                 GALAX                               *)
(*                            XML Query Engine                         *)
(*                                                                     *)
(*  Copyright 2000, Lucent Technologies.                               *)
(*  Distributed only by permission.                                    *)
(*                                                                     *)
(***********************************************************************)

(* $Id: datatypes.mli,v 1.5 2003/06/09 15:28:26 simeon Exp $ *)

open Decimal
open AnyURI
open DateTime


(* This module provides support for atomic values and atomic types. *)

(*****************)
(* Atomic values *)
(*****************)

(* Note:
     Each of the following Caml types implements the *value space* of
     one the 19 XML Schema primitive atomic types.
   - Jerome
 *)

type xs_string       = string
type xs_boolean      = bool
type xs_decimal      = Decimal._decimal
type xs_float        = float
type xs_double       = float
type xs_duration     = string
type xs_dateTime     = DateTime._dateTime
type xs_time         = string
type xs_date         = string
type xs_gYearMonth   = string
type xs_gYear        = string
type xs_gMonthDay    = string
type xs_gDay         = string
type xs_gMonth       = string
type xs_hexBinary    = string
type xs_base64Binary = string
type xs_anyURI       = _uri            (* Defined in the AnyUri module *)
type xs_QName        = Sym.anon_symbol (* This is an anonymous QName - e.g, used as a data model value *)
type xs_NOTATION     = string

type xs_integer      = Decimal._integer
type xs_int          = Decimal._int

type xdt_untyped = string
type xdt_yearMonthDuration = string
type xdt_dayTimeDuration = string


(*****************)
(* Atomic values *)
(*****************)

type _AtomicValue =
  | AtomicString of xs_string
  | AtomicBoolean of xs_boolean
  | AtomicDecimal of xs_decimal
  | AtomicFloat of xs_float
  | AtomicDouble of xs_double
  | AtomicDuration of xs_duration
  | AtomicDateTime of xs_dateTime
  | AtomicTime of xs_time
  | AtomicDate of xs_date
  | AtomicGYearMonth of xs_gYearMonth
  | AtomicGYear of xs_gYear
  | AtomicGMonthDay of xs_gMonthDay
  | AtomicGDay of xs_gDay
  | AtomicGMonth of xs_gMonth
  | AtomicHexBinary of xs_hexBinary
  | AtomicBase64Binary of xs_base64Binary
  | AtomicAnyURI of xs_anyURI
  | AtomicQName of xs_QName
  | AtomicNOTATION of xs_NOTATION

      (* Values of derived built-in atomic types *) 
  | AtomicInteger of xs_integer
  | AtomicInt of xs_int

      (* Atomic types in xdt namespace *) 
  | AtomicYearMonthDuration of xdt_yearMonthDuration
  | AtomicDayTimeDuration of xdt_dayTimeDuration
  | AtomicUntyped of xdt_untyped

type _AtomicValueKind =
  | AtomicStringKind
  | AtomicBooleanKind
  | AtomicDecimalKind
  | AtomicFloatKind
  | AtomicDoubleKind
  | AtomicDurationKind
  | AtomicDateTimeKind
  | AtomicTimeKind
  | AtomicDateKind
  | AtomicGYearMonthKind
  | AtomicGYearKind
  | AtomicGMonthDayKind
  | AtomicGDayKind
  | AtomicGMonthKind
  | AtomicHexBinaryKind
  | AtomicBase64BinaryKind
  | AtomicAnyURIKind
  | AtomicQNameKind
  | AtomicNOTATIONKind
  | AtomicIntegerKind
  | AtomicIntKind
  | AtomicUntypedKind
  | AtomicYearMonthDurationKind
  | AtomicDayTimeDurationKind


(*****************)
(* Simple values *)
(*****************)

type _SimpleValue = _AtomicValue list


(**************************************)
(* Caml specific operations on values *)
(**************************************)

(* Note:
     The following functions are not part of the data model but are
     useful to manipulate the Caml representations of values.
   - Jerome
 *)

val erase_atomic_value   : _AtomicValue -> xdt_untyped
    (* Turns an atomic value back into its text representation *)

val erase_simple_value   : _AtomicValue list -> xdt_untyped
    (* Turns a simple value back into its text representation *)

(* Casts from specific value types to a generic value *)

val buildAtomicString       : xs_string            -> _AtomicValue
val buildAtomicBoolean      : xs_boolean           -> _AtomicValue
val buildAtomicDecimal      : xs_decimal           -> _AtomicValue
val buildAtomicFloat        : xs_float             -> _AtomicValue
val buildAtomicDouble       : xs_double            -> _AtomicValue
val buildAtomicDuration     : xs_duration          -> _AtomicValue
val buildAtomicDateTime     : xs_dateTime          -> _AtomicValue
val buildAtomicTime         : xs_time              -> _AtomicValue
val buildAtomicDate         : xs_date              -> _AtomicValue
val buildAtomicGYearMonth   : xs_gYearMonth        -> _AtomicValue
val buildAtomicGYear        : xs_gYear             -> _AtomicValue
val buildAtomicGMonthDay    : xs_gMonthDay         -> _AtomicValue
val buildAtomicGDay         : xs_gDay              -> _AtomicValue
val buildAtomicGMonth       : xs_gMonth            -> _AtomicValue
val buildAtomicHexBinary    : xs_hexBinary         -> _AtomicValue
val buildAtomicBase64Binary : xs_base64Binary      -> _AtomicValue
val buildAtomicAnyURI       : xs_anyURI            -> _AtomicValue
val buildAtomicQName        : xs_QName             -> _AtomicValue
val buildAtomicNOTATION     : xs_NOTATION          -> _AtomicValue
val buildAtomicInteger      : xs_integer           -> _AtomicValue
val buildAtomicInt          : xs_int               -> _AtomicValue
val buildAtomicUntyped      : xdt_untyped           -> _AtomicValue

(* Casts from generic value to a specific value type *)

val getAtomicString       : _AtomicValue -> xs_string
val getAtomicBoolean      : _AtomicValue -> xs_boolean
val getAtomicDecimal      : _AtomicValue -> xs_decimal
val getAtomicFloat        : _AtomicValue -> xs_float
val getAtomicDouble       : _AtomicValue -> xs_double
val getAtomicDuration     : _AtomicValue -> xs_duration
val getAtomicDateTime     : _AtomicValue -> xs_dateTime
val getAtomicTime         : _AtomicValue -> xs_time
val getAtomicDate         : _AtomicValue -> xs_date
val getAtomicGYearMonth   : _AtomicValue -> xs_gYearMonth
val getAtomicGYear        : _AtomicValue -> xs_gYear
val getAtomicGMonthDay    : _AtomicValue -> xs_gMonthDay
val getAtomicGDay         : _AtomicValue -> xs_gDay
val getAtomicGMonth       : _AtomicValue -> xs_gMonth
val getAtomicHexBinary    : _AtomicValue -> xs_hexBinary
val getAtomicBase64Binary : _AtomicValue -> xs_base64Binary
val getAtomicAnyURI       : _AtomicValue -> xs_anyURI
val getAtomicQName        : _AtomicValue -> xs_QName
val getAtomicNOTATION     : _AtomicValue -> xs_NOTATION
val getAtomicInteger      : _AtomicValue -> xs_integer
val getAtomicInt          : _AtomicValue -> xs_int
val getAtomicUntyped : _AtomicValue -> xdt_untyped

(* Returns the kindness of a value *)

val getAtomicValueKind : _AtomicValue -> _AtomicValueKind

(************************)
(* Operations on values *)
(************************)

(* Generic operations on values *)

val atomic_value_eq   : _AtomicValue -> _AtomicValue -> bool
val atomic_value_neq  : _AtomicValue -> _AtomicValue -> bool

val atomic_value_lteq : _AtomicValue -> _AtomicValue -> bool
val atomic_value_lt   : _AtomicValue -> _AtomicValue -> bool
val atomic_value_gteq : _AtomicValue -> _AtomicValue -> bool
val atomic_value_gt   : _AtomicValue -> _AtomicValue -> bool

val atomic_value_compare : _AtomicValue -> _AtomicValue -> int

(* Operations on QNames *)

val localname  : xs_QName -> Namespace.ncname
val namespace  : xs_QName -> Namespace.uri

(*******************************)
(* Parsing from text to values *)
(*******************************)

val string_of_untyped       : xdt_untyped -> xs_string
val boolean_of_untyped      : xdt_untyped -> xs_boolean
val decimal_of_untyped      : xdt_untyped -> xs_decimal
val float_of_untyped        : xdt_untyped -> xs_float
val double_of_untyped       : xdt_untyped -> xs_double
val duration_of_untyped     : xdt_untyped -> xs_duration
val dateTime_of_untyped     : xdt_untyped -> xs_dateTime
val time_of_untyped         : xdt_untyped -> xs_time
val date_of_untyped         : xdt_untyped -> xs_date
val gYearMonth_of_untyped   : xdt_untyped -> xs_gYearMonth
val gYear_of_untyped        : xdt_untyped -> xs_gYear
val gMonthDay_of_untyped    : xdt_untyped -> xs_gMonthDay
val gDay_of_untyped         : xdt_untyped -> xs_gDay
val gMonth_of_untyped       : xdt_untyped -> xs_gMonth
val hexBinary_of_untyped    : xdt_untyped -> xs_hexBinary
val base64Binary_of_untyped : xdt_untyped -> xs_base64Binary
val anyURI_of_untyped       : xdt_untyped -> xs_anyURI
val qname_of_untyped        : Namespace.nsenv -> xdt_untyped -> xs_QName
val notation_of_untyped     : xdt_untyped -> xs_NOTATION
val integer_of_untyped      : xdt_untyped -> xs_integer
val int_of_untyped          : xdt_untyped -> xs_int
val yearMonthDuration_of_untyped   : xdt_untyped -> xdt_yearMonthDuration
val dayTimeDuration_of_untyped     : xdt_untyped -> xdt_dayTimeDuration


(****************************)
(* Support for atomic types *)
(****************************)

type atomic_type =
      (* 19 primitive XML Schema atomic types *)
  | ATString
  | ATBoolean
  | ATDecimal
  | ATFloat
  | ATDouble
  | ATDuration
  | ATDateTime
  | ATTime
  | ATDate
  | ATGYearMonth
  | ATGYear
  | ATGMonthDay
  | ATGDay
  | ATGMonth
  | ATHexBinary
  | ATBase64Binary
  | ATAnyURI
  | ATQName
  | ATNOTATION

      (* Derived atomic types *)
  | ATInteger
  | ATInt

      (* xdt data types *)
  | ATYearMonthDuration
  | ATDayTimeDuration
  | ATUntyped

type _Def_T =
  | SimpleType of atomic_type
  | ComplexType of Sym.rgroup_symbol

(* Operations on atomic types *)

val atomic_type_subsumes : atomic_type -> atomic_type -> bool

val atomic_type_of_atomic_value : _AtomicValue -> atomic_type
val untyped_atomic_type : atomic_type

val lookup_bltin_type : Namespace.uqname -> atomic_type

val uqname_of_primitive_type : atomic_type -> Namespace.uqname

val unit_symbol_of_base_type : atomic_type -> Sym.simple_symbol

val can_be_promoted_to : atomic_type -> atomic_type list

val string_equal       : xs_string -> xs_string -> bool
val string_lteq        : xs_string -> xs_string -> bool
val string_lt          : xs_string -> xs_string -> bool
val string_gteq        : xs_string -> xs_string -> bool
val string_gt          : xs_string -> xs_string -> bool

val bool_equal         : xs_boolean    	 -> xs_boolean 	    -> bool
val float_equal        : xs_float      	 -> xs_float   	    -> bool
val double_equal       : xs_double     	 -> xs_double  	    -> bool
val duration_equal     : xs_duration   	 -> xs_duration     -> bool
val dateTime_equal     : xs_dateTime   	 -> xs_dateTime     -> bool
val time_equal         : xs_time       	 -> xs_time 	    -> bool
val date_equal         : xs_date       	 -> xs_date 	    -> bool
val gYearMonth_equal   : xs_gYearMonth 	 -> xs_gYearMonth   -> bool
val gYear_equal        : xs_gYear      	 -> xs_gYear        -> bool
val gMonthDay_equal    : xs_gMonthDay    -> xs_gMonthDay    -> bool
val gMonth_equal       : xs_gMonth       -> xs_gMonth       -> bool
val hexBinary_equal    : xs_hexBinary    -> xs_hexBinary    -> bool
val base64Binary_equal : xs_base64Binary -> xs_base64Binary -> bool
val anyURI_equal       : xs_anyURI   	 -> xs_anyURI 	    -> bool
val qname_equal        : xs_QName    	 -> xs_QName  	    -> bool
val notation_equal     : xs_NOTATION 	 -> xs_NOTATION     -> bool

