Xcos MVC: fix some unneeded dependencies
[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 <string>
14 #include <algorithm>
15
16 #include "Adapters.hxx"
17
18 #include "BlockAdapter.hxx"
19 #include "CprAdapter.hxx"
20 #include "DiagramAdapter.hxx"
21 #include "GraphicsAdapter.hxx"
22 #include "LinkAdapter.hxx"
23 #include "ModelAdapter.hxx"
24 #include "ParamsAdapter.hxx"
25 #include "StateAdapter.hxx"
26 #include "TextAdapter.hxx"
27
28 namespace org_scilab_modules_scicos
29 {
30 namespace view_scilab
31 {
32
33 Adapters Adapters::m_instance = Adapters();
34
35 Adapters& Adapters::instance()
36 {
37     return m_instance;
38 }
39
40 Adapters::Adapters()
41 {
42     /*
43      * Create the supported data types list
44      */
45     adapters = adapters_t();
46     // we assume that the INVALID_ADAPTER is set at end of the enum
47     adapters.reserve(INVALID_ADAPTER);
48
49     adapters.push_back(adapter_t(view_scilab::BlockAdapter::getSharedTypeStr(), BLOCK_ADAPTER));
50     adapters.push_back(adapter_t(view_scilab::CprAdapter::getSharedTypeStr(), CPR_ADAPTER));
51     adapters.push_back(adapter_t(L"Deleted", DELETED_ADAPTER));
52     adapters.push_back(adapter_t(view_scilab::DiagramAdapter::getSharedTypeStr(), DIAGRAM_ADAPTER));
53     adapters.push_back(adapter_t(view_scilab::GraphicsAdapter::getSharedTypeStr(), GRAPHIC_ADAPTER));
54     adapters.push_back(adapter_t(view_scilab::LinkAdapter::getSharedTypeStr(), LINK_ADAPTER));
55     adapters.push_back(adapter_t(view_scilab::ModelAdapter::getSharedTypeStr(), MODEL_ADAPTER));
56     adapters.push_back(adapter_t(view_scilab::ParamsAdapter::getSharedTypeStr(), PARAMS_ADAPTER));
57     adapters.push_back(adapter_t(view_scilab::StateAdapter::getSharedTypeStr(), STATE_ADAPTER));
58     adapters.push_back(adapter_t(view_scilab::TextAdapter::getSharedTypeStr(), TEXT_ADAPTER));
59
60     std::sort(adapters.begin(), adapters.end());
61 }
62
63 Adapters::~Adapters()
64 {
65     adapters.clear();
66 }
67
68 Adapters::adapters_index_t Adapters::lookup_by_typename(const std::wstring& name)
69 {
70     adapters_t::iterator it = std::lower_bound(adapters.begin(), adapters.end(), name);
71     if (it != adapters.end() && !(name < it->name))
72     {
73         return it->kind;
74     }
75     return INVALID_ADAPTER;
76 }
77
78 } /* namespace view_scilab */
79 } /* namespace org_scilab_modules_scicos */