Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

variable_argument_array.hh

00001 /*
00002 *  Name:      variable_argument_array.hh
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Variable argument list handler
00005 *  Date:      $Date: 2003/08/08 23:30:34 $
00006 *  Revision:  $Revision: 1.2 $
00007 *
00008 *  Copyright (C) 1994-2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00026 #ifndef _MPCL_UTIL_VARIABLE_ARGUMENT_ARRAY__
00027 #define _MPCL_UTIL_VARIABLE_ARGUMENT_ARRAY__
00028 
00029 #include <cstdarg>
00030 #include <vector>
00031 #include "../exceptions.hh"
00032 
00033 
00035 namespace mpcl
00036 {
00037 
00039   namespace util
00040   {
00041 
00051     template <typename TArgumentType>
00052     class TVariableArgumentArray
00053     {
00054 
00055       private:
00056 
00062         va_list*   ptVa_list;
00063 
00070         mutable bool   gLastGetFailed;
00071 
00073         mutable std::vector<TArgumentType>   tArgumentArray;
00074 
00075 
00076       public:
00077 
00078         //
00079         //  C O N S T R U C T O R S
00080         //
00081 
00083         TVariableArgumentArray (void) :
00084           ptVa_list      (NULL)       ,
00085           gLastGetFailed (false)      ,
00086           tArgumentArray ()           {}
00087 
00093         void initialize (va_list& rtSOURCE_VA_LIST)
00094         {
00095           ptVa_list      = &rtSOURCE_VA_LIST;
00096           gLastGetFailed = false;
00097           tArgumentArray.clear();
00098         }
00099 
00100 
00101       public:
00102 
00103         //
00104         //  S E L E C T O R S
00105         //
00106 
00112         TArgumentType& operator [] (size_t zINDEX) const
00113           throw (TConstraintException)
00114         {
00115           if ( zINDEX >= size() )
00116           {
00117             throw TConstraintException ("out of limits", __FILE__, __LINE__);
00118           }
00119           return tArgumentArray [zINDEX];
00120         }
00121 
00126         size_t size (void) const;
00127 
00128     };  // class TVariableArgumentArray
00129 
00130 
00131     //
00132     //  C O N S T R U C T O R S
00133     //
00134 
00135     template <typename TArgumentType>
00136     inline size_t TVariableArgumentArray<TArgumentType>::size (void) const
00137     {
00138 
00139       if ( !gLastGetFailed )
00140       {
00141         int*   piTest = NULL;
00142 
00143         while ( !gLastGetFailed )
00144         {
00145           piTest = va_arg (*ptVa_list, int*);
00146           if ( !piTest )
00147           {
00148             gLastGetFailed = true;
00149             continue;
00150           }
00151           tArgumentArray.push_back ((TArgumentType) piTest);
00152         }
00153       }
00154       return tArgumentArray.size();
00155 
00156     }  // size()
00157 
00158   }  // namespace util
00159 
00160 }  // namespace mpcl
00161 
00162 
00163 #endif  // not _MPCL_UTIL_VARIABLE_ARGUMENT_ARRAY__

Generated on Mon Oct 13 02:35:24 2003 for MPCL by doxygen1.2.18