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

#include "datablk.h"
#include "iterator.h"
#include "llistobj.h"
#include "wstring.h"
#include "diction.h"
#include "idxcoltn.h"
@implementation WDCStarDataBlock

#include "starutig.m"

- (int)compare:anObject
{
  return [[self getNameString] compareCString:[anObject getName]
	  ignoreCase :YES];
}

- (const char *)getDataBlockName;
{
  return [self getName];
}

- getGlobalBlock
{
  return _globalBlock;
}

- getDataItem: (const char *)itemname;
{
  return [[self getValue] getItemNamed:itemname];
}

- getAllDataItems: (const char *)itemname;
{
  return [[self getValue] getAllItemsNamed:itemname];
}

- setDataBlockName: (const char *)blockname;
{
  return [self setName: blockname];
}

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

- addDataItem: dataitem;
{
  id item;
  if (item=[self getValue])
    {
      // printf("addStarAssocValue\n");
      if ([item isKindOfClassNamed:"WDCStarItemAssocValue"])
	[item addStarAssocValue: dataitem];
      else
	{
	  printf("Value is of type %s \n", [item name]);
	  [self error: "Non-StarItemAssocValue item in data block."];
	}
    }
  else
    {
      // printf("setValue\n");
      if ([dataitem isKindOfClassNamed:"WDCStarItemAssocValue"])
	[self setValue: dataitem];
      else
	[self error:"Attempt to add Non-StarItemAssocValue to data block"];
    }
  return self;
}

- setDictionary: dictionary
{
  if ([dictionary isMemberOfClassNamed:"WDCDictionary"])
    _dictionary=dictionary;
  else
    [self error:"attempt to assign non-dictionary object to dictionary"];
  return self;
}

- getDictionary
{
  return _dictionary;
}

- makeItemDefinitionLink
{
  id iter, currentid, dictionary;
  if (dictionary=[self getDictionary])
    {
      iter=[[WDCListIterator alloc] initFrom:[self getValue]];
      while ([iter goNext])
	{
	  currentid=[iter getCurrentObject];
	  if ([currentid respondsTo : @selector(makeItemDefinitionLinkWith:)]) 
	    [currentid makeItemDefinitionLinkWith:dictionary];
	}
      [iter free];
    }
  return self;
}

- (BOOL)isSaveFrame
{
  return strncmp("save_", [self getName], 5)?NO:YES;
}

- printForDebugger
{
  // id temp;
  printf("(%s\n", [self name]);
  printf(" _name:");
  [_name printForDebugger];
  printf(" _item:");
  [_item printForDebugger];
  printf("\n");
  printf(" _globalBlock:%s\n", [[self getGlobalBlock] getName]); 
  printf("has element of:\n");
  [_value printForDebugger];
}

@end

/*  
@implementation WDCLineBuffer

- (WDCLineBuffer*)getNext;
{
  return _next;
}

- setNext:(WDCLineBuffer*)obj;
{
  _next=obj;
  return self;
}

- add:(WDCLineBuffer*)obj;
{
  if (!_next) [self setNext:obj];
  else [_next add: obj];
  return self;
}

- addString:(char *)str;
{
  return [self add: [[WDCLineBuffer alloc] initFromCString: str]];
}

@end

*/




