cbutils.h 1.47 KB
/*=========================================================================
  Program:   cesbio-utils
  Language:  C++

  Copyright (c) CESBIO. All rights reserved.

  See otb-bv-copyright.txt for details.

  This software is distributed WITHOUT ANY WARRANTY; without even
  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __CBUTILS_H
#define __CBUTILS_H

#include <boost/algorithm/string.hpp>
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>


namespace cbutils
{

namespace string
{
std::vector<std::string> split(const std::string& str, 
                               const char* separators = "\t ")
{  std::vector< std::string > tokens;
  boost::split(tokens, str, boost::is_any_of(separators), boost::token_compress_on);
  return tokens;
}
} //end ns string

namespace file
{
std::vector<std::string> readlines(const std::string& fname)
{
  std::ifstream ifs(fname);
  std::vector<std::string> lines{};
  std::string line{};
  while(ifs.good())
    {
    std::getline(ifs, line);
    lines.emplace_back(line);
    }
  return lines;
}
}//end ns file

namespace seq
{
template <typename Seq> Seq tail(const Seq& s)
{
  Seq result{};
  auto head = std::begin(s);
  std::advance(head,1);
  std::copy(head, std::end(s), std::back_inserter(result));
  return result;

}
}// end ns seq

}//end ns cbutils

#endif