.packageName <- "Ruuid"
#Copyright R. Gentleman, 2003, All rights reserved

getuuid <- function(cur)
{
    if (missing(cur))
        x <- .Call("Ruuid_getuuid", PACKAGE="Ruuid")
    else if (is(cur,"uuidt")) {
        y <- .Call("Ruuid_uuid2str", cur, PACKAGE="Ruuid")
        x <- new("Ruuid",stringRep=y, uuid=cur)
    }
    else if (is.character(cur)) {
        y <- .Call("Ruuid_str2uuid", cur, PACKAGE="Ruuid")
        x <- new("Ruuid",stringRep=cur,uuid=y)
    }
    else {
        stop("Incorrect parameter type")
    }
    x
}

.initRuuidMethods <- function(where) {
    setMethod("print", "Ruuid", function(x)
              print(x@stringRep),where=where)

    setMethod("as.character", "Ruuid", function(x) x@stringRep, where=where)


    setMethod("==", signature("Ruuid", "Ruuid"),
              function(e1, e2) as.character(e1) == as.character(e2),
              where=where)

    setMethod("!=", signature("Ruuid", "Ruuid"),
              function(e1, e2) as.character(e1) != as.character(e2),
              where=where)

    setMethod("print", "uuidt", function(x) {
        z <- .Call("Ruuid_printuuid", x, PACKAGE="Ruuid")
        print(z)
    }, where=where)
}

setClass("uuidt", representation(uuid="character"))

setClass("Ruuid", representation(stringRep="character",
                                 uuid="uuidt"))


if (is.null(getGeneric("uuid")))
    setGeneric("uuid", function(object)
               standardGeneric("uuid"))

setMethod("uuid", "Ruuid", function(object)
          object@uuid)

## uuid_t class
setGeneric("uuidt", function(object)
           standardGeneric("uuidt"))

setMethod("uuid", "uuidt", function(object)
          object@uuid)
.First.lib <-
function(libname, pkgname,where)
{
    if (missing(where)) {
        where <- match(paste("package:", pkgname, sep=""), search())
        if(is.na(where)) {
            warning(paste("Not a package name: ",pkgname))
            return()
        }
        where <- pos.to.env(where)
    }

    library.dynam("Ruuid", pkgname, libname)
    .initRuuidMethods(where)
    if((.Platform$OS.type == "windows") && ("Biobase" %in% installed.packages()[,"Package"])
       && (interactive()) && (.Platform$GUI ==  "Rgui")){
        if (require("Biobase"))
            addVigs2WinMenu("Ruuid")
    }
}

