source: XIOS/trunk/src/interface/c/icutil.hpp @ 836

Last change on this file since 836 was 793, checked in by rlacroix, 8 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
Line 
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
14inline 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
32inline 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__
Note: See TracBrowser for help on using the repository browser.