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

system.cc

00001 /*
00002 *  Name:      system.cc
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Base operating system class
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 #include <climits>
00027 #include <iterator>
00028 #include <mpcl/system/system.hh>
00029 #include <mpcl/text/string.hh>
00030 
00031 
00032 //
00033 //  C O N S T R U C T O R S
00034 //
00035 
00036 mpcl::system::ISystem::TMachineDependent::
00037 TMachineDependent (void) :
00038   eEndianType (eBigEndian) 
00039 {
00040 
00041   using std::size_t;
00042 
00043   size_t   zGuess = 0;
00044 
00045   //
00046   //  Endian guessing.
00047   //
00048 
00049   //
00050   //  zGuess will hold (for "size_t" with 4 bytes
00051   //  length): 0x04030201
00052   //
00053   for (register size_t J = 0; ( J < sizeof (size_t) ) ;++J)
00054   {
00055     zGuess |= ((J + 1) << (J * CHAR_BIT));
00056   }
00057   
00058   if ( *((const char*) &zGuess) == sizeof (size_t) )
00059   {
00060     eEndianType = eBigEndian;
00061   }
00062   else
00063   {
00064     eEndianType = eLittleEndian;
00065   }
00066 
00067 }  // TMachineDependent::TMachineDependent()
00068 
00069 
00070 long int mpcl::system::ISystem::TMachineDependent::
00071 getEndianIndependentLongInt ( EEndianness          eENDIAN_TYPE      ,
00072                               const unsigned char* pkucSOURCE_BUFFER ,
00073                               std::size_t          zLENGTH           ) const
00074 {
00075 
00076   long int   liResult  = 0;
00077   int        iMaxShift = ((zLENGTH - 1) * CHAR_BIT);
00078 
00079   if ( eENDIAN_TYPE == eLittleEndian )
00080   {
00081     for (register int J = 0; ( J <= iMaxShift ) ;++pkucSOURCE_BUFFER)
00082     {
00083       liResult += (((long int) *pkucSOURCE_BUFFER) << J);
00084       J        += CHAR_BIT;
00085     }
00086   }
00087   else
00088   {
00089     for (register int J = iMaxShift; ( J >= 0 ) ;++pkucSOURCE_BUFFER)
00090     {
00091       liResult += (((long int) *pkucSOURCE_BUFFER) << J);
00092       J        -= CHAR_BIT;
00093     }
00094   }
00095   return liResult;
00096 
00097 }  // TMachineDependent::getEndianIndependentLongInt()
00098 
00099 
00100 std::vector<mpcl::text::TString> mpcl::system::ISystem::
00101 getPathItems (const std::string& rkySOURCE_PATH_COLLECTION) const
00102 {
00103 
00104   using std::back_insert_iterator;
00105   using std::vector;
00106   using text::Split;
00107   using text::TString;
00108 
00109   //
00110   //  To clarify declarations.
00111   //  
00112   typedef
00113     vector<TString>
00114     TStringVector;
00115 
00116   TStringVector::iterator   I;
00117   TStringVector             tPathVector;
00118   const char                kcDirSeparator = getDirectorySeparator();
00119 
00120   //
00121   //  Splits string in sub-strings separated by path separators.
00122   //
00123   Split ( rkySOURCE_PATH_COLLECTION.begin()                 ,
00124           rkySOURCE_PATH_COLLECTION.end()                   ,
00125           getPathSeparator()                                ,
00126           back_insert_iterator<TStringVector> (tPathVector) );
00127 
00128   //
00129   //  Adds directory separator if not present.
00130   //
00131   for (I = tPathVector.begin(); ( I != tPathVector.end() ) ;++I)
00132   {
00133     if ( (*I) [I->length() - 1] != kcDirSeparator )
00134     {
00135       I->append (1, kcDirSeparator);
00136     }
00137   }
00138   return tPathVector;
00139 
00140 }  // getPathItems()

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