00001 /* 00002 * 00003 * Copyright (C) 2000-2005, 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: meichel $ 00025 * Update Date: $Date: 2005/12/08 16:06:04 $ 00026 * CVS/RCS Revision: $Revision: 1.23 $ 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 "dcmtk/config/osconfig.h" 00038 #include "dcmtk/ofstd/oflist.h" /* for class OFList */ 00039 #include "dcmtk/ofstd/ofstring.h" /* for class OFString */ 00040 #include "dcmtk/ofstd/oftypes.h" /* for OFBool */ 00041 00042 #define INCLUDE_CSTDLIB 00043 #define INCLUDE_CSTDIO 00044 #define INCLUDE_CSTRING 00045 #define INCLUDE_UNISTD 00046 #include "dcmtk/ofstd/ofstdinc.h" 00047 00048 BEGIN_EXTERN_C 00049 #ifdef HAVE_SYS_TYPES_H 00050 #include <sys/types.h> /* for size_t */ 00051 #endif 00052 END_EXTERN_C 00053 00054 00055 /*---------------------* 00056 * class declaration * 00057 *---------------------*/ 00058 00062 class OFStandard 00063 { 00064 00065 public: 00066 00067 // --- string functions --- 00068 00084 static inline size_t strlcpy(char *dst, const char *src, size_t siz) 00085 { 00086 #ifdef HAVE_STRLCPY 00087 return ::strlcpy(dst, src, siz); 00088 #else 00089 return my_strlcpy(dst, src, siz); 00090 #endif 00091 } 00092 00110 static inline size_t strlcat(char *dst, const char *src, size_t siz) 00111 { 00112 #ifdef HAVE_STRLCAT 00113 return ::strlcat(dst, src, siz); 00114 #else 00115 return my_strlcat(dst, src, siz); 00116 #endif 00117 } 00118 00119 // --- file system functions --- 00120 00127 static OFBool pathExists(const OFString &pathName); 00128 00135 static OFBool fileExists(const OFString &fileName); 00136 00143 static OFBool dirExists(const OFString &dirName); 00144 00150 static OFBool isReadable(const OFString &pathName); 00151 00157 static OFBool isWriteable(const OFString &pathName); 00158 00170 static OFString &normalizeDirName(OFString &result, 00171 const OFString &dirName, 00172 const OFBool allowEmptyDirName = OFFalse); 00173 00188 static OFString &combineDirAndFilename(OFString &result, 00189 const OFString &dirName, 00190 const OFString &fileName, 00191 const OFBool allowEmptyDirName = OFFalse); 00192 00204 static size_t searchDirectoryRecursively(const OFString &directory, 00205 OFList<OFString> &fileList, 00206 const OFString &pattern /*= ""*/, // default parameter value not 00207 const OFString &dirPrefix /*= ""*/); // supported by Sun CC 2.0.1 :-/ 00208 00209 // --- other functions --- 00210 00228 static const OFString &convertToMarkupString(const OFString &sourceString, 00229 OFString &markupString, 00230 const OFBool convertNonASCII = OFFalse, 00231 const OFBool xmlMode = OFTrue, 00232 const OFBool newlineAllowed = OFFalse); 00233 00247 static const OFString &encodeBase64(const unsigned char *data, 00248 const size_t length, 00249 OFString &result, 00250 const size_t width = 0); 00251 00265 static size_t decodeBase64(const OFString &data, 00266 unsigned char *&result); 00267 00302 static double atof(const char *s, 00303 OFBool *success = NULL); 00304 00328 static void ftoa(char *target, 00329 size_t targetSize, 00330 double value, 00331 unsigned int flags = 0, 00332 int width = 0, 00333 int precision = -1); 00334 00339 00341 static const unsigned int ftoa_format_e; 00342 00344 static const unsigned int ftoa_format_f; 00345 00347 static const unsigned int ftoa_uppercase; 00348 00353 static const unsigned int ftoa_alternate; 00354 00356 static const unsigned int ftoa_leftadj; 00357 00359 static const unsigned int ftoa_zeropad; 00360 00362 00371 static OFBool stringMatchesCharacterSet( const char *str, const char *charset ); 00372 00378 static inline unsigned int sleep(unsigned int seconds) 00379 { 00380 #if defined(HAVE_SLEEP) && !defined(HAVE_WINDOWS_H) 00381 // we only use this call if HAVE_WINDOWS_H is undefined because 00382 // MinGW has sleep() but no prototype 00383 return ::sleep(seconds); 00384 #else 00385 return my_sleep(seconds); 00386 #endif 00387 } 00388 00389 private: 00390 00399 static size_t my_strlcpy(char *dst, const char *src, size_t siz); 00400 00409 static size_t my_strlcat(char *dst, const char *src, size_t siz); 00410 00416 static unsigned int my_sleep(unsigned int seconds); 00417 00418 }; 00419 00420 00421 #endif 00422 00423 00424 /* 00425 * 00426 * CVS/RCS Log: 00427 * $Log: ofstd.h,v $ 00428 * Revision 1.23 2005/12/08 16:06:04 meichel 00429 * Changed include path schema for all DCMTK header files 00430 * 00431 * Revision 1.22 2004/08/03 11:45:42 meichel 00432 * Headers libc.h and unistd.h are now included via ofstdinc.h 00433 * 00434 * Revision 1.21 2004/04/16 12:43:26 joergr 00435 * Restructured code to avoid default parameter values for "complex types" like 00436 * OFString. Required for Sun CC 2.0.1. 00437 * 00438 * Revision 1.20 2003/12/05 10:37:41 joergr 00439 * Removed leading underscore characters from preprocessor symbols (reserved 00440 * symbols). Updated copyright date where appropriate. 00441 * 00442 * Revision 1.19 2003/08/12 13:10:10 joergr 00443 * Improved implementation of normalizeDirName(). 00444 * 00445 * Revision 1.18 2003/07/17 14:53:24 joergr 00446 * Added new function searchDirectoryRecursively(). 00447 * Updated documentation to get rid of doxygen warnings. 00448 * 00449 * Revision 1.17 2003/07/04 13:31:51 meichel 00450 * Fixed issues with compiling with HAVE_STD_STRING 00451 * 00452 * Revision 1.16 2003/07/03 14:23:50 meichel 00453 * Minor changes to make OFStandard::sleep compile on MinGW 00454 * 00455 * Revision 1.15 2003/06/06 09:43:54 meichel 00456 * Added static sleep function in class OFStandard. This replaces the various 00457 * calls to sleep(), Sleep() and usleep() throughout the toolkit. 00458 * 00459 * Revision 1.14 2003/04/17 15:50:51 joergr 00460 * Replace LF and CR by and in XML mode instead of ¶ (para). 00461 * 00462 * Revision 1.13 2003/03/12 14:57:47 joergr 00463 * Added apostrophe (') to the list of characters to be replaced by the 00464 * corresponding HTML/XML mnenonic. 00465 * 00466 * Revision 1.12 2002/12/13 13:45:33 meichel 00467 * Removed const from decodeBase64() return code, needed on MIPSpro 00468 * 00469 * Revision 1.11 2002/12/05 13:49:36 joergr 00470 * Moved definition of ftoa() processing flags to implementation file to avoid 00471 * compiler errors (e.g. on Sun CC 2.0.1). 00472 * 00473 * Revision 1.10 2002/12/04 09:13:00 meichel 00474 * Implemented a locale independent function OFStandard::ftoa() that 00475 * converts double to string and offers all the flexibility of the 00476 * sprintf family of functions. 00477 * 00478 * Revision 1.9 2002/11/27 11:23:06 meichel 00479 * Adapted module ofstd to use of new header file ofstdinc.h 00480 * 00481 * Revision 1.8 2002/07/02 15:17:57 wilkens 00482 * Added function OFStandard::stringMatchesCharacterSet(...). 00483 * 00484 * Revision 1.7 2002/06/20 12:02:38 meichel 00485 * Implemented a locale independent function OFStandard::atof() that 00486 * converts strings to double and optionally returns a status code 00487 * 00488 * Revision 1.6 2002/05/14 08:12:51 joergr 00489 * Added support for Base64 (MIME) encoding and decoding. 00490 * 00491 * Revision 1.5 2002/04/25 09:13:52 joergr 00492 * Moved helper function which converts a conventional character string to an 00493 * HTML/XML mnenonic string (e.g. using "<" instead of "<") from module 00494 * dcmsr to ofstd. 00495 * 00496 * Revision 1.4 2002/04/11 12:06:42 joergr 00497 * Added general purpose routines to check whether a file exists, a path points 00498 * to a directory or a file, etc. 00499 * 00500 * Revision 1.3 2001/12/04 16:57:15 meichel 00501 * Implemented strlcpy and strlcat routines compatible with the 00502 * corresponding BSD libc routines in class OFStandard 00503 * 00504 * Revision 1.2 2001/06/01 15:51:35 meichel 00505 * Updated copyright header 00506 * 00507 * Revision 1.1 2000/03/02 12:42:57 joergr 00508 * Added new class comprising all general purpose helper functions (first 00509 * entry: strlcpy - a mixture of strcpy and strncpy). 00510 * 00511 * 00512 * 00513 */