VariadicArgument.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   (c) Art Tevs, MPI Informatik Saarbruecken                             *
00004  *       mailto: <tevs@mpi-sb.mpg.de>                                      *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  *                                                                         *
00011  ***************************************************************************/
00012 
00013 //----------------------------------------------------------------------------------
00014 // Includes
00015 //----------------------------------------------------------------------------------
00016 #include "VariadicArgument.h"
00017 #include "Exception.h"
00018 
00019 namespace nrEngine {
00020 
00021         //----------------------------------------------------------------------------------
00022         VarArg::VarArg() : count(0)
00023         {
00024 
00025         }
00026 
00027         //----------------------------------------------------------------------------------
00028         VarArg::VarArg(const boost::any& p) : count(1)
00029         {
00030                 mArgs.push_back(p);
00031         }
00032 
00033         //----------------------------------------------------------------------------------
00034         VarArg::VarArg(const VarArg& v)
00035         {
00036                 // copy all elemnts form v into this
00037                 this->count = v.count;
00038                 this->mArgs = v.mArgs;
00039         }
00040 
00041         //----------------------------------------------------------------------------------
00042         VarArg& VarArg::operator, (const boost::any& p)
00043         {
00044                 // add new element to the list
00045                 mArgs.push_back(p);
00046                 count ++;
00047                 return *this;
00048         }
00049 
00050         //----------------------------------------------------------------------------------
00051         boost::any VarArg::pop_front()
00052         {
00053                 NR_ASSERT(count > 0);           
00054                 boost::any p = mArgs.front();
00055                 mArgs.pop_front();
00056                 count --;
00057                 return p;
00058         }
00059 
00060         //----------------------------------------------------------------------------------
00061         boost::any VarArg::pop_back()
00062         {
00063                 NR_ASSERT(count > 0);
00064                 boost::any p = mArgs.back();
00065                 mArgs.pop_back();
00066                 count --;
00067                 return p;
00068         }
00069 
00070         //----------------------------------------------------------------------------------
00071         void VarArg::push_back(const boost::any& p)
00072         {
00073                 *this,p;
00074         }
00075 
00076         //----------------------------------------------------------------------------------
00077         void VarArg::empty()
00078         {
00079                 mArgs.empty();
00080                 count = 0;
00081         }
00082 
00083         //----------------------------------------------------------------------------------
00084         boost::any& VarArg::_get(int index)
00085         {
00086                 // check if the index is OK
00087                 NR_ASSERT(index >= 0 && index < count);
00088 
00089                 // get the value on this position
00090                 args::iterator it = mArgs.begin();
00091                 for (int k=0; k < index; k++) it++;
00092                 //it = it + index;
00093                 
00094                 return *it;
00095         }
00096         
00097         //----------------------------------------------------------------------------------
00098         boost::any& VarArg::operator[](int index)
00099         {
00100                 return _get(index);
00101         }
00102 
00103 };
00104 

Generated on Wed Sep 12 23:19:42 2007 for nrEngine by  doxygen 1.5.1