]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/helper_funcs.h
Controller-view split of Graphics and Index popups.
[lyx.git] / src / frontends / controllers / helper_funcs.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2001 The LyX Team.
8  *
9  * ======================================================
10  *
11  * \file ControlCitation.h
12  * \author Angus Leeming <a.leeming@ic.ac.uk>
13  */
14
15 #ifndef HELPERFUNCS_H
16 #define HELPERFUNCS_H
17
18 #ifdef __GNUG__
19 #pragma interface
20 #endif
21
22 /** Functions to convert a string to/from a vector. */
23
24 ///
25 string const
26 getStringFromVector(std::vector<string> const & vec, string const & delim=",");
27
28 ///
29 std::vector<string> const
30 getVectorFromString(string const & str, string const & delim=",");
31
32 /** Functions to extract vectors of the first and second elems from a
33     vector<pair<A,B> >
34 */
35
36 ///
37 template <class A, class B>
38 std::vector<A> const getFirst(std::vector<std::pair<A,B> > const & pairVec)
39 {
40         typedef std::vector<std::pair<A,B> > PV;
41
42         std::vector<A> first(pairVec.size());
43
44         for (PV::size_type i = 0; i < pairVec.size(); ++i) {
45                 first[i] = pairVec[i].first;
46         }
47
48         return first;
49 }
50 ///
51 template <class A, class B>
52 std::vector<B> const getSecond(std::vector<std::pair<A,B> > const & pairVec)
53 {
54         typedef std::vector<std::pair<A,B> > PV;
55
56         std::vector<B> second(pairVec.size());
57
58         for (PV::size_type i = 0; i < pairVec.size(); ++i) {
59                 second[i] = pairVec[i].second;
60         }
61
62         return second;
63 }
64
65
66 template<class Pair>
67 struct firster {
68         typedef typename Pair::first_type first_type;
69         first_type const & operator()(Pair const & p) { return p.first; }
70 };
71
72 template<class Pair>
73 struct seconder {
74         typedef typename Pair::second_type second_type;
75         second_type const & operator()(Pair const & p) { return p.second; }
76 };
77
78 template<class Pair>
79 typename Pair::first_type const getFirst(std::vector<Pair> const & pr)
80 {
81         std::vector<typename Pair::first_type> tmp(pr.size);
82         std::transform(pr.begin(), pr.end(), tmp.begin(), firster<Pair>());
83         return tmp;
84 }
85
86 template<class Pair>
87 typename Pair::second_type const getSecond(std::vector<Pair> const & pr)
88 {
89         std::vector<typename Pair::second_type> tmp(pr.size);
90         std::transform(pr.begin(), pr.end(), tmp.begin(), seconder<Pair>());
91         return tmp;
92 }
93
94
95
96 #endif // HELPERFUNCS_H
97