Xcos MVC: add ParamsAdapter
[scilab.git] / scilab / modules / scicos / src / cpp / view_scilab / Adapters.cpp
1 /*
2  *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  *  Copyright (C) 2014-2014 - Scilab Enterprises - Clement DAVID
4  *
5  *  This file must be used under the terms of the CeCILL.
6  *  This source file is licensed as described in the file COPYING, which
7  *  you should have received as part of this distribution.  The terms
8  *  are also available at
9  *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10  *
11  */
12
13 #include <algorithm>
14
15 #include "Adapters.hxx"
16
17 #include "BlockAdapter.hxx"
18 #include "CprAdapter.hxx"
19 #include "DiagramAdapter.hxx"
20 #include "GraphicsAdapter.hxx"
21 #include "LinkAdapter.hxx"
22 #include "ModelAdapter.hxx"
23 #include "ParamsAdapter.hxx"
24 #include "StateAdapter.hxx"
25 #include "TextAdapter.hxx"
26
27 namespace org_scilab_modules_scicos
28 {
29 namespace view_scilab
30 {
31
32 Adapters Adapters::m_instance = Adapters();
33
34 Adapters& Adapters::instance()
35 {
36     return m_instance;
37 }
38
39 Adapters::Adapters()
40 {
41     /*
42      * Create the supported data types list
43      */
44     adapters = adapters_t();
45     // we assume that the INVALID_ADAPTER is set at end of the enum
46     adapters.reserve(INVALID_ADAPTER);
47
48     adapters.push_back(adapter_t(view_scilab::BlockAdapter::getSharedTypeStr(), BLOCK_ADAPTER));
49     adapters.push_back(adapter_t(view_scilab::CprAdapter::getSharedTypeStr(), CPR_ADAPTER));
50     adapters.push_back(adapter_t(L"Deleted", DELETED_ADAPTER));
51     adapters.push_back(adapter_t(view_scilab::DiagramAdapter::getSharedTypeStr(), DIAGRAM_ADAPTER));
52     adapters.push_back(adapter_t(view_scilab::GraphicsAdapter::getSharedTypeStr(), GRAPHIC_ADAPTER));
53     adapters.push_back(adapter_t(view_scilab::LinkAdapter::getSharedTypeStr(), LINK_ADAPTER));
54     adapters.push_back(adapter_t(view_scilab::ModelAdapter::getSharedTypeStr(), MODEL_ADAPTER));
55     adapters.push_back(adapter_t(view_scilab::ParamsAdapter::getSharedTypeStr(), PARAMS_ADAPTER));
56     adapters.push_back(adapter_t(view_scilab::StateAdapter::getSharedTypeStr(), STATE_ADAPTER));
57     adapters.push_back(adapter_t(view_scilab::TextAdapter::getSharedTypeStr(), TEXT_ADAPTER));
58
59     std::sort(adapters.begin(), adapters.end());
60 }
61
62 Adapters::~Adapters()
63 {
64     adapters.clear();
65 }
66
67 Adapters::adapters_index_t Adapters::lookup_by_typename(const std::wstring& name)
68 {
69     adapters_t::iterator it = std::lower_bound(adapters.begin(), adapters.end(), name);
70     if (it != adapters.end() && !(name < it->name))
71     {
72         return it->kind;
73     }
74     return INVALID_ADAPTER;
75 }
76
77 } /* namespace view_scilab */
78 } /* namespace org_scilab_modules_scicos */