OFFIS DCMTK  Version 3.6.0
ofstd.h
1 /*
2  *
3  * Copyright (C) 2000-2010, OFFIS e.V.
4  * All rights reserved. See COPYRIGHT file for details.
5  *
6  * This software and supporting documentation were developed by
7  *
8  * OFFIS e.V.
9  * R&D Division Health
10  * Escherweg 2
11  * D-26121 Oldenburg, Germany
12  *
13  *
14  * Module: ofstd
15  *
16  * Author: Joerg Riesmeier, Marco Eichelberg
17  *
18  * Purpose: Class for various helper functions
19  *
20  * Last Update: $Author: joergr $
21  * Update Date: $Date: 2010-10-14 13:15:50 $
22  * CVS/RCS Revision: $Revision: 1.42 $
23  * Status: $State: Exp $
24  *
25  * CVS/RCS Log at end of file
26  *
27  */
28 
29 
30 #ifndef OFSTD_H
31 #define OFSTD_H
32 
33 #include "dcmtk/config/osconfig.h"
34 #include "dcmtk/ofstd/oflist.h" /* for class OFList */
35 #include "dcmtk/ofstd/ofstring.h" /* for class OFString */
36 #include "dcmtk/ofstd/oftypes.h" /* for OFBool */
37 #include "dcmtk/ofstd/ofcond.h" /* for OFCondition */
38 
39 #define INCLUDE_CSTDLIB
40 #define INCLUDE_CSTDIO
41 #define INCLUDE_CSTRING
42 #define INCLUDE_UNISTD
43 #include "dcmtk/ofstd/ofstdinc.h"
44 
45 BEGIN_EXTERN_C
46 #ifdef HAVE_SYS_TYPES_H
47 #include <sys/types.h> /* for size_t */
48 #endif
49 END_EXTERN_C
50 
51 
52 /*---------------------*
53  * class declaration *
54  *---------------------*/
55 
60 {
61 
62  public:
63 
64  // --- type definitions ---
65 
69  {
78  };
79 
80  // --- string functions ---
81 
97  static inline size_t strlcpy(char *dst, const char *src, size_t siz)
98  {
99 #ifdef HAVE_STRLCPY
100  return ::strlcpy(dst, src, siz);
101 #else
102  return my_strlcpy(dst, src, siz);
103 #endif
104  }
105 
123  static inline size_t strlcat(char *dst, const char *src, size_t siz)
124  {
125 #ifdef HAVE_STRLCAT
126  return ::strlcat(dst, src, siz);
127 #else
128  return my_strlcat(dst, src, siz);
129 #endif
130  }
131 
142  static const char *strerror(const int errnum,
143  char *buf,
144  const size_t buflen);
145 
151  static OFString &toUpper(OFString &result,
152  const OFString &value);
153 
159  static OFString &toUpper(OFString &value);
160 
166  static OFString &toLower(OFString &result,
167  const OFString &value);
168 
174  static OFString &toLower(OFString &value);
175 
176  // --- file system functions ---
177 
184  static OFBool pathExists(const OFString &pathName);
185 
192  static OFBool fileExists(const OFString &fileName);
193 
200  static OFBool dirExists(const OFString &dirName);
201 
207  static OFBool isReadable(const OFString &pathName);
208 
214  static OFBool isWriteable(const OFString &pathName);
215 
227  static OFString &getDirNameFromPath(OFString &result,
228  const OFString &pathName,
229  const OFBool assumeDirName = OFTrue);
230 
242  static OFString &getFilenameFromPath(OFString &result,
243  const OFString &pathName,
244  const OFBool assumeFilename = OFTrue);
245 
257  static OFString &normalizeDirName(OFString &result,
258  const OFString &dirName,
259  const OFBool allowEmptyDirName = OFFalse);
260 
276  static OFString &combineDirAndFilename(OFString &result,
277  const OFString &dirName,
278  const OFString &fileName,
279  const OFBool allowEmptyDirName = OFFalse);
280 
292  const OFString &rootDir,
293  const OFString &pathName,
294  const OFBool allowLeadingPathSeparator = OFTrue);
295 
308  static size_t searchDirectoryRecursively(const OFString &directory,
309  OFList<OFString> &fileList,
310  const OFString &pattern /*= ""*/, // default parameter value not
311  const OFString &dirPrefix /*= ""*/, // supported by Sun CC 2.0.1 :-/
312  const OFBool recurse = OFTrue);
313 
318  static OFBool deleteFile(const OFString &filename);
319 
324  static size_t getFileSize(const OFString &filename);
325 
326  // --- other functions ---
327 
336  static OFBool checkForMarkupConversion(const OFString &sourceString,
337  const OFBool convertNonASCII = OFFalse);
338 
359  static OFCondition convertToMarkupStream(STD_NAMESPACE ostream &out,
360  const OFString &sourceString,
361  const OFBool convertNonASCII = OFFalse,
362  const E_MarkupMode markupMode = MM_XML,
363  const OFBool newlineAllowed = OFFalse);
364 
385  static const OFString &convertToMarkupString(const OFString &sourceString,
386  OFString &markupString,
387  const OFBool convertNonASCII = OFFalse,
388  const E_MarkupMode markupMode = MM_XML,
389  const OFBool newlineAllowed = OFFalse);
390 
404  static OFCondition encodeBase64(STD_NAMESPACE ostream &out,
405  const unsigned char *data,
406  const size_t length,
407  const size_t width = 0);
408 
422  static const OFString &encodeBase64(const unsigned char *data,
423  const size_t length,
424  OFString &result,
425  const size_t width = 0);
426 
440  static size_t decodeBase64(const OFString &data,
441  unsigned char *&result);
442 
477  static double atof(const char *s,
478  OFBool *success = NULL);
479 
503  static void ftoa(char *target,
504  size_t targetSize,
505  double value,
506  unsigned int flags = 0,
507  int width = 0,
508  int precision = -1);
509 
514 
516  static const unsigned int ftoa_format_e;
517 
519  static const unsigned int ftoa_format_f;
520 
522  static const unsigned int ftoa_uppercase;
523 
528  static const unsigned int ftoa_alternate;
529 
531  static const unsigned int ftoa_leftadj;
532 
534  static const unsigned int ftoa_zeropad;
535 
537 
543  static inline unsigned int sleep(unsigned int seconds)
544  {
545 #if defined(HAVE_SLEEP) && !defined(HAVE_WINDOWS_H)
546  // we only use this call if HAVE_WINDOWS_H is undefined because
547  // MinGW has sleep() but no prototype
548  return ::sleep(seconds);
549 #else
550  return my_sleep(seconds);
551 #endif
552  }
553 
557  static long getProcessID();
558 
564  static inline OFBool check32BitAddOverflow(const Uint32 summand1,
565  const Uint32 summand2)
566  {
567  return (0xffffffff - summand1 < summand2);
568  }
569 
570  private:
571 
580  static size_t my_strlcpy(char *dst, const char *src, size_t siz);
581 
590  static size_t my_strlcat(char *dst, const char *src, size_t siz);
591 
597  static unsigned int my_sleep(unsigned int seconds);
598 };
599 
600 
601 #endif
602 
603 
604 /*
605  *
606  * CVS/RCS Log:
607  * $Log: ofstd.h,v $
608  * Revision 1.42 2010-10-14 13:15:50 joergr
609  * Updated copyright header. Added reference to COPYRIGHT file.
610  *
611  * Revision 1.41 2010-06-02 12:54:28 joergr
612  * Introduced new helper function strerror() which is used as a wrapper to the
613  * various approaches found on different systems.
614  *
615  * Revision 1.40 2010-05-20 09:20:13 joergr
616  * Added new method for determining the size of a given file (in bytes).
617  *
618  * Revision 1.39 2010-04-26 12:22:30 uli
619  * Fixed a some minor doxygen warnings.
620  *
621  * Revision 1.38 2010-01-21 14:43:27 joergr
622  * Added stream variant of method convertToMarkupString().
623  *
624  * Revision 1.37 2010-01-20 13:49:47 uli
625  * Added OFStandard::getProcessID().
626  *
627  * Revision 1.36 2010-01-04 16:02:23 joergr
628  * Added new method getDirNameFromPath() and enhanced existing method
629  * getFilenameFromPath().
630  *
631  * Revision 1.35 2009-08-19 10:43:37 joergr
632  * Added new string helper functions toUpper() and toLower().
633  *
634  * Revision 1.34 2009-04-27 14:26:00 joergr
635  * Added comment on absolute path names e.g. in UNC syntax.
636  *
637  * Revision 1.33 2009-03-13 09:47:20 joergr
638  * Added new helper function getFilenameFromPath().
639  *
640  * Revision 1.32 2009-03-05 13:33:12 onken
641  * Added helper function that checks whether a given Uint32 addition would
642  * result in an overflow.
643  *
644  * Revision 1.31 2008-08-28 10:44:36 onken
645  * Introduced deleteFile() method.
646  *
647  * Revision 1.30 2008-07-15 09:49:33 joergr
648  * Removed unused function OFStandard::stringMatchesCharacterSet().
649  *
650  * Revision 1.29 2008-04-28 12:03:24 joergr
651  * Adapted OFStandard::checkForMarkupConversion() to the new behavior of
652  * parameter "convertNonASCII" of OFStandard::convertToMarkupString().
653  * Fixed API documentation of OFStandard::convertToMarkupString().
654  *
655  * Revision 1.28 2007/11/15 16:11:43 joergr
656  * Introduced new markup mode for convertToMarkupString() that is used to
657  * distinguish between HTML, HTML 3.2, XHTML and XML.
658  *
659  * Revision 1.27 2007/06/26 16:21:14 joergr
660  * Added new variant of encodeBase64() method that outputs directly to a stream
661  * (avoids using a memory buffer for large binary data).
662  *
663  * Revision 1.26 2007/03/09 14:54:59 joergr
664  * Added optional parameter "recurse" to searchDirectoryRecursively().
665  *
666  * Revision 1.25 2007/02/20 13:12:27 joergr
667  * Added function that removes a given prefix from a pathname (e.g. root dir).
668  *
669  * Revision 1.24 2006/10/13 10:04:03 joergr
670  * Added new helper function that allows to check whether the conversion to an
671  * HTML/XML markup string is required.
672  *
673  * Revision 1.23 2005/12/08 16:06:04 meichel
674  * Changed include path schema for all DCMTK header files
675  *
676  * Revision 1.22 2004/08/03 11:45:42 meichel
677  * Headers libc.h and unistd.h are now included via ofstdinc.h
678  *
679  * Revision 1.21 2004/04/16 12:43:26 joergr
680  * Restructured code to avoid default parameter values for "complex types" like
681  * OFString. Required for Sun CC 2.0.1.
682  *
683  * Revision 1.20 2003/12/05 10:37:41 joergr
684  * Removed leading underscore characters from preprocessor symbols (reserved
685  * symbols). Updated copyright date where appropriate.
686  *
687  * Revision 1.19 2003/08/12 13:10:10 joergr
688  * Improved implementation of normalizeDirName().
689  *
690  * Revision 1.18 2003/07/17 14:53:24 joergr
691  * Added new function searchDirectoryRecursively().
692  * Updated documentation to get rid of doxygen warnings.
693  *
694  * Revision 1.17 2003/07/04 13:31:51 meichel
695  * Fixed issues with compiling with HAVE_STD_STRING
696  *
697  * Revision 1.16 2003/07/03 14:23:50 meichel
698  * Minor changes to make OFStandard::sleep compile on MinGW
699  *
700  * Revision 1.15 2003/06/06 09:43:54 meichel
701  * Added static sleep function in class OFStandard. This replaces the various
702  * calls to sleep(), Sleep() and usleep() throughout the toolkit.
703  *
704  * Revision 1.14 2003/04/17 15:50:51 joergr
705  * Replace LF and CR by &#10; and &#13; in XML mode instead of &#182; (para).
706  *
707  * Revision 1.13 2003/03/12 14:57:47 joergr
708  * Added apostrophe (') to the list of characters to be replaced by the
709  * corresponding HTML/XML mnenonic.
710  *
711  * Revision 1.12 2002/12/13 13:45:33 meichel
712  * Removed const from decodeBase64() return code, needed on MIPSpro
713  *
714  * Revision 1.11 2002/12/05 13:49:36 joergr
715  * Moved definition of ftoa() processing flags to implementation file to avoid
716  * compiler errors (e.g. on Sun CC 2.0.1).
717  *
718  * Revision 1.10 2002/12/04 09:13:00 meichel
719  * Implemented a locale independent function OFStandard::ftoa() that
720  * converts double to string and offers all the flexibility of the
721  * sprintf family of functions.
722  *
723  * Revision 1.9 2002/11/27 11:23:06 meichel
724  * Adapted module ofstd to use of new header file ofstdinc.h
725  *
726  * Revision 1.8 2002/07/02 15:17:57 wilkens
727  * Added function OFStandard::stringMatchesCharacterSet(...).
728  *
729  * Revision 1.7 2002/06/20 12:02:38 meichel
730  * Implemented a locale independent function OFStandard::atof() that
731  * converts strings to double and optionally returns a status code
732  *
733  * Revision 1.6 2002/05/14 08:12:51 joergr
734  * Added support for Base64 (MIME) encoding and decoding.
735  *
736  * Revision 1.5 2002/04/25 09:13:52 joergr
737  * Moved helper function which converts a conventional character string to an
738  * HTML/XML mnenonic string (e.g. using "&lt;" instead of "<") from module
739  * dcmsr to ofstd.
740  *
741  * Revision 1.4 2002/04/11 12:06:42 joergr
742  * Added general purpose routines to check whether a file exists, a path points
743  * to a directory or a file, etc.
744  *
745  * Revision 1.3 2001/12/04 16:57:15 meichel
746  * Implemented strlcpy and strlcat routines compatible with the
747  * corresponding BSD libc routines in class OFStandard
748  *
749  * Revision 1.2 2001/06/01 15:51:35 meichel
750  * Updated copyright header
751  *
752  * Revision 1.1 2000/03/02 12:42:57 joergr
753  * Added new class comprising all general purpose helper functions (first
754  * entry: strlcpy - a mixture of strcpy and strncpy).
755  *
756  *
757  *
758  */


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2