Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

spkghsh.cpp

Go to the documentation of this file.
00001 // +-------------------------------------------------------------------------+
00002 // |               I__n__t__e__L__i__b           0.6.10 development          |
00003 // | Copyright (c) Andrey Vikt. Stolyarov <crocodil_AT_croco.net> 2000-2007. |
00004 // |                                                                         |
00005 // | This is free software. The library part is available under              |
00006 // |                               GNU LESSER GENERAL PUBLIC LICENSE v.2.1.  |
00007 // | GNU LGPL v2.1 is found in docs/gnu_gpl2.txt,  or at  http://www.gnu.org |
00008 // |     Please see also docs/readme.txt and visit http://www.intelib.org    |
00009 // |                                                                         |
00010 // | !!! THERE IS NO WARRANTY OF ANY KIND, NEITHER EXPRESSED NOR IMPLIED !!! |
00011 // +-------------------------------------------------------------------------+
00012 
00013 
00014 
00015 
00016 #include <string.h>
00017 #include <ctype.h>
00018 
00019 #include "../sexpress/shashtbl.hpp"
00020 
00021 #include "spkghsh.hpp"
00022 
00024 // SExpressionHashPackage
00025 
00026 IntelibTypeId
00027 SExpressionHashPackage::TypeId(&SExpressionHashTable::TypeId, false);
00028    // SExpressionHashPackage is declared unchangeable so that it is never 
00029    // Clone()'d but it is still possible to clone expressions which contain
00030    // references to a package
00031 
00032 SExpressionHashPackage::SExpressionHashPackage()
00033     : SExpressionHashTable(TypeId)
00034 {}
00035 
00036 SExpressionHashPackage::SExpressionHashPackage(const SHashPackage& par)
00037     : SExpressionHashTable(TypeId), parent(par)
00038 {}
00039 
00040 SExpressionHashPackage::SExpressionHashPackage(const IntelibTypeId& tid)
00041     : SExpressionHashTable(tid)
00042 {}
00043 
00044 SExpressionHashPackage::SExpressionHashPackage(const IntelibTypeId& tid,
00045                                                const SHashPackage& par)
00046     : SExpressionHashTable(tid), parent(par)
00047 {}
00048 
00049 SExpressionHashPackage::~SExpressionHashPackage()
00050 {}
00051 
00052 bool SExpressionHashPackage::Import(const SReference &ref, 
00053                                     const char *symbname, 
00054                                     bool safe)
00055 {
00056     SExpressionLabel *symb = ref.DynamicCastGetPtr<SExpressionLabel>();
00057     INTELIB_ASSERT(symb, IntelibX_not_a_label(ref));
00058 
00059     const char *name = symbname ? symbname : symb->GetName();
00060 
00061     if(safe) {
00062         return SafeAddItem(name, ref);
00063     } else {
00064         AddItem(name, ref);
00065         return true;
00066     }
00067 }
00068 
00069 SReference SExpressionHashPackage::Intern(const char *name)
00070 {
00071     SReference ret = FindSymbol(name);
00072     if(ret.GetPtr() == EmptySlotMark.GetPtr()) {
00073         // Now we create a new symbol
00074         ret = CreateNewSymbolObject(name); 
00075         AddItem(name, ret);
00076     }
00077     return ret;
00078 } 
00079 
00080 SReference SExpressionHashPackage::FindSymbol(const char *name)
00081 {
00082     SReference tmp = FindItem(name);
00083     if(tmp.GetPtr() == EmptySlotMark.GetPtr() && parent.GetPtr()) {
00084         return parent->FindSymbol(name);
00085     } else {
00086         return tmp;
00087     }
00088 }
00089 
00090 #if 0
00091 SReference SExpressionHashPackage::GetAllSymbols() const
00092 {
00093     SReference res(*PTheEmptyList);
00094     Iterator it(*this);
00095     SReference r = it.GetNext();
00096     while(r.GetPtr()) {
00097         res = SReference(r.Cdr(), res);
00098         r = it.GetNext();
00099     }
00100 }
00101 #endif
00102 
00103 SReference SExpressionHashPackage::MakeSymbol(const char *name)
00104 {
00105     return Intern(name);
00106 }
00107 
00108 SString SExpressionHashPackage::TextRepresentation() const
00109 {
00110     return SString("#<PACKAGE>");
00111 }
00112 
00113 
00114 SReference SExpressionHashPackage::CreateNewSymbolObject(const char *nm) const
00115 {
00116     return SReference(new SExpressionLabel(nm)); 
00117 }
00118 
00120 // exceptions
00121 
00122 IntelibX_not_a_package::
00123 IntelibX_not_a_package(SReference a_param) 
00124     : IntelibX("Not a package", a_param) {}
00125 
00126 IntelibX_package_conflict::
00127 IntelibX_package_conflict(SReference a_param) 
00128     : IntelibX("Name conflict within a package", a_param) {}

Generated on Tue Dec 18 00:39:45 2007 for InteLib by  doxygen 1.4.1