XIOS  1.0
Xml I/O Server
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Définitions de type Énumérations Valeurs énumérées Amis Macros
icutil.hpp
Aller à la documentation de ce fichier.
1 /* ************************************************************************** *
2  * Copyright © IPSL/LSCE, xios, Avril 2010 - Octobre 2011 *
3  * ************************************************************************** */
4 
5 
6 #ifndef __ICUTIL_HPP__
7 #define __ICUTIL_HPP__
8 
9 #include <string>
10 #include <algorithm>
11 
12 // ///////////////////////// Définitions/Déclarations /////////////////////// //
13 
14 inline bool cstr2string(const char* cstr, int cstr_size, std::string& str)
15 {
16  if (cstr_size != -1)
17  {
18  std::string valtemp;
19  std::size_t d, f = 0;
20 
21  valtemp.append(cstr, cstr_size);
22  d = valtemp.find_first_not_of(' ');
23  f = valtemp.find_last_not_of (' ');
24  str = valtemp.substr(d, f - d + 1);
25 
26  return true;
27  }
28  else
29  return false;
30 }
31 
32 inline bool string_copy(const std::string& str, char* cstr, int cstr_size)
33 {
34  if (str.size() > cstr_size)
35  return false;
36  else
37  {
38  std::fill(cstr, cstr + cstr_size, ' ');
39  str.copy(cstr, cstr_size);
40  return true;
41  }
42 }
43 
44 #endif // __ICUTIL_HPP__
ifstream f(fileToReadWrite_.c_str())
bool string_copy(const std::string &str, char *cstr, int cstr_size)
Definition: icutil.hpp:32
bool cstr2string(const char *cstr, int cstr_size, std::string &str)
Definition: icutil.hpp:14