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

(* $Id: simple.mli,v 1.11 2002/10/15 15:15:38 simeon Exp $ *)

open Decimal
open Uri

(********************)
(* Support XML Text *)
(********************)

(* Text value *)

(* Note:
     The type for text in the data model is unclear. Right now, we
     treat it as a completely separate type called _text. It is open
     whether _text and _string are two different types.
   - Jerome
 *)

type _text = string

(****************************)
(* Simple for simple values *)
(****************************)

(* All the simple XML Schema values *)

(* Note:
     Each of these types corresponds to one of the 14 XML Schema base
     datatypes.
   - Jerome
 *)

type _ncName    = Namespace.ncname   (* This is a local name - e.g., used in namespace functions *)

type _string = string
type _boolean = bool
type _float = float
type _double = float
type _duration = string
type _dateTime = Datetime._dateTime
type _time = string
type _date = string
type _gYearMonth = string
type _gYear = string
type _gMonthDay = string
type _gDay = string
type _gMonth = string
type _hexBinary = string
type _base64Binary = string
type _anyURI = _uri
type _QName = Sym.anon_symbol    (* This is an anonymous QName - e.g, used as a data model value *)
type _NOTATION = string

(* Generic value type *)

type _DataValue =
      (* Values of built-in simple types *)
  | DataString of _string
  | DataBoolean of _boolean
  | DataDecimal of _decimal
  | DataFloat of _float
  | DataDouble of _double
  | DataDuration of _duration
  | DataDateTime of _dateTime
  | DataTime of _time
  | DataDate of _date
  | DataGYearMonth of _gYearMonth
  | DataGYear of _gYear
  | DataGMonthDay of _gMonthDay
  | DataGDay of _gDay
  | DataGMonth of _gMonth
  | DataHexBinary of _hexBinary
  | DataBase64Binary of _base64Binary
  | DataAnyURI of _anyURI
  | DataQName of _QName
  | DataNOTATION of _NOTATION
      (* Values of derived built-in simple types *) 
  | DataInteger of _integer
  | DataInt of _int
  | DataUnknownSimple of _text

type _DataValueKind =
  | DataStringKind
  | DataBooleanKind
  | DataDecimalKind
  | DataFloatKind
  | DataDoubleKind
  | DataDurationKind
  | DataDateTimeKind
  | DataTimeKind
  | DataDateKind
  | DataGYearMonthKind
  | DataGYearKind
  | DataGMonthDayKind
  | DataGDayKind
  | DataGMonthKind
  | DataHexBinaryKind
  | DataBase64BinaryKind
  | DataAnyURIKind
  | DataQNameKind
  | DataNOTATIONKind
  | DataIntegerKind
  | DataIntKind
  | DataUnknownSimpleKind


(**************************************)
(* 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 serialize_value   : _DataValue -> _text
    (* Serializes a value *)

val erase_value       : _DataValue list -> _text

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

val buildDataString       : _string            -> _DataValue
val buildDataBoolean      : _boolean           -> _DataValue
val buildDataDecimal      : _decimal           -> _DataValue
val buildDataFloat        : _float             -> _DataValue
val buildDataDouble       : _double            -> _DataValue
val buildDataDuration     : _duration          -> _DataValue
val buildDataDateTime     : _dateTime          -> _DataValue
val buildDataTime         : _time              -> _DataValue
val buildDataDate         : _date              -> _DataValue
val buildDataGYearMonth   : _gYearMonth        -> _DataValue
val buildDataGYear        : _gYear             -> _DataValue
val buildDataGMonthDay    : _gMonthDay         -> _DataValue
val buildDataGDay         : _gDay              -> _DataValue
val buildDataGMonth       : _gMonth            -> _DataValue
val buildDataHexBinary    : _hexBinary         -> _DataValue
val buildDataBase64Binary : _base64Binary      -> _DataValue
val buildDataAnyURI       : _anyURI            -> _DataValue
val buildDataQName        : _QName             -> _DataValue
val buildDataNOTATION     : _NOTATION          -> _DataValue
val buildDataInteger      : _integer           -> _DataValue
val buildDataInt          : _int               -> _DataValue
val buildDataUnknownSimple  : _text            -> _DataValue

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

val getDataString       : _DataValue -> _string
val getDataBoolean      : _DataValue -> _boolean
val getDataDecimal      : _DataValue -> _decimal
val getDataFloat        : _DataValue -> _float
val getDataDouble       : _DataValue -> _double
val getDataDuration     : _DataValue -> _duration
val getDataDateTime     : _DataValue -> _dateTime
val getDataTime         : _DataValue -> _time
val getDataDate         : _DataValue -> _date
val getDataGYearMonth   : _DataValue -> _gYearMonth
val getDataGYear        : _DataValue -> _gYear
val getDataGMonthDay    : _DataValue -> _gMonthDay
val getDataGDay         : _DataValue -> _gDay
val getDataGMonth       : _DataValue -> _gMonth
val getDataHexBinary    : _DataValue -> _hexBinary
val getDataBase64Binary : _DataValue -> _base64Binary
val getDataAnyURI       : _DataValue -> _anyURI
val getDataQName        : _DataValue -> _QName
val getDataNOTATION     : _DataValue -> _NOTATION
val getDataInteger      : _DataValue -> _integer
val getDataInt          : _DataValue -> _int
val getDataUnknownSimple : _DataValue -> _text

(* Returns the kindness of a value *)

val getValueKind : _DataValue -> _DataValueKind

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

(* Generic operations on values *)

val value_eq   : _DataValue -> _DataValue -> bool
val value_neq  : _DataValue -> _DataValue -> bool

val value_lteq : _DataValue -> _DataValue -> bool
val value_lt   : _DataValue -> _DataValue -> bool
val value_gteq : _DataValue -> _DataValue -> bool
val value_gt   : _DataValue -> _DataValue -> bool

val value_compare : _DataValue -> _DataValue -> int

(* Operations on QNames *)

val localname  : _QName -> _ncName
val namespace  : _QName -> Namespace.uri

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

val string_of_text       : _text -> _string
val boolean_of_text      : _text -> _boolean
val decimal_of_text      : _text -> _decimal
val float_of_text        : _text -> _float
val double_of_text       : _text -> _double
val duration_of_text     : _text -> _duration
val dateTime_of_text     : _text -> _dateTime
val time_of_text         : _text -> _time
val date_of_text         : _text -> _date
val gYearMonth_of_text   : _text -> _gYearMonth
val gYear_of_text        : _text -> _gYear
val gMonthDay_of_text    : _text -> _gMonthDay
val gDay_of_text         : _text -> _gDay
val gMonth_of_text       : _text -> _gMonth
val hexBinary_of_text    : _text -> _hexBinary
val base64Binary_of_text : _text -> _base64Binary
val anyURI_of_text       : _text -> _anyURI
val qname_of_text        : Namespace.nsenv -> _text -> _QName
val notation_of_text     : _text -> _NOTATION
val integer_of_text      : _text -> _integer
val int_of_text          : _text -> _int

(****************************)
(* Support for simple types *)
(****************************)

(* All the simple XML Schema types *)

type simple_type =
      (* Primitive simple types *)
  | STString
  | STBoolean
  | STDecimal
  | STFloat
  | STDouble
  | STDuration
  | STDateTime
  | STTime
  | STDate
  | STGYearMonth
  | STGYear
  | STGMonthDay
  | STGDay
  | STGMonth
  | STHexBinary
  | STBase64Binary
  | STAnyURI
  | STQName
  | STNOTATION
      (* Derived simple types *)
  | STInteger
  | STInt
      (* UnknownSimpleType *)
  | STUnknownSimpleType

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

(* Operations on simple types *)

val simple_type_subsumes : simple_type -> simple_type -> bool

val simple_type_of_simple_value : _DataValue -> simple_type
val unknown_simple_type : simple_type

val lookup_bltin_type : Namespace.uqname -> simple_type

val uqname_of_primitive_type : simple_type -> Namespace.uqname

val unit_symbol_of_base_type : simple_type -> Sym.simple_symbol


