// file: $isip/doc/examples/class/mmedia/mmedia_example_07/example.cc
//

// isip include files
//
#include <Identifier.h>
#include <Console.h>

// this example demonstrates how to use the Identifier object
//
int main(int argc, const char** argv) {

  // declare Identifier objects
  //
  String database(L"Timit");
  String anchor(L"Anchor");
  String annotation(L"Annotation");  
  Identifier ident_00(database, anchor);
  Identifier ident_01(database, annotation);

  // register id's via the identifiers
  //
  if (!ident_00.registerId().eq(L"Timit:Anchor1")) {
    Console::put(L"invalid identifier\n");
  }
  if (!ident_01.registerId().eq(L"Timit:Annotation1")) {
    Console::put(L"invalid identifier\n");
  }

  if (!ident_00.registerId().eq(L"Timit:Anchor2")) {
    Console::put(L"invalid identifier\n");
  }
  if (!ident_01.registerId().eq(L"Timit:Annotation2")) {
    Console::put(L"invalid identifier\n");
  }

  if (!ident_00.registerId(L"Timit:Anchor3").eq(L"Timit:Anchor3")) {
    Console::put(L"invalid identifier\n");
  }
  if (!ident_01.registerId(L"Timit:Annotation3").eq(L"Timit:Annotation3")) {
    Console::put(L"invalid identifier\n");
  }

  if (!ident_00.registerId(L"Timit:Anchor3").eq(L"Timit:Anchor4")) {
    Console::put(L"invalid identifier\n");
  }
  if (!ident_01.registerId(L"Timit:Annotation3").eq(L"Timit:Annotation4")) {
    Console::put(L"invalid identifier\n");
  }        

  // verify that the identifiers exists
  //
  if (!ident_00.existsId(L"Timit:Anchor1")) {
    Console::put(L"invalid identifier\n");
  }
  if (!ident_01.existsId(L"Timit:Annotation1")) {
    Console::put(L"invalid identifier\n");
  }

  if (ident_00.existsId(L"Timit:Anchor8")) {
    Console::put(L"invalid identifier\n");
  }
  if (ident_01.existsId(L"Timit:Annotation8")) {
    Console::put(L"invalid identifier\n");
  }    

  // reclaim the identifiers
  //
  if (!ident_00.reclaimId(L"Timit:Anchor1")) {
    Console::put(L"invalid identifier\n");
  }
  if (!ident_01.reclaimId(L"Timit:Annotation1")) {
    Console::put(L"invalid identifier\n");
  }

  if (ident_00.existsId(L"Timit:Anchor1")) {
    Console::put(L"invalid identifier\n");
  }
  if (ident_01.existsId(L"Timit:Annotation1")) {
    Console::put(L"invalid identifier\n");
  }  

  // verify the namespace via the identifiers
  //
  if (!ident_00.getNamespace(L"Timit:Anchor1").eq(L"Timit")) {
    Console::put(L"invalid identifier\n");
  }
  if (!ident_00.getNamespace(L"Anchor1").eq(String::EMPTY)) {
    Console::put(L"invalid identifier\n");
  }  

  // get/set/delete/exists annotations via the identifiers
  //
  Annotation anno_00;
  Annotation anno_01;

  ident_00.addAnnotationRef(L"Timit:Annotation1", &anno_00);
  ident_01.addAnnotationRef(L"Timit:Annotation2", &anno_01);

  if (ident_00.getAnnotationRef(L"Timit:Annotation1") != &anno_00) {
    Console::put(L"invalid identifier\n");
  }
  if (ident_01.getAnnotationRef(L"Timit:Annotation2") != &anno_01) {
    Console::put(L"invalid identifier\n");
  }  

  if (!ident_01.existsAnnotation(L"Timit:Annotation2")) {
    Console::put(L"invalid identifier\n");
  }
  if (ident_01.existsAnnotation(L"Timit:Annotation6")) {
    Console::put(L"invalid identifier\n");
  }  

  ident_01.deleteAnnotationRef(L"Timit:Annotation2");
  if (ident_01.existsAnnotation(L"Timit:Annotation2")) {
    Console::put(L"invalid identifier\n");
  }
  if (ident_01.getAnnotationRef(L"Timit:Annotation2") != (Annotation*)NULL) {
    Console::put(L"invalid identifier\n");
  }

  // get/set/delete/exists anchors via the identifiers
  //
  Anchor ancr_00;
  Anchor ancr_01;

  ident_00.addAnchorRef(L"Timit:Anchor1", &ancr_00);
  ident_01.addAnchorRef(L"Timit:Anchor2", &ancr_01);

  if (ident_00.getAnchorRef(L"Timit:Anchor1") != &ancr_00) {
    Console::put(L"invalid identifier\n");
  }
  if (ident_01.getAnchorRef(L"Timit:Anchor2") != &ancr_01) {
    Console::put(L"invalid identifier\n");
  }  

  if (!ident_01.existsAnchor(L"Timit:Anchor2")) {
    Console::put(L"invalid identifier\n");
  }
  if (ident_01.existsAnchor(L"Timit:Anchor6")) {
    Console::put(L"invalid identifier\n");
  }  

  ident_01.deleteAnchorRef(L"Timit:Anchor2");
  if (ident_01.existsAnchor(L"Timit:Anchor2")) {
    Console::put(L"invalid identifier\n");
  }
  if (ident_01.getAnchorRef(L"Timit:Anchor2") != (Anchor*)NULL) {
    Console::put(L"invalid identifier\n");
  }  

  // exit gracefully
  //
  Integral::exit();
}
