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

list.h

00001 /*****************************************************************************
00002  * list.h
00003  * Last Change: 2003-12-27
00004  * Copyright (c) 2003 Sebastian "randomZ" Beschke
00005  ****************
00006  * This file is part of the libsofu project, a parser library for an all-purpose
00007  * ASCII file format. More information can be found on the project web site
00008  * at http://sofu.sourceforge.net/ .
00009  *
00010  * libsofu is published under the terms of the MIT license, which basically means
00011  * "Do with it whatever you want". For more information, see the license.txt
00012  * file that should be enclosed with libsofu distributions. A copy of the license
00013  * is (at the time of this writing) also available at
00014  * http://www.opensource.org/licenses/mit-license.php .
00015  *****************************************************************************/
00016 
00017 #ifndef INC_SOFU_LIST_H
00018 #define INC_SOFU_LIST_H
00019 
00020 #include "main.h"
00021 #include "object.h"
00022 
00023 namespace Sofu
00024 {
00025     class Value;
00026     class Composite;
00027 
00028     class List : public Object
00029     {
00030         private:
00031             vector<Object*> elems;
00032         public:
00033             List(void);
00034             List(const List& cpy);
00035             ~List(void);
00036 
00037             class iterator;
00038 
00039             iterator begin(void);
00040             iterator end(void);
00041         
00042             unsigned int size(void);
00043             Object*& at(int pos);
00044             Value* value(int pos);
00045             List* list(int pos);
00046             Composite* composite(int pos);
00047             
00048             void push_back(Object* obj);            
00049             
00050             class iterator
00051             {
00052                 private:
00053                     friend class List;
00054                     vector<Object*>::iterator itor;
00055                     iterator(vector<Object*>::iterator iitor);
00056                 public:
00057                     iterator(void);
00058                     ~iterator(void);
00059                     
00060                     iterator& operator=(iterator& rhs);
00061                     
00062                     bool operator==(const iterator& rhs) const;
00063                     bool operator!=(const iterator& rhs) const;
00064                     
00065                     iterator operator+(int steps) const;
00066                     iterator operator-(int steps) const;
00067                     iterator& operator+=(int steps);
00068                     iterator& operator-=(int steps);
00069                     iterator& operator++(void);
00070                     iterator& operator--(void);
00071                     
00072                     Object* operator*(void);
00073                     Value* value(void);
00074                     List* list(void);
00075                     Composite* composite(void);
00076             };
00077     };
00078 
00079     struct Exc_WrongListElemType : public Exc
00080     {
00081         int elemNum;
00082         string assumedType;
00083     
00084         Exc_WrongListElemType(const string& iassumedType)
00085         : elemNum(-1), assumedType(iassumedType)
00086         {
00087             ostringstream oss;
00088             oss << "Tried to treat a list element as a "
00089                 << assumedType << ", which it is not.";
00090             message = oss.str();
00091         }
00092         
00093         Exc_WrongListElemType(int ielemNum, const string& iassumedType)
00094         : elemNum(ielemNum), assumedType(iassumedType)
00095         {
00096             ostringstream oss;
00097             oss << "Tried to treat list element number " << elemNum << " as a "
00098                 << assumedType << ", which it is not.";
00099             message = oss.str();
00100         }
00101         
00102     };
00103 }
00104 
00105 #endif // INC_LIST_H

Generated on Wed Jan 7 21:34:45 2004 for libsofu by doxygen 1.3.5