2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2001 The LyX Team.
9 * ======================================================
11 * \file ControlCitation.h
12 * \author Angus Leeming <a.leeming@ic.ac.uk>
18 #include <utility> // pair
24 /** Functions to convert a string to/from a vector. */
28 getStringFromVector(std::vector<string> const & vec, string const & delim=",");
31 std::vector<string> const
32 getVectorFromString(string const & str, string const & delim=",");
36 /** Launch a file dialog and return the chosen file.
37 filename: a suggested filename.
38 title: the title of the dialog.
40 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
42 string const browseFile(LyXView *lv, string const & filename,
44 string const & pattern,
45 std::pair<string,string> const & dir1,
46 std::pair<string,string> const & dir2);
48 /** Functions to extract vectors of the first and second elems from a
53 template <class A, class B>
54 std::vector<A> const getFirst(std::vector<std::pair<A,B> > const & pairVec)
56 typedef std::vector<std::pair<A,B> > PV;
58 std::vector<A> first(pairVec.size());
60 for (PV::size_type i = 0; i < pairVec.size(); ++i) {
61 first[i] = pairVec[i].first;
67 template <class A, class B>
68 std::vector<B> const getSecond(std::vector<std::pair<A,B> > const & pairVec)
70 typedef std::vector<std::pair<A,B> > PV;
72 std::vector<B> second(pairVec.size());
74 for (PV::size_type i = 0; i < pairVec.size(); ++i) {
75 second[i] = pairVec[i].second;
84 typedef typename Pair::first_type first_type;
85 first_type const & operator()(Pair const & p) { return p.first; }
90 typedef typename Pair::second_type second_type;
91 second_type const & operator()(Pair const & p) { return p.second; }
95 typename Pair::first_type const getFirst(std::vector<Pair> const & pr)
97 std::vector<typename Pair::first_type> tmp(pr.size);
98 std::transform(pr.begin(), pr.end(), tmp.begin(), firster<Pair>());
103 typename Pair::second_type const getSecond(std::vector<Pair> const & pr)
105 std::vector<typename Pair::second_type> tmp(pr.size);
106 std::transform(pr.begin(), pr.end(), tmp.begin(), seconder<Pair>());
112 #endif // HELPERFUNCS_H