1 | #include "c_interface.hpp" |
---|
2 | |
---|
3 | /* ********************************************************** */ |
---|
4 | /* CONVERSION FUNCTION */ |
---|
5 | /* ********************************************************** */ |
---|
6 | |
---|
7 | static inline std::string stringXtoStd(XString _str) |
---|
8 | { |
---|
9 | char * const temp = new char[_str.len+1](); |
---|
10 | memset(temp, '\0', _str.len+1); |
---|
11 | memcpy(temp, _str.str, _str.len); |
---|
12 | std::string _retstr(temp); |
---|
13 | size_t d = _retstr.find_first_not_of(' '); |
---|
14 | size_t f = _retstr.find_last_not_of (' '); |
---|
15 | |
---|
16 | delete[] temp; |
---|
17 | return (_retstr.substr(d, f-d+1)); |
---|
18 | } |
---|
19 | |
---|
20 | static inline XString stringXtoStd(const std::string& _str) // Non testée |
---|
21 | { |
---|
22 | XString _retstr = {new char[_str.size()](), _str.size()}; |
---|
23 | memcpy(_retstr.str, _str.c_str(), _str.size()); |
---|
24 | return (_retstr); |
---|
25 | } |
---|
26 | |
---|
27 | /* ********************************************************** */ |
---|
28 | /* HANDLE INTERFACE */ |
---|
29 | /* ********************************************************** */ |
---|
30 | |
---|
31 | void xios_handle_create_(XHandle * _ret, const XDType * const _dtype, XString _id) |
---|
32 | { |
---|
33 | // Si le handle n'est pas initialisé à 0, on ne fait aucun traitement. |
---|
34 | if (!isNullHandle(*_ret)) return; |
---|
35 | std::string __id = stringXtoStd(_id); |
---|
36 | switch(*_dtype) |
---|
37 | { |
---|
38 | /* EAXIS, EDOMAIN, EFIELD, EFILE, EGRID, GAXIS, GDOMAIN, GFIELD, GFILE, GGRID*/ |
---|
39 | case (ECONTEXT): |
---|
40 | // Si le context n'existe pas, on retourne un handle vide/nul. |
---|
41 | if (!Context::HasContext(__id)) { *_ret = NULLHANDLE; return ; } |
---|
42 | _ret->data_type = *_dtype; |
---|
43 | _ret->data_ptr = Context::GetContext(__id); |
---|
44 | return ; |
---|
45 | |
---|
46 | default : |
---|
47 | *_ret = NULLHANDLE; |
---|
48 | return ; |
---|
49 | }; |
---|
50 | } |
---|
51 | |
---|
52 | /* ********************************************************** */ |
---|
53 | /* XML INTERFACE */ |
---|
54 | /* ********************************************************** */ |
---|
55 | |
---|
56 | void xios_xml_parse_file_(XString _filename) |
---|
57 | { |
---|
58 | std::string __filename = stringXtoStd(_filename); |
---|
59 | std::ifstream __istr( __filename.c_str() , std::ifstream::in ); |
---|
60 | |
---|
61 | // On commence la lecture du flux de donnée xml. |
---|
62 | XMLNode node = XMLNode::CreateNode(__istr, Context::GetRootName()); |
---|
63 | |
---|
64 | // On parse le fichier xml noeud par noeud |
---|
65 | // (ie on construit dynamiquement notre arbre d'objets). |
---|
66 | XMLParser::Parse(node); |
---|
67 | } |
---|
68 | |
---|
69 | void xios_xml_parse_string_(XString _xmlcontent) |
---|
70 | { |
---|
71 | std::string __xmlcontent = stringXtoStd(_xmlcontent); |
---|
72 | std::istringstream __istr(__xmlcontent); |
---|
73 | |
---|
74 | // On commence la lecture du flux de donnée xml. |
---|
75 | XMLNode node = XMLNode::CreateNode(__istr, Context::GetRootName()); |
---|
76 | |
---|
77 | // On parse le fichier xml noeud par noeud |
---|
78 | // (ie on construit dynamiquement notre arbre d'objets). |
---|
79 | XMLParser::Parse(node); |
---|
80 | } |
---|
81 | |
---|
82 | /* ********************************************************** */ |
---|
83 | /* DATA TREATMENT INTERFACE */ |
---|
84 | /* ********************************************************** */ |
---|
85 | |
---|
86 | static std::vector<DataTreatment *> AllDataTreatment; |
---|
87 | |
---|
88 | static void deleteAllDataTreatment(void) |
---|
89 | { |
---|
90 | std::vector<DataTreatment *>::iterator it; |
---|
91 | for (it = AllDataTreatment.begin(); |
---|
92 | it != AllDataTreatment.end(); it++) |
---|
93 | if (*it != NULL) delete (*it); |
---|
94 | } |
---|
95 | |
---|
96 | void xios_dtreatment_new_(XHandle * _dt, const XHandle * const _hd) |
---|
97 | { |
---|
98 | static bool called = false; |
---|
99 | |
---|
100 | // Si le handle de traitement n'est pas initialisé à 0, on ne fait aucun traitement. |
---|
101 | if (!isNullHandle(*_dt) || (_hd->data_type != ECONTEXT)) return; |
---|
102 | Context* const __ctxt = (Context*) _hd->data_ptr; |
---|
103 | |
---|
104 | _dt->data_type = DTREATMENT; |
---|
105 | _dt->data_ptr = new DataTreatment(__ctxt); |
---|
106 | |
---|
107 | if (!called) |
---|
108 | { |
---|
109 | atexit (&deleteAllDataTreatment); |
---|
110 | called = true; |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | void xios_dtreatment_create_files_and_headers_(const XHandle * const _hd, const XFileType * const _ft) |
---|
115 | { |
---|
116 | if (isNullHandle(*_hd) || (_hd->data_type != DTREATMENT)) return; |
---|
117 | DataTreatment * const __dt = (DataTreatment*)_hd->data_ptr; |
---|
118 | AllDataTreatment.push_back (__dt); |
---|
119 | switch(*_ft) |
---|
120 | { |
---|
121 | case (NETCDF4): |
---|
122 | __dt->createDataOutput<NetCDF4DataOutput>(); |
---|
123 | return; |
---|
124 | // Autres formats de fichiers si disponibles... |
---|
125 | default: |
---|
126 | return; |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | /* ********************************************************** */ |
---|
131 | /* CONTEXT INTERFACE */ |
---|
132 | /* ********************************************************** */ |
---|
133 | |
---|
134 | void xios_context_set_current_(const XHandle * const _ctxt, const bool * const _wswap) |
---|
135 | { |
---|
136 | bool __wswap = (_wswap == NULL) ? false : *_wswap; |
---|
137 | if (isNullHandle(*_ctxt) || (_ctxt->data_type != ECONTEXT)) return; |
---|
138 | |
---|
139 | Context* const __ctxt = (Context*) _ctxt->data_ptr; |
---|
140 | Context::SetCurrentContext(__ctxt->getId(), __wswap) ; |
---|
141 | } |
---|
142 | |
---|