[325] | 1 | /* ************************************************************************** * |
---|
[335] | 2 | * Copyright © IPSL/LSCE, xios, Avril 2010 - Octobre 2011 * |
---|
[325] | 3 | * ************************************************************************** */ |
---|
| 4 | |
---|
| 5 | #include <boost/multi_array.hpp> |
---|
| 6 | |
---|
[1542] | 7 | #include <memory> |
---|
| 8 | |
---|
[591] | 9 | #include "xios.hpp" |
---|
[325] | 10 | |
---|
[352] | 11 | #include "attribute_template.hpp" |
---|
| 12 | #include "object_template.hpp" |
---|
| 13 | #include "group_template.hpp" |
---|
[325] | 14 | |
---|
| 15 | #include "calendar_type.hpp" |
---|
| 16 | |
---|
| 17 | #include "icutil.hpp" |
---|
[347] | 18 | #include "timer.hpp" |
---|
[352] | 19 | #include "context.hpp" |
---|
[325] | 20 | |
---|
| 21 | extern "C" |
---|
| 22 | { |
---|
| 23 | // /////////////////////////////// Définitions ////////////////////////////// // |
---|
| 24 | |
---|
| 25 | // ----------------------- Redéfinition de types ---------------------------- |
---|
| 26 | |
---|
| 27 | typedef enum { D360 = 0 , ALLLEAP, NOLEAP, JULIAN, GREGORIAN } XCalendarType ; |
---|
| 28 | |
---|
[345] | 29 | typedef xios::CContext * XContextPtr; |
---|
[325] | 30 | |
---|
| 31 | // ------------------------ Création des handle ----------------------------- |
---|
[545] | 32 | |
---|
[325] | 33 | void cxios_context_handle_create (XContextPtr * _ret, const char * _id, int _id_len) |
---|
[1622] | 34 | TRY |
---|
[325] | 35 | { |
---|
[545] | 36 | std::string id; |
---|
[325] | 37 | if (!cstr2string(_id, _id_len, id)) return; |
---|
[347] | 38 | CTimer::get("XIOS").resume() ; |
---|
[545] | 39 | |
---|
[347] | 40 | std::vector<xios::CContext*> def_vector = |
---|
[346] | 41 | xios::CContext::getRoot()->getChildList(); |
---|
[325] | 42 | |
---|
| 43 | for (std::size_t i = 0; i < def_vector.size(); i++) |
---|
[393] | 44 | { |
---|
[325] | 45 | if (def_vector[i]->getId().compare(id) == 0) |
---|
[393] | 46 | { |
---|
| 47 | *_ret = def_vector[i]; |
---|
| 48 | CTimer::get("XIOS").suspend() ; |
---|
| 49 | return; |
---|
| 50 | } |
---|
[325] | 51 | } |
---|
[347] | 52 | CTimer::get("XIOS").suspend() ; |
---|
[393] | 53 | ERROR("void cxios_context_handle_create (XContextPtr * _ret, const char * _id, int _id_len)", |
---|
| 54 | << "Context "<<id<<" unknown"); |
---|
[325] | 55 | // Lever une exeception ici |
---|
| 56 | } |
---|
[1622] | 57 | CATCH_DUMP_STACK |
---|
[545] | 58 | |
---|
[325] | 59 | // ------------------------ Changements de contextes ------------------------ |
---|
[545] | 60 | |
---|
| 61 | void cxios_context_get_current(XContextPtr* context) |
---|
[1622] | 62 | TRY |
---|
[545] | 63 | { |
---|
| 64 | CTimer::get("XIOS").resume(); |
---|
| 65 | *context = CContext::getCurrent(); |
---|
| 66 | CTimer::get("XIOS").suspend(); |
---|
| 67 | } |
---|
[1622] | 68 | CATCH_DUMP_STACK |
---|
[545] | 69 | |
---|
[325] | 70 | void cxios_context_set_current(XContextPtr context, bool withswap) |
---|
[1622] | 71 | TRY |
---|
[325] | 72 | { |
---|
[347] | 73 | CTimer::get("XIOS").resume() ; |
---|
[346] | 74 | CContext::setCurrent(context->getId()); |
---|
[347] | 75 | CTimer::get("XIOS").suspend() ; |
---|
[325] | 76 | } |
---|
[1622] | 77 | CATCH_DUMP_STACK |
---|
[545] | 78 | |
---|
[325] | 79 | // -------------------- Vérification des identifiants ----------------------- |
---|
| 80 | |
---|
| 81 | void cxios_context_valid_id (bool * _ret, const char * _id, int _id_len) |
---|
[1622] | 82 | TRY |
---|
[325] | 83 | { |
---|
| 84 | std::string id; |
---|
| 85 | if (!cstr2string(_id, _id_len, id)) return; |
---|
[545] | 86 | |
---|
[520] | 87 | CTimer::get("XIOS").resume(); |
---|
[347] | 88 | std::vector<xios::CContext*> def_vector = |
---|
[346] | 89 | xios::CContext::getRoot()->getChildList(); |
---|
[325] | 90 | |
---|
[520] | 91 | *_ret = false; |
---|
[325] | 92 | for (std::size_t i = 0; i < def_vector.size(); i++) |
---|
[520] | 93 | { |
---|
| 94 | if (def_vector[i]->getId().compare(id) == 0) |
---|
| 95 | { |
---|
[325] | 96 | *_ret = true; |
---|
[520] | 97 | break; |
---|
| 98 | } |
---|
[325] | 99 | } |
---|
[520] | 100 | CTimer::get("XIOS").suspend(); |
---|
[325] | 101 | } |
---|
[1622] | 102 | CATCH_DUMP_STACK |
---|
[325] | 103 | } // extern "C" |
---|