// ////////////////////////////////////////////////////////
// Copyright (1994) Columbia University
// Department of Biochemistry and Molecular Biophysics
//
// Author: Weider Chang, Ph.D
// ///////////////////////////////////////////////////////

#include "diction.h"
#include "datablk.h"
#include "iterator.h"
#include "llistobj.h"

extern int general_debug;

@implementation WDCDictionary

#include "starutig.m"

- init;
{
  [super initEncoding:@encode(WDCStarDataBlock*) 
         keyEncoding:@encode(WDCString*)];
  return self;
}

- setName:(const char*)aName
{
  return [self setNameString:[[WDCString alloc]
                            initFromCString:(char*)aName]];
}

- setDisplayWindow:window
{
  _displayWindow=window;
  return self;
}

- setGlobalBlock:block
{
  _globalBlock=block;
  return self;
}

- setDictionary:(WDCDictionary*)dictionary
{
  _dictionary=dictionary;
  return self;
}

- (WDCDictionary*)getDictionary
{
  return _dictionary;
}

- getGlobalBlock
{
  return _globalBlock;
}

- getDisplayWindow
{
  return _displayWindow;
}

- (const char*)getName;
{
  return [_name cStringValue];
}

- getNameString;
{
  return _name;
}

- getDefinitionBlockAtKey:(const char*)aName
{
  id temp_id, string=[[WDCString alloc] initFromCString:(char*)aName];
  elt temp;
  BOOL notFound=NO;
  elt err(arglist_t argFrame)
    {
      if (general_debug)
	printf("Dictionary element at key %s not found.\n",aName);
      notFound=YES;
      return 0;
    };
  temp=[self elementAtKey:(WDCString*)string ifAbsentCall:err];
  if (!notFound)
      temp_id=temp.id_u;
  else
      temp_id=0;
  [string free];
  return temp_id;
}

- setNameString: nameString;
{
  if (_name) [_name free];
  _name=nameString;
  return self;
}

- addDataItem: item
{
  return [self insertElement:item atKey:(WDCString*)[item getNameString]];
}


- printForDebugger
{
  int i=0;
  id iter, current_id;
  printf("(%s\n", [self name]);
  printf(" _name:%s\n Contents the following elements:\n",[self getName]);
  printf(" Just the _name Item\n");
  iter=[[WDCListIterator alloc] initFrom:self];
  while ([iter goNext]){
    printf("\n<Dictionary element %d>:\n", ++i);
    printf(" _name is :%s\n",[[iter getCurrentObject] getName]);
    [[[iter getCurrentObject] getDataItem:"_category"] printForDebugger];
  }
  printf(")\n");
  [iter free];
  return self;
} 



@end





