cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
service.h
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2022 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 
4 #ifndef SERVICE_H_
5 #define SERVICE_H_
6 
7 #include <string>
8 #include <vector>
9 
10 // remove whitespace from the end of a string
11 void trimTrailingWhiteSpace( std::string &str );
12 // remove whitespace form the end of a char array
13 void trimTrailingWhiteSpace( char *str );
14 
22 
24 void Split(const std::string& str, // input string
25  const std::string& sep, // separator, may be multiple characters
26  std::vector<std::string>& lst, // the separated items will be appended here
27  split_mode mode); // see above
28 
29 inline bool FindAndReplace(string& str,
30  const string& substr,
31  const string& newstr)
32 {
33  string::size_type ptr = str.find( substr );
34  if( ptr != string::npos )
35  str.replace( ptr, substr.length(), newstr );
36  return ptr != string::npos;
37 }
38 
39 inline bool FindAndErase(string& str,
40  const string& substr)
41 {
42  return FindAndReplace( str, substr, "" );
43 }
44 
45 void service(double tau, double a, double beta);
46 
48 inline void wr_block(const void *ptr,
49  size_t len,
50  FILE *fdes)
51 {
52  if( fwrite(ptr,len,size_t(1),fdes) != 1 ) {
53  printf( "wr_block: error writing to file\n" );
54  fclose(fdes);
56  }
57 }
58 
60 inline void wr_block(const void *ptr,
61  size_t len,
62  const char *fnam)
63 {
64  FILE *fdes = open_data( fnam, "wb" );
65  wr_block( ptr, len, fdes );
66  fclose(fdes);
67 }
68 
70 inline void rd_block(void *ptr,
71  size_t len,
72  FILE *fdes)
73 {
74  if( fread(ptr,len,size_t(1),fdes) != 1 ) {
75  printf( "rd_block: error reading from file\n" );
76  fclose(fdes);
78  }
79 }
80 
82 inline void rd_block(void *ptr,
83  size_t len,
84  const char *fnam)
85 {
86  FILE *fdes = open_data( fnam, "rb", AS_LOCAL_ONLY );
87  rd_block( ptr, len, fdes );
88  fclose(fdes);
89 }
90 
91 #endif /* SERVICE_ */
bool FindAndErase(string &str, const string &substr)
Definition: service.h:39
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
Definition: cpu.cpp:765
split_mode
Definition: service.h:21
void trimTrailingWhiteSpace(string &str)
Definition: service.cpp:153
void service(double tau, double a, double beta)
#define EXIT_FAILURE
Definition: cddefines.h:168
void rd_block(void *ptr, size_t len, FILE *fdes)
Definition: service.h:70
#define cdEXIT(FAIL)
Definition: cddefines.h:482
void wr_block(const void *ptr, size_t len, FILE *fdes)
Definition: service.h:48
void Split(const string &str, const string &sep, vector< string > &lst, split_mode mode)
Definition: service.cpp:106
bool FindAndReplace(string &str, const string &substr, const string &newstr)
Definition: service.h:29