Changeset 91:f04d6cdf4e0a in rrlib_util


Ignore:
Timestamp:
28.08.2013 15:48:22 (6 years ago)
Author:
Jens Wettach <wettach@…>
Branch:
default
Children:
92:77b2d68da1f5, 95:f3f1f1f16eac
Phase:
public
Message:

generalized container input/output

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sFileIOUtils.h

    r84 r91  
    139139   * \note If filename has suffix ".bz2" it is compressed accordingly. 
    140140   */ 
    141   template <class T> 
    142   static bool WriteContainerToFile(const std::vector<T> &content, const std::string& filename) 
     141  template <class ConstForwardIterator> 
     142  static bool WriteContainerToFile(ConstForwardIterator begin, ConstForwardIterator end, const std::string& filename) 
    143143  { 
    144144    std::ofstream output_file_stream; 
     
    153153      { 
    154154        out.push(output_file_stream); 
    155         std::copy(content.begin(), content.end(), std::ostream_iterator<T>(out)); 
     155        std::copy(begin, end, std::ostream_iterator<typename ConstForwardIterator::value_type>(out)); 
    156156        return true; 
    157157      } 
     
    162162      if (output_file_stream) 
    163163      { 
    164         std::copy(content.begin(), content.end(), std::ostream_iterator<T>(output_file_stream)); 
     164        std::copy(begin, end, std::ostream_iterator<typename ConstForwardIterator::value_type>(output_file_stream)); 
    165165        output_file_stream.close(); 
    166166        return true; 
     
    170170  } 
    171171 
     172  template <class Container> 
     173  static bool WriteContainerToFile(const Container &container, const std::string& filename) 
     174  { 
     175    return WriteContainerToFile(container.begin(), container.end(), filename); 
     176  } 
     177 
    172178  /*! 
    173179   * \brief Reads file with given name and writes its content to given container 
     
    177183   * \note If filename has suffix ".bz2" it is decompressed accordingly before reading. 
    178184   */ 
    179   template <class T> 
    180   static bool ReadContainerFromFile(std::vector<T> &content, const std::string& filename) 
     185  template <class Container> 
     186  static bool ReadContainerFromFile(Container &container, const std::string& filename) 
    181187  { 
    182188    std::ifstream input_file_stream; 
     
    191197      { 
    192198        in.push(input_file_stream); 
    193         std::copy(std::istream_iterator<T>(in), std::istream_iterator<T>(), std::back_inserter(content)); 
     199        std::copy(std::istream_iterator<typename Container::value_type>(in), std::istream_iterator<typename Container::value_type>(), std::back_inserter(container)); 
     200        RRLIB_LOG_PRINT(ERROR, "got ", container.size(), " container elements from file ", filename); 
    194201        return true; 
    195202      } 
     
    200207      if (input_file_stream) 
    201208      { 
    202         std::copy(std::istream_iterator<T>(input_file_stream), std::istream_iterator<T>(), std::back_inserter(content)); 
     209        std::copy(std::istream_iterator<typename Container::value_type>(input_file_stream), std::istream_iterator<typename Container::value_type>(), std::back_inserter(container)); 
     210        RRLIB_LOG_PRINT(ERROR, "got ", container.size(), " container elements from file ", filename); 
    203211      } 
    204212      input_file_stream.close(); 
Note: See TracChangeset for help on using the changeset viewer.