// -*- C++ -*- /* This file is part of * ====================================================== * * LyX, The Document Processor * * Copyright 2001 The LyX Team. * * ====================================================== * * \file ControlCitation.h * \author Angus Leeming */ #ifndef HELPERFUNCS_H #define HELPERFUNCS_H #ifdef __GNUG__ #pragma interface #endif /** Functions to convert a string to/from a vector. */ /// string const getStringFromVector(std::vector const & vec, string const & delim=","); /// std::vector const getVectorFromString(string const & str, string const & delim=","); /** Functions to extract vectors of the first and second elems from a vector > */ /// template std::vector const getFirst(std::vector > const & pairVec) { typedef std::vector > PV; std::vector first(pairVec.size()); for (PV::size_type i = 0; i < pairVec.size(); ++i) { first[i] = pairVec[i].first; } return first; } /// template std::vector const getSecond(std::vector > const & pairVec) { typedef std::vector > PV; std::vector second(pairVec.size()); for (PV::size_type i = 0; i < pairVec.size(); ++i) { second[i] = pairVec[i].second; } return second; } template struct firster { typedef typename Pair::first_type first_type; first_type const & operator()(Pair const & p) { return p.first; } }; template struct seconder { typedef typename Pair::second_type second_type; second_type const & operator()(Pair const & p) { return p.second; } }; template typename Pair::first_type const getFirst(std::vector const & pr) { std::vector tmp(pr.size); std::transform(pr.begin(), pr.end(), tmp.begin(), firster()); return tmp; } template typename Pair::second_type const getSecond(std::vector const & pr) { std::vector tmp(pr.size); std::transform(pr.begin(), pr.end(), tmp.begin(), seconder()); return tmp; } #endif // HELPERFUNCS_H