[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> |
---|
| 10 | #include <string.h> |
---|
| 11 | // ///////////////////////// Définitions/Déclarations /////////////////////// // |
---|
| 12 | |
---|
| 13 | inline bool cstr2string(const char * cstr, int cstr_size, std::string & str) |
---|
| 14 | { |
---|
| 15 | std::string valtemp; |
---|
| 16 | std::size_t d, f = 0; |
---|
| 17 | if (cstr_size != -1) |
---|
| 18 | { |
---|
| 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); |
---|
| 24 | } |
---|
| 25 | else |
---|
| 26 | { |
---|
| 27 | return (false); |
---|
| 28 | } |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | inline bool string_copy(const string& str, char* cstr,int cstr_size) |
---|
| 32 | { |
---|
| 33 | |
---|
| 34 | if (str.size()>cstr_size) return false ; |
---|
| 35 | else |
---|
| 36 | { |
---|
| 37 | std::memset (cstr,' ',cstr_size); |
---|
| 38 | str.copy(cstr,cstr_size) ; |
---|
| 39 | return true ; |
---|
| 40 | } |
---|
| 41 | } |
---|
[369] | 42 | /* |
---|
[325] | 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 | } |
---|
[369] | 66 | */ |
---|
[325] | 67 | |
---|
| 68 | #endif // __ICUTIL_HPP__ |
---|