| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/kernel/TeUtils.h
Go to the documentation of this file.

    00001 /************************************************************************************
    00002 TerraLib - a library for developing GIS applications.
    00003 Copyright  2001-2004 INPE and Tecgraf/PUC-Rio.
    00004
    00005 This code is part of the TerraLib library.
    00006 This library is free software; you can redistribute it and/or
    00007 modify it under the terms of the GNU Lesser General Public
    00008 License as published by the Free Software Foundation; either
    00009 version 2.1 of the License, or (at your option) any later version.
    00010
    00011 You should have received a copy of the GNU Lesser General Public
    00012 License along with this library.
    00013
    00014 The authors reassure the license terms regarding the warranties.
    00015 They specifically disclaim any warranties, including, but not limited to,
    00016 the implied warranties of merchantability and fitness for a particular purpose.
    00017 The library provided hereunder is on an "as is" basis, and the authors have no
    00018 obligation to provide maintenance, support, updates, enhancements, or modifications.
    00019 In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
    00020 indirect, special, incidental, or consequential damages arising out of the use
    00021 of this library and its documentation.
    00022 *************************************************************************************/
    00026 #ifndef  __TERRALIB_INTERNAL_UTILS_H
    00027 #define  __TERRALIB_INTERNAL_UTILS_H
    00028
    00029 #if defined(_MSC_VER) /* MSVC Compiler */
    00030 #pragma warning(disable: 4786)
    00031 #endif
    00032
    00033 #include <string>
    00034 #include <vector>
    00035 #include <cstdio>
    00036 #include <time.h>
    00037
    00038
    00039 #include "TeCoord2D.h"
    00040 #include "TeProgress.h"
    00041 #include "TeAttribute.h"
    00042 #include "TeBox.h"
    00043
    00044 class TeProjection;
    00045
    00046 using namespace std;
    00047
    00057
    00058            TL_DLL string TeGetExtension ( const char* value );
    00059
    00061            TL_DLL string TeGetName ( const char* value );
    00062
    00064            TL_DLL string TeGetBaseName ( const char* value );
    00065
    00067            TL_DLL string TeGetPath(const char* value);
    00068
    00070
    00075            TL_DLL void TeWriteToFile(const string& fileName, const string& text, const string& mode);
    00082
    00083            TL_DLL string Te2String ( const int value );
    00084
    00086            TL_DLL string Te2String ( const unsigned int value );
    00087
    00089            TL_DLL string Te2String ( const long value );
    00090
    00092   TL_DLL string Te2String ( const long long int value );
    00093
    00095            TL_DLL string Te2String ( const unsigned long value );
    00096
    00098            TL_DLL string Te2String ( const double value, int precision );
    00099
    00101            TL_DLL string Te2String ( const double value );
    00102
    00109
    00110            TL_DLL void TeConvertToUpperCase ( const string& , char* );
    00111
    00113            TL_DLL string TeConvertToUpperCase (const string &name);
    00114
    00116            TL_DLL string TeConvertToLowerCase (const string &name);
    00117
    00119            TL_DLL std::string TeRemoveSpecialChars ( const std::string& str);
    00120
    00122            TL_DLL std::string TeReplaceSpecialChars ( const std::string& str);
    00123
    00125            TL_DLL std::string TeReplaceSpecialChars ( const std::string& str,  bool& changed);
    00126
    00128            TL_DLL bool TeRenameInvalidFieldName(TeAttributeList &attr);
    00129
    00131   /*
    00132     \param strIn Input String.
    00133     \param separatorSymbol The symbol between the decimal string part
    00134     and the remaining characteres.
    00135     \param strOut Output string.
    00136   */
    00137   TL_DLL void TeRemoveRightDecimalZeroes( const std::string& strIn,
    00138     char separatorSymbol, std::string& strOut );
    00139
    00140
    00142            TL_DLL void TeTrim(string &str);
    00143
    00145            TL_DLL int TeSplitString(const string& input, const string& delimiter, vector<string>& results);
    00146
    00148            /*
    00149                       \params caseS flag indicating if it is a case sensitive comparation
    00150            */
    00151            TL_DLL bool TeStringCompare(const string& str1, const string& str2, bool caseS=false);
    00152
    00153
    00155            /*
    00156                       \param name                                 string to be checked
    00157                       \param changed                   output flag to identify that string has changed
    00158                       \param invalidChar    output or sequence of chars that are invalid in the name
    00159                       \return the modified valid name
    00160            */
    00161            TL_DLL string TeCheckName(const string& name, bool& changed, string& invalidChar);
    00168
    00169     inline int TeRound(double val)
    00170            {
    00171                       if (val>=0)
    00172                                  return (int)(val+.5);
    00173                       else
    00174                                  return (int)(val-.5);
    00175            }
    00176
    00178            TL_DLL double TeRoundD(double val, int precision=8);
    00179
    00181            TL_DLL bool TeCompareDouble(double a, double b, int precision);
    00182
    00184            /*
    00185                       \param val the number to be adjusted
    00186                       \param precision the number of decimals places to be used
    00187                       \param reduce flag to indicate that the number should be reduced instead to increased
    00188                       \return the adjusted number
    00189            */
    00190            TL_DLL double TeAdjustToPrecision(double val, int precision, bool reduce=false);
    00191
    00193            /*
    00194                       Raster elements have area, so raster element in upper-left position has
    00195                       index from [-0.5,+0.5) in i and j dimension.
    00196            */
    00197     inline int TeRoundRasterIndex(double val)
    00198            {
    00199                       int ind = (int) val;
    00200                       if (val < (ind-0.5))
    00201                                  ind -= 1;
    00202                       else if (val >= (ind+0.5))
    00203                                  ind += 1;
    00204                       return ind;
    00205            }
    00212     inline double TeCubicRoot( double x )
    00213            {
    00214                       if( x < 0 ) {
    00215                       return ( -1. ) * pow(  ( -1. ) * x, ( 1. / 3. ) );
    00216                       } else {
    00217                                  return pow(  x, ( 1. / 3. ) );
    00218                       }
    00219            };
    00220
    00222     inline bool TeFPEquals(double d1, double d2, double precision)
    00223            {
    00224                       double eps1 = fabs(d1),
    00225                                  eps2 = fabs(d2),
    00226                                  eps;
    00227                       eps = (eps1 > eps2) ? eps1 : eps2;
    00228                       if (eps == 0.0)
    00229                                  return true; //both numbers are 0.0
    00230                       eps *= precision;
    00231                       return (fabs(d1 - d2) < eps);
    00232            }
    00233
    00235            static inline short swaps(short value)
    00236            {
    00237                       short svalue = ((value & 0x00ff) << 8) | ((value >> 8) & 0x00ff);
    00238                       return svalue;
    00239            }
    00240
    00246   TL_DLL unsigned long int TeGetFreePhysicalMemory();
    00247
    00253   TL_DLL unsigned long int TeGetTotalPhysicalMemory();
    00254
    00261   TL_DLL unsigned long int TeGetUsedVirtualMemory();
    00262
    00270   TL_DLL unsigned long int TeGetTotalVirtualMemory();
    00271
    00277   TL_DLL unsigned int TeGetPhysProcNumber();
    00278
    00285   TL_DLL bool TeGetTempFileName( std::string& filename );
    00286
    00294   TL_DLL unsigned long int TeGetFileSize( const std::string& filename );
    00295
    00302   TL_DLL bool TeCheckFileExistence( const std::string& filename );
    00303
    00305   /*
    00306     \param path The directory path.
    00307     \param recursive If true, a recursive search will be performed.
    00308     \param filesnames The files names.
    00309     \return true if OK, false on errors.
    00310   */
    00311   TL_DLL bool
    00312   TeGetDirFullFilesNames( const std::string& path,
    00313     const bool& recursive,
    00314     std::vector< std::string >& filesnames );
    00315
    00323   TL_DLL bool TeCopyFile( const std::string& inputFileName,
    00324     const std::string& outputFileName );
    00325
    00333   TL_DLL bool TeCompareFiles( const std::string& inputFileName1,
    00334     const std::string& inputFileName2 );
    00335
    00346   TL_DLL bool TeReplaceTextFileSubString( const std::string& inputFileName,
    00347     const std::string& outputFileName, const std::string& oldSubString,
    00348     const std::string& newSubString );
    00349
    00362   TL_DLL unsigned long int TeCreateHashFromString(
    00363     unsigned char const* inputString,
    00364     const unsigned int& inputStringSize );
    00365
    00366
    00377   TL_DLL void TeGetEspecialCharsFixVector(std::vector<std::string> & especialIn, std::vector<std::string> & especialOut);
    00378
    00386   TL_DLL void TeGetAccentuatedUpperVector(std::vector<std::string> & upperIn, std::vector<std::string> & upperOut);
    00387
    00395   TL_DLL void TeGetAccentuatedLowerVector(std::vector<std::string> & lowerIn, std::vector<std::string> & lowerOut);
    00396
    00404   TL_DLL bool TeCheckBoxConsistency(const TeBox& box, TeProjection* boxProjection);
    00405
    00412   TL_DLL std::string TeGetUnitName(const TeUnits& units);
    00413
    00420   TL_DLL TeUnits TeGetUnit(const std::string& unitName);
    00421
    00430   TL_DLL double TeConvertUnits(const double& value, const TeUnits& unitFrom, const TeUnits& unitTo);
    00431
    00438   TL_DLL bool TeFileExists(const std::string& fileName);
    00439
    00447   TL_DLL bool TeFileCopy(const std::string& fileNameIn, const std::string& fileNameOut);
    00448
    00455   TL_DLL bool TeFileDelete(const std::string& fileName);
    00456
    00464   TL_DLL bool TeFileRename(const std::string& oldFileName, const std::string& newFileName);
    00465
    00466 #endif
    00467
    00468

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines