Commit 217e26c2bd2e5cfef6e2eae66ede1a45164816a3

Authored by Jordi Inglada
0 parents
Exists in master

init the repo

Showing 1 changed file with 68 additions and 0 deletions   Show diff stats
include/cbutils.h 0 → 100644
  1 +++ a/include/cbutils.h
... ... @@ -0,0 +1,68 @@
  1 +/*=========================================================================
  2 + Program: cesbio-utils
  3 + Language: C++
  4 +
  5 + Copyright (c) CESBIO. All rights reserved.
  6 +
  7 + See otb-bv-copyright.txt for details.
  8 +
  9 + This software is distributed WITHOUT ANY WARRANTY; without even
  10 + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11 + PURPOSE. See the above copyright notices for more information.
  12 +
  13 +=========================================================================*/
  14 +#ifndef __CBUTILS_H
  15 +#define __CBUTILS_H
  16 +
  17 +#include <boost/algorithm/string.hpp>
  18 +#include <vector>
  19 +#include <string>
  20 +#include <fstream>
  21 +#include <algorithm>
  22 +
  23 +
  24 +namespace cbutils
  25 +{
  26 +
  27 +namespace string
  28 +{
  29 +std::vector<std::string> split(const std::string& str,
  30 + const char* separators = "\t ")
  31 +{ std::vector< std::string > tokens;
  32 + boost::split(tokens, str, boost::is_any_of(separators), boost::token_compress_on);
  33 + return tokens;
  34 +}
  35 +} //end ns string
  36 +
  37 +namespace file
  38 +{
  39 +std::vector<std::string> readlines(const std::string& fname)
  40 +{
  41 + std::ifstream ifs(fname);
  42 + std::vector<std::string> lines{};
  43 + std::string line{};
  44 + while(ifs.good())
  45 + {
  46 + std::getline(ifs, line);
  47 + lines.emplace_back(line);
  48 + }
  49 + return lines;
  50 +}
  51 +}//end ns file
  52 +
  53 +namespace seq
  54 +{
  55 +template <typename Seq> Seq tail(const Seq& s)
  56 +{
  57 + Seq result{};
  58 + auto head = std::begin(s);
  59 + std::advance(head,1);
  60 + std::copy(head, std::end(s), std::back_inserter(result));
  61 + return result;
  62 +
  63 +}
  64 +}// end ns seq
  65 +
  66 +}//end ns cbutils
  67 +
  68 +#endif
... ...