GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
char_counting_sink.hpp
1 /**
2  * Copyright (c) 2009 Carnegie Mellon University.
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an "AS
13  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14  * express or implied. See the License for the specific language
15  * governing permissions and limitations under the License.
16  *
17  * For more about this software visit:
18  *
19  * http://www.graphlab.ml.cmu.edu
20  *
21  */
22 
23 
24 #ifndef CHAR_COUNTING_SINK
25 #define CHAR_COUNTING_SINK
26 #include <boost/iostreams/stream.hpp>
27 #include <boost/iostreams/categories.hpp>
28 
29 namespace graphlab {
30 
31 /**
32  \ingroup util_internal
33 A boost sink device which counts the number of characters written
34 */
36  char_counting_sink(size_t initial = 0):count(initial) { }
37 
38  char_counting_sink(const char_counting_sink &buf):count(buf.count) { }
39  size_t count;
40  typedef char char_type;
41  struct category: public boost::iostreams::device_tag,
42  public boost::iostreams::output,
43  public boost::iostreams::multichar_tag,
44  public boost::iostreams::optimally_buffered_tag { };
45 
46  /** the optimal buffer size is 0. */
47  inline std::streamsize optimal_buffer_size() const { return 0; }
48 
49  inline std::streamsize write(const char* s, std::streamsize n) {
50  count += n;
51  return n;
52  }
53 };
54 }
55 #endif
56