]> git.lyx.org Git - lyx.git/blob - src/FloatList.cpp
28d37ecb021f682200a0736db5f84066ef35d634
[lyx.git] / src / FloatList.cpp
1 /**
2  * \file FloatList.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "FloatList.h"
14 #include "Floating.h"
15
16 using namespace std;
17
18 namespace lyx {
19
20 // This class is now mostly finished, except one thing, it is a global
21 // object. This will not do. The user (and layout files) are free to
22 // create floats and modify them to fit into a certain document. So it is
23 // pretty clear that each layout needs its own list, as do documents.
24 // However this is also not enough since we really want the user to be
25 // able to create "presistent" floats, in the sense that a user created
26 // float can be used across sessions and across documents. So we need a
27 // global¹ floatlist as well. The interaction between these are not quite
28 // clear, but it seems natural that the definition found in the document
29 // takes precedence.
30 // We also have the issue about what get stored _in_ the lyx file.
31 //
32 // ¹ not absolutely global but somewhere where documents,layouts and
33 // the bufferview can have access to it.
34 //
35 // Lgb
36
37 FloatList::FloatList()
38 {
39 }
40
41
42 FloatList::const_iterator FloatList::begin() const
43 {
44         return list.begin();
45 }
46
47
48 FloatList::const_iterator FloatList::end() const
49 {
50         return list.end();
51 }
52
53
54 void FloatList::newFloat(Floating const & fl)
55 {
56         list[fl.type()] = fl;
57 }
58
59
60 string const FloatList::defaultPlacement(string const & t) const
61 {
62         List::const_iterator cit = list.find(t);
63         if (cit != list.end())
64                 return cit->second.placement();
65         return string();
66 }
67
68
69 bool FloatList::typeExist(string const & t) const
70 {
71         List::const_iterator cit = list.find(t);
72         return cit != list.end();
73 }
74
75
76 Floating const & FloatList::getType(string const & t) const
77 {
78         // I wish we could use exceptions
79         List::const_iterator cit = list.find(t);
80         if (cit != list.end())
81                 return cit->second;
82 #ifdef HAVE_EXCEPTIONS
83         throw UnknownFloatType(t);
84 #else
85         static Floating empty_float;
86         return empty_float;
87 #endif
88 }
89
90
91 void FloatList::erase(string const & t)
92 {
93         list.erase(t);
94 }
95
96
97 FloatList::const_iterator FloatList::operator[](string const & t) const
98 {
99         return list.find(t);
100 }
101
102
103 } // namespace lyx