Last change
on this file since 2328 was
793,
checked in by rlacroix, 9 years ago
|
Fortran interface: Make the compilation of some helper functions more resiliant.
|
-
Property copyright set to
Software name : XIOS (Xml I/O Server) http://forge.ipsl.jussieu.fr/ioserver Creation date : January 2009 Licence : CeCCIL version2 see license file in root directory : Licence_CeCILL_V2-en.txt or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement) CNRS/IPSL (Institut Pierre Simon Laplace) Project Manager : Yann Meurdesoif yann.meurdesoif@cea.fr
|
File size:
1.0 KB
|
Rev | Line | |
---|
[325] | 1 | /* ************************************************************************** * |
---|
[335] | 2 | * Copyright © IPSL/LSCE, xios, Avril 2010 - Octobre 2011 * |
---|
[325] | 3 | * ************************************************************************** */ |
---|
| 4 | |
---|
| 5 | |
---|
| 6 | #ifndef __ICUTIL_HPP__ |
---|
| 7 | #define __ICUTIL_HPP__ |
---|
| 8 | |
---|
| 9 | #include <string> |
---|
[793] | 10 | #include <algorithm> |
---|
| 11 | |
---|
[325] | 12 | // ///////////////////////// Définitions/Déclarations /////////////////////// // |
---|
| 13 | |
---|
[793] | 14 | inline bool cstr2string(const char* cstr, int cstr_size, std::string& str) |
---|
[325] | 15 | { |
---|
[793] | 16 | if (cstr_size != -1) |
---|
[325] | 17 | { |
---|
[793] | 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; |
---|
[325] | 27 | } |
---|
| 28 | else |
---|
[793] | 29 | return false; |
---|
[325] | 30 | } |
---|
| 31 | |
---|
[793] | 32 | inline bool string_copy(const std::string& str, char* cstr, int cstr_size) |
---|
[325] | 33 | { |
---|
[793] | 34 | if (str.size() > cstr_size) |
---|
| 35 | return false; |
---|
[325] | 36 | else |
---|
| 37 | { |
---|
[793] | 38 | std::fill(cstr, cstr + cstr_size, ' '); |
---|
| 39 | str.copy(cstr, cstr_size); |
---|
| 40 | return true; |
---|
[325] | 41 | } |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | #endif // __ICUTIL_HPP__ |
---|
Note: See
TracBrowser
for help on using the repository browser.