Changeset 793


Ignore:
Timestamp:
11/19/15 16:55:16 (8 years ago)
Author:
rlacroix
Message:

Fortran interface: Make the compilation of some helper functions more resiliant.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/interface/c/icutil.hpp

    r501 r793  
    88 
    99#include <string> 
    10 #include <string.h> 
     10#include <algorithm> 
     11 
    1112// ///////////////////////// Définitions/Déclarations /////////////////////// // 
    1213 
    13 inline bool cstr2string(const char * cstr, int cstr_size, std::string & str) 
     14inline bool cstr2string(const char* cstr, int cstr_size, std::string& str) 
    1415{ 
    15   std::string valtemp; 
    16   std::size_t d, f = 0; 
    17   if (cstr_size != -1)  
     16  if (cstr_size != -1) 
    1817  {  
    19      valtemp.append (cstr, cstr_size); 
    20      d = valtemp.find_first_not_of(' '); 
    21      f = valtemp.find_last_not_of (' '); 
    22      str = valtemp.substr(d, f-d+1);  
    23      return (true); 
     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; 
    2427  } 
    2528  else 
    26   { 
    27      return (false); 
    28   }   
     29     return false; 
    2930} 
    3031 
    31 inline bool string_copy(const string& str, char* cstr,int cstr_size) 
     32inline bool string_copy(const std::string& str, char* cstr, int cstr_size) 
    3233{ 
    33    
    34   if (str.size()>cstr_size) return false ; 
     34  if (str.size() > cstr_size) 
     35    return false; 
    3536  else 
    3637  { 
    37     std::memset (cstr,' ',cstr_size); 
    38     str.copy(cstr,cstr_size) ; 
    39     return true ; 
     38    std::fill(cstr, cstr + cstr_size, ' '); 
     39    str.copy(cstr, cstr_size); 
     40    return true; 
    4041  } 
    4142} 
    42 /* 
    43   template<class T> 
    44   inline  bool array_copy(ARRAY(T,1) array_in, T* array_out, size_t extent1) 
    45   { 
    46     if (array_in->num_elements() != extent1) return false ; 
    47     std::copy(array_in->data(), array_in->data() + array_in->num_elements(), array_out); 
    48     return true ; 
    49   } 
    50  
    51   template<class T> 
    52   inline  bool array_copy(ARRAY(T,2) array_in, T* array_out, size_t extent1, size_t extent2) 
    53   { 
    54     if (array_in->num_elements() != extent1*extent2) return false ; 
    55     std::copy(array_in->data(), array_in->data() + array_in->num_elements(), array_out); 
    56     return true ; 
    57   } 
    58  
    59   template<class T> 
    60   inline  bool array_copy(ARRAY(T,3) array_in, T* array_out, size_t extent1, size_t extent2, size_t extent3) 
    61   { 
    62     if (array_in->num_elements() != extent1*extent2*extent3) return false ; 
    63     std::copy(array_in->data(), array_in->data() + array_in->num_elements(), array_out); 
    64     return true ; 
    65   }         
    66 */ 
    6743 
    6844#endif // __ICUTIL_HPP__ 
Note: See TracChangeset for help on using the changeset viewer.