/// TKS_Namespace.cpp
/// 
/// (c) 2008-2009 by Bastian Spiegel <bs@tkscript.de> 
///     - distributed under terms of the GNU general public license (GPL). 
/// 
/// 
#include "tks.h" 


TKS_Namespace::TKS_Namespace(void) {
   init();
}

TKS_Namespace::~TKS_Namespace() {
   TKS_Namespace::free();
}

void TKS_Namespace::init(void) {
   class_decl_hash.allocCache(TKS_MAX_CLASSDECLS + 1);

   global_vars.allocCache(TKS_MAX_NAMESPACE_VARIABLES + 1);
}

void TKS_Namespace::free(void) {

   freeVars();

   freeTypes();
}

void TKS_Namespace::freeVars(void) {

   global_vars.freeCache();
}

void TKS_Namespace::freeTypes(void) {

   class_decl_hash.freeCache();
}

TKS_ClassDecl *TKS_Namespace::findClassDecl(YAC_String *_name) const {
   TKS_CachedObject *co = class_decl_hash.findEntry(_name);
   if(NULL != co)
   {
      // Ok, found it
      return (TKS_ClassDecl*) co->value.any;
   }
   // Failed
   return NULL;
}

TKS_FreezedNamespaceArray TKS_Namespace::freeze(void) {
   TKS_FreezedNamespaceArray f = new TKS_Namespace*[2];

   f[0] = this;
   f[1] = NULL;

   return f;
}

TKS_CachedObject *TKS_Namespace::findVar(YAC_String *_name) const {
   return global_vars.findEntry(_name);
}

