PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Dependencies/Boost/boost/random/detail/vector_io.hpp

http://hadesmem.googlecode.com/
C++ Header | 75 lines | 57 code | 7 blank | 11 comment | 11 complexity | 5c93caa9a182a33b42e531969396adcb MD5 | raw file
 1/* boost random/vector_io.hpp header file
 2 *
 3 * Copyright Steven Watanabe 2011
 4 * Distributed under the Boost Software License, Version 1.0. (See
 5 * accompanying file LICENSE_1_0.txt or copy at
 6 * http://www.boost.org/LICENSE_1_0.txt)
 7 *
 8 * See http://www.boost.org for most recent version including documentation.
 9 *
10 * $Id: vector_io.hpp 71018 2011-04-05 21:27:52Z steven_watanabe $
11 */
12
13#ifndef BOOST_RANDOM_DETAIL_VECTOR_IO_HPP
14#define BOOST_RANDOM_DETAIL_VECTOR_IO_HPP
15
16#include <vector>
17#include <iosfwd>
18#include <istream>
19
20namespace boost {
21namespace random {
22namespace detail {
23
24template<class CharT, class Traits, class T>
25void print_vector(std::basic_ostream<CharT, Traits>& os,
26                  const std::vector<T>& vec)
27{
28    typename std::vector<T>::const_iterator
29        iter = vec.begin(),
30        end =  vec.end();
31    os << os.widen('[');
32    if(iter != end) {
33        os << *iter;
34        ++iter;
35        for(; iter != end; ++iter)
36        {
37            os << os.widen(' ') << *iter;
38        }
39    }
40    os << os.widen(']');
41}
42
43template<class CharT, class Traits, class T>
44void read_vector(std::basic_istream<CharT, Traits>& is, std::vector<T>& vec)
45{
46    CharT ch;
47    if(!(is >> ch)) {
48        return;
49    }
50    if(ch != is.widen('[')) {
51        is.putback(ch);
52        is.setstate(std::ios_base::failbit);
53        return;
54    }
55    T val;
56    while(is >> std::ws >> val) {
57        vec.push_back(val);
58    }
59    if(is.fail()) {
60        is.clear();
61        if(!(is >> ch)) {
62            return;
63        }
64        if(ch != is.widen(']')) {
65            is.putback(ch);
66            is.setstate(std::ios_base::failbit);
67        }
68    }
69}
70
71}
72}
73}
74
75#endif // BOOST_RANDOM_DETAIL_VECTOR_IO_HPP