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

squeue.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 "squeue.hpp"
00017 //#if INTELIB_TEXT_REPRESENTATIONS == 1
00018 //#  include "sstring.hpp"
00019 //#endif
00020 
00021 
00022 
00023 SQueue::SQueue()
00024     : SReference(*PTheEmptyList), last(0)
00025 {}
00026 
00027 SQueue::SQueue(const SReference &ref)
00028 {
00029     if(!ref.GetPtr() || 
00030        !ref->TermType().IsSubtypeOf(SExpressionCons::TypeId)) 
00031     {
00032         throw IntelibX_not_a_list(ref);
00033     }
00034     SReference::operator=(ref.CopyList());
00035     for(last=GetPtr(); 
00036         last && !last->Cdr().IsEmptyList(); 
00037         last=last->Cdr().DynamicCastGetPtr<SExpressionCons>())
00038     {}
00039     if(!last)
00040         throw IntelibX_not_a_list(ref);
00041 }
00042 
00043 void SQueue::InsertFirst(const SReference& item)
00044 {
00045     SExpressionCons *tmp = new SExpressionCons(item, *this);
00046     bool was_empty = IsEmpty();
00047     SReference::operator=(tmp);
00048     if(was_empty)
00049         last = tmp;
00050 }
00051 
00052 void SQueue::Append(const SReference& item)
00053 {
00054     SExpressionCons *tmp = new SExpressionCons(item, *PTheEmptyList);
00055     if(IsEmpty()) {
00056         SReference::operator=(tmp);
00057         last = tmp;
00058     } else {
00059         last->Cdr() = tmp;
00060         last = tmp;
00061     }
00062 }
00063 
00064 bool SQueue::RemoveFirst() 
00065 {
00066     if(IsEmpty()) return false;
00067     SReference::operator=(GetPtr()->Cdr());
00068     if(IsEmpty()) last = 0;
00069     return true;
00070 }

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