ofstd/include/ofstd.h

00001 /* 00002 * 00003 * Copyright (C) 2000-2004, OFFIS 00004 * 00005 * This software and supporting documentation were developed by 00006 * 00007 * Kuratorium OFFIS e.V. 00008 * Healthcare Information and Communication Systems 00009 * Escherweg 2 00010 * D-26121 Oldenburg, Germany 00011 * 00012 * THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND OFFIS MAKES NO WARRANTY 00013 * REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY OR 00014 * FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES OR 00015 * ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND 00016 * PERFORMANCE OF THE SOFTWARE IS WITH THE USER. 00017 * 00018 * Module: ofstd 00019 * 00020 * Author: Joerg Riesmeier, Marco Eichelberg 00021 * 00022 * Purpose: Class for various helper functions 00023 * 00024 * Last Update: $Author: joergr $ 00025 * Update Date: $Date: 2004/04/16 12:43:26 $ 00026 * CVS/RCS Revision: $Revision: 1.21 $ 00027 * Status: $State: Exp $ 00028 * 00029 * CVS/RCS Log at end of file 00030 * 00031 */ 00032 00033 00034 #ifndef OFSTD_H 00035 #define OFSTD_H 00036 00037 #include "osconfig.h" 00038 #include "oflist.h" /* for class OFList */ 00039 #include "ofstring.h" /* for class OFString */ 00040 #include "oftypes.h" /* for OFBool */ 00041 00042 #define INCLUDE_CSTDLIB 00043 #define INCLUDE_CSTDIO 00044 #define INCLUDE_CSTRING 00045 #include "ofstdinc.h" 00046 00047 BEGIN_EXTERN_C 00048 #ifdef HAVE_SYS_TYPES_H 00049 #include <sys/types.h> /* for size_t */ 00050 #endif 00051 #ifdef HAVE_UNISTD_H 00052 #include <unistd.h> /* for sleep */ 00053 #endif 00054 END_EXTERN_C 00055 00056 00057 /*---------------------* 00058 * class declaration * 00059 *---------------------*/ 00060 00064 class OFStandard 00065 { 00066 00067 public: 00068 00069 // --- string functions --- 00070 00086 static inline size_t strlcpy(char *dst, const char *src, size_t siz) 00087 { 00088 #ifdef HAVE_STRLCPY 00089 return ::strlcpy(dst, src, siz); 00090 #else 00091 return my_strlcpy(dst, src, siz); 00092 #endif 00093 } 00094 00112 static inline size_t strlcat(char *dst, const char *src, size_t siz) 00113 { 00114 #ifdef HAVE_STRLCAT 00115 return ::strlcat(dst, src, siz); 00116 #else 00117 return my_strlcat(dst, src, siz); 00118 #endif 00119 } 00120 00121 // --- file system functions --- 00122 00129 static OFBool pathExists(const OFString &pathName); 00130 00137 static OFBool fileExists(const OFString &fileName); 00138 00145 static OFBool dirExists(const OFString &dirName); 00146 00152 static OFBool isReadable(const OFString &pathName); 00153 00159 static OFBool isWriteable(const OFString &pathName); 00160 00172 static OFString &normalizeDirName(OFString &result, 00173 const OFString &dirName, 00174 const OFBool allowEmptyDirName = OFFalse); 00175 00190 static OFString &combineDirAndFilename(OFString &result, 00191 const OFString &dirName, 00192 const OFString &fileName, 00193 const OFBool allowEmptyDirName = OFFalse); 00194 00206 static size_t searchDirectoryRecursively(const OFString &directory, 00207 OFList<OFString> &fileList, 00208 const OFString &pattern /*= ""*/, // default parameter value not 00209 const OFString &dirPrefix /*= ""*/); // supported by Sun CC 2.0.1 :-/ 00210 00211 // --- other functions --- 00212 00230 static const OFString &convertToMarkupString(const OFString &sourceString, 00231 OFString &markupString, 00232 const OFBool convertNonASCII = OFFalse, 00233 const OFBool xmlMode = OFTrue, 00234 const OFBool newlineAllowed = OFFalse); 00235 00249 static const OFString &encodeBase64(const unsigned char *data, 00250 const size_t length, 00251 OFString &result, 00252 const size_t width = 0); 00253 00267 static size_t decodeBase64(const OFString &data, 00268 unsigned char *&result); 00269 00304 static double atof(const char *s, 00305 OFBool *success = NULL); 00306 00330 static void ftoa(char *target, 00331 size_t targetSize, 00332 double value, 00333 unsigned int flags = 0, 00334 int width = 0, 00335 int precision = -1); 00336 00341 00343 static const unsigned int ftoa_format_e; 00344 00346 static const unsigned int ftoa_format_f; 00347 00349 static const unsigned int ftoa_uppercase; 00350 00355 static const unsigned int ftoa_alternate; 00356 00358 static const unsigned int ftoa_leftadj; 00359 00361 static const unsigned int ftoa_zeropad; 00362 00364 00373 static OFBool stringMatchesCharacterSet( const char *str, const char *charset ); 00374 00380 static inline unsigned int sleep(unsigned int seconds) 00381 { 00382 #if defined(HAVE_SLEEP) && !defined(HAVE_WINDOWS_H) 00383 // we only use this call if HAVE_WINDOWS_H is undefined because 00384 // MinGW has sleep() but no prototype 00385 return ::sleep(seconds); 00386 #else 00387 return my_sleep(seconds); 00388 #endif 00389 } 00390 00391 private: 00392 00401 static size_t my_strlcpy(char *dst, const char *src, size_t siz); 00402 00411 static size_t my_strlcat(char *dst, const char *src, size_t siz); 00412 00418 static unsigned int my_sleep(unsigned int seconds); 00419 00420 }; 00421 00422 00423 #endif 00424 00425 00426 /* 00427 * 00428 * CVS/RCS Log: 00429 * $Log: ofstd.h,v $ 00430 * Revision 1.21 2004/04/16 12:43:26 joergr 00431 * Restructured code to avoid default parameter values for "complex types" like 00432 * OFString. Required for Sun CC 2.0.1. 00433 * 00434 * Revision 1.20 2003/12/05 10:37:41 joergr 00435 * Removed leading underscore characters from preprocessor symbols (reserved 00436 * symbols). Updated copyright date where appropriate. 00437 * 00438 * Revision 1.19 2003/08/12 13:10:10 joergr 00439 * Improved implementation of normalizeDirName(). 00440 * 00441 * Revision 1.18 2003/07/17 14:53:24 joergr 00442 * Added new function searchDirectoryRecursively(). 00443 * Updated documentation to get rid of doxygen warnings. 00444 * 00445 * Revision 1.17 2003/07/04 13:31:51 meichel 00446 * Fixed issues with compiling with HAVE_STD_STRING 00447 * 00448 * Revision 1.16 2003/07/03 14:23:50 meichel 00449 * Minor changes to make OFStandard::sleep compile on MinGW 00450 * 00451 * Revision 1.15 2003/06/06 09:43:54 meichel 00452 * Added static sleep function in class OFStandard. This replaces the various 00453 * calls to sleep(), Sleep() and usleep() throughout the toolkit. 00454 * 00455 * Revision 1.14 2003/04/17 15:50:51 joergr 00456 * Replace LF and CR by &#10; and &#13; in XML mode instead of &#182; (para). 00457 * 00458 * Revision 1.13 2003/03/12 14:57:47 joergr 00459 * Added apostrophe (') to the list of characters to be replaced by the 00460 * corresponding HTML/XML mnenonic. 00461 * 00462 * Revision 1.12 2002/12/13 13:45:33 meichel 00463 * Removed const from decodeBase64() return code, needed on MIPSpro 00464 * 00465 * Revision 1.11 2002/12/05 13:49:36 joergr 00466 * Moved definition of ftoa() processing flags to implementation file to avoid 00467 * compiler errors (e.g. on Sun CC 2.0.1). 00468 * 00469 * Revision 1.10 2002/12/04 09:13:00 meichel 00470 * Implemented a locale independent function OFStandard::ftoa() that 00471 * converts double to string and offers all the flexibility of the 00472 * sprintf family of functions. 00473 * 00474 * Revision 1.9 2002/11/27 11:23:06 meichel 00475 * Adapted module ofstd to use of new header file ofstdinc.h 00476 * 00477 * Revision 1.8 2002/07/02 15:17:57 wilkens 00478 * Added function OFStandard::stringMatchesCharacterSet(...). 00479 * 00480 * Revision 1.7 2002/06/20 12:02:38 meichel 00481 * Implemented a locale independent function OFStandard::atof() that 00482 * converts strings to double and optionally returns a status code 00483 * 00484 * Revision 1.6 2002/05/14 08:12:51 joergr 00485 * Added support for Base64 (MIME) encoding and decoding. 00486 * 00487 * Revision 1.5 2002/04/25 09:13:52 joergr 00488 * Moved helper function which converts a conventional character string to an 00489 * HTML/XML mnenonic string (e.g. using "&lt;" instead of "<") from module 00490 * dcmsr to ofstd. 00491 * 00492 * Revision 1.4 2002/04/11 12:06:42 joergr 00493 * Added general purpose routines to check whether a file exists, a path points 00494 * to a directory or a file, etc. 00495 * 00496 * Revision 1.3 2001/12/04 16:57:15 meichel 00497 * Implemented strlcpy and strlcat routines compatible with the 00498 * corresponding BSD libc routines in class OFStandard 00499 * 00500 * Revision 1.2 2001/06/01 15:51:35 meichel 00501 * Updated copyright header 00502 * 00503 * Revision 1.1 2000/03/02 12:42:57 joergr 00504 * Added new class comprising all general purpose helper functions (first 00505 * entry: strlcpy - a mixture of strcpy and strncpy). 00506 * 00507 * 00508 * 00509 */


Generated on 4 Nov 2004 for OFFIS DCMTK Version 3.5.3 by Doxygen 1.3.8