/usr/include/terralib/kernel/TeUtils.h is in libterralib-dev 4.0.0-5ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | /************************************************************************************
TerraLib - a library for developing GIS applications.
Copyright 2001-2004 INPE and Tecgraf/PUC-Rio.
This code is part of the TerraLib library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
You should have received a copy of the GNU Lesser General Public
License along with this library.
The authors reassure the license terms regarding the warranties.
They specifically disclaim any warranties, including, but not limited to,
the implied warranties of merchantability and fitness for a particular purpose.
The library provided hereunder is on an "as is" basis, and the authors have no
obligation to provide maintenance, support, updates, enhancements, or modifications.
In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
indirect, special, incidental, or consequential damages arising out of the use
of this library and its documentation.
*************************************************************************************/
/*! \file TeUtils.h
\brief This file contains some general purpose utilitary functions
*/
#ifndef __TERRALIB_INTERNAL_UTILS_H
#define __TERRALIB_INTERNAL_UTILS_H
#ifdef WIN32
#pragma warning ( disable: 4786 )
#endif
#include <string>
#include <vector>
#include <cstdio>
#include <time.h>
#include "TeCoord2D.h"
#include "TeProgress.h"
#include "TeAttribute.h"
#include "TeBox.h"
class TeProjection;
using namespace std;
/** @defgroup Utils General purpose utilitary functions
* General purpose utilitary functions
* @{
*/
/** @defgroup FileNameFunctions Functions to manipulate file names
@ingroup Utils
* @{
*/
//! Get the extension part (right to the dot) of a string
TL_DLL string TeGetExtension ( const char* value );
//! Get the name part (left to the dot) of a string, path included
TL_DLL string TeGetName ( const char* value );
//! Get the base name part of a string, strip path information
TL_DLL string TeGetBaseName ( const char* value );
//! Get the path part of a file name
TL_DLL string TeGetPath(const char* value);
//! Writes a string to a file.
/*!
\param fileName the file name to write to, including the directory.
\param text the string with the text to write to.
\param mode the mode used to write to the file (a | w | r).
*/
TL_DLL void TeWriteToFile(const string& fileName, const string& text, const string& mode);
/** @} */
/** @defgroup C2StringFunctions Functions convert numbers to strings
@ingroup Utils
* @{
*/
//! Transforms an integer to string
TL_DLL string Te2String ( const int value );
//! Transforms an unsigned integer to string
TL_DLL string Te2String ( const unsigned int value );
//! Transforms a long to string
TL_DLL string Te2String ( const long value );
//! Transforms an unsigned long to string
TL_DLL string Te2String ( const unsigned long value );
//! Transforms a double to string floating point notation with precision decimal places
TL_DLL string Te2String ( const double value, int precision );
//! Transforms a double to string in exponential notation
TL_DLL string Te2String ( const double value );
/** @} */
/** @defgroup StringFunctions Functions to manipulate strings
@ingroup Utils
* @{
*/
//! Converts a string to upper case
TL_DLL void TeConvertToUpperCase ( const string& , char* );
//! Converts a string to upper case
TL_DLL string TeConvertToUpperCase (const string &name);
//! Converts a string to lower case
TL_DLL string TeConvertToLowerCase (const string &name);
//! Removes special characteres from a string
TL_DLL std::string TeRemoveSpecialChars ( const std::string& str);
//! Replace special characteres from a string
TL_DLL std::string TeReplaceSpecialChars ( const std::string& str);
//! Replace special characteres from a string
TL_DLL std::string TeReplaceSpecialChars ( const std::string& str, bool& changed);
//! Rename special field names
TL_DLL bool TeRenameInvalidFieldName(TeAttributeList &attr);
//! Remove all occurrences right decimal zeros from the real number represented by strIn.
/*
\param strIn Input String.
\param separatorSymbol The symbol between the decimal string part
and the remaining characteres.
\param strOut Output string.
*/
TL_DLL void TeRemoveRightDecimalZeroes( const std::string& strIn,
char separatorSymbol, std::string& strOut );
//! Removes left and right blank, tab and carriage return characters of a string
TL_DLL void TeTrim(string &str);
//! Splits a string, given a separator, in a vector of parts
TL_DLL int TeSplitString(const string& input, const string& delimiter, vector<string>& results);
//! Compares two strings
/*
\params caseS flag indicating if it is a case sensitive comparation
*/
TL_DLL bool TeStringCompare(const string& str1, const string& str2, bool caseS=false);
//! Validate a string to check if it can be used as a column name
/*
\param name string to be checked
\param changed output flag to identify that string has changed
\param invalidChar output or sequence of chars that are invalid in the name
\return the modified valid name
*/
TL_DLL string TeCheckName(const string& name, bool& changed, string& invalidChar);
/** @} */
/** @defgroup MathFunctions Mathematical functions
@ingroup Utils
* @{
*/
//! Rounds a double to int
TL_DLL inline int TeRound(double val)
{
if (val>=0)
return (int)(val+.5);
else
return (int)(val-.5);
}
//! Rounds a double value to a given number of decimal digits
TL_DLL double TeRoundD(double val, int precision=8);
//! Compares two doubles
TL_DLL bool TeCompareDouble(double a, double b, int precision);
//! Adjust a number to a given precision
/*
\param val the number to be adjusted
\param precision the number of decimals places to be used
\param reduce flag to indicate that the number should be reduced instead to increased
\return the adjusted number
*/
TL_DLL double TeAdjustToPrecision(double val, int precision, bool reduce=false);
//! Rounds a double raster element index to an integer
/*
Raster elements have area, so raster element in upper-left position has
index from [-0.5,+0.5) in i and j dimension.
*/
TL_DLL inline int TeRoundRasterIndex(double val)
{
int ind = (int) val;
if (val < (ind-0.5))
ind -= 1;
else if (val >= (ind+0.5))
ind += 1;
return ind;
}
/**
* Cubic root from x.
*
* @param x X.
* @return The cubic root from x.
*/
TL_DLL inline double TeCubicRoot( double x )
{
if( x < 0 ) {
return ( -1. ) * pow( ( -1. ) * x, ( 1. / 3. ) );
} else {
return pow( x, ( 1. / 3. ) );
}
};
/*! Comparassion of two floating points, considering a given precision */
TL_DLL inline bool TeFPEquals(double d1, double d2, double precision)
{
double eps1 = fabs(d1),
eps2 = fabs(d2),
eps;
eps = (eps1 > eps2) ? eps1 : eps2;
if (eps == 0.0)
return true; //both numbers are 0.0
eps *= precision;
return (fabs(d1 - d2) < eps);
}
//! Swap the bytes of a short value
static inline short swaps(short value)
{
short svalue = ((value & 0x00ff) << 8) | ((value >> 8) & 0x00ff);
return svalue;
}
/**
* Returns the amount of free physical memory (bytes).
*
* @return The amount of free physical memory (bytes).
*/
TL_DLL unsigned long int TeGetFreePhysicalMemory();
/**
* Returns the amount of total physical memory (bytes).
*
* @return The amount of total physical memory (bytes).
*/
TL_DLL unsigned long int TeGetTotalPhysicalMemory();
/**
* Returns the amount of free virtual memory (bytes)
* for the current process (physical + swapped).
*
* @return The amount of free virtual memory (bytes).
*/
TL_DLL unsigned long int TeGetFreeVirtualMemory();
/**
* Returns the amount of total virtual memory (bytes)
* that can be claimed by the current process
* (physical + swapped).
*
* @return The amount of total virtual memory (bytes).
*/
TL_DLL unsigned long int TeGetTotalVirtualMemory();
/**
* Returns the number of physical processors.
*
* @return The number of physical processors.
*/
TL_DLL unsigned int TeGetPhysProcNumber();
/**
* Generates a temporary unique file name.
*
* @param filename The generated file name.
* @return true if ok, false errors.
*/
TL_DLL bool TeGetTempFileName( std::string& filename );
/**
* @brief The file size (bytes).
*
* @note Throws an exception if file not found.
* @param filename The file name.
* @return The file size (bytes).
*/
TL_DLL unsigned long int TeGetFileSize( const std::string& filename );
/**
* @brief Check the file existence.
*
* @param filename The file name.
* @return true if the file exists, false if not.
*/
TL_DLL bool TeCheckFileExistence( const std::string& filename );
//! Get the full names of all files inside the given directory.
/*
\param path The directory path.
\param recursive If true, a recursive search will be performed.
\param filesnames The files names.
\return true if OK, false on errors.
*/
TL_DLL bool
TeGetDirFullFilesNames( const std::string& path,
const bool& recursive,
std::vector< std::string >& filesnames );
/**
* @brief Creates a copy from the given input file name.
*
* @param inputFileName The input full file name.
* @param outputFileName The output full file name.
* @return true if OK, false if not.
*/
TL_DLL bool TeCopyFile( const std::string& inputFileName,
const std::string& outputFileName );
/**
* @brief Compare two files.
*
* @param inputFileName1 The input full file 1 name.
* @param inputFileName2 The input full file 2 name.
* @return true if the two files are identical, false if not.
*/
TL_DLL bool TeCompareFiles( const std::string& inputFileName1,
const std::string& inputFileName2 );
/**
* @brief Creates a copy from the given input text file name
* replacing all ocurrences of
*
* @param inputFileName The input full file name.
* @param inputFileName The output full file name.
* @param oldSubString The sub-string to be replaced from the input file.
* @param newSubString The new sub-string.
* @return true if OK, false if not.
*/
TL_DLL bool TeReplaceTextFileSubString( const std::string& inputFileName,
const std::string& outputFileName, const std::string& oldSubString,
const std::string& newSubString );
/**
* @brief Creates a hash number from an input string.
* @details This algorithm was created for sdbm (a public-domain
* reimplementation of ndbm) database library. It was found to do well in
* scrambling bits, causing better distribution of the keys and fewer
* splits. It also happens to be a good general hashing function with
* good distribution. the actual function is
* hash(i) = hash(i - 1) * 65599 + str[i]
* @param inputStringFileName The input full file name.
* @param inputStringSize Input string size.
* @return The generated hash value.
*/
TL_DLL unsigned long int TeCreateHashFromString(
unsigned char const* inputString,
const unsigned int& inputStringSize );
/** @} */
/** @} */
/**
* @brief Popule vectors with especial chars with accentuation and without
*
* @param vectorIn Vector with accentuation.
* @param vectorOut Vector without accentuation.
* @return void
*/
TL_DLL void TeGetEspecialCharsFixVector(std::vector<std::string> & especialIn, std::vector<std::string> & especialOut);
/**
* @brief Popule vectors with upper chars with accentuation and without
*
* @param vectorIn Vector with accentuation.
* @param vectorOut Vector without accentuation.
* @return void
*/
TL_DLL void TeGetAccentuatedUpperVector(std::vector<std::string> & upperIn, std::vector<std::string> & upperOut);
/**
* @brief Popule vectors with lower chars with accentuation and without
*
* @param vectorIn Vector with accentuation.
* @param vectorOut Vector without accentuation.
* @return void
*/
TL_DLL void TeGetAccentuatedLowerVector(std::vector<std::string> & lowerIn, std::vector<std::string> & lowerOut);
/**
* @brief Checks if the given box at the given projection is inside the LatLong's representation limits
*
* @param box The box to be verified
* @param boxProjection The projection of the box.
* @return TRUE if the box is consisnt, FALSE otherwise.
*/
TL_DLL bool TeCheckBoxConsistency(const TeBox& box, TeProjection* boxProjection);
#endif
|