HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_ContainerPrinter.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_ContainerPrinter.h ( UT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __UT_ContainerPrinter__
12 #define __UT_ContainerPrinter__
13 
14 #include <SYS/SYS_Types.h>
15 
16 template<typename T>
18 {
19 public:
20  UT_ContainerPrinter(const T &c, exint limit = 100) :
21  myContainer(c), myLimit(limit) {}
22 
23 private:
24  const T &myContainer;
25  exint myLimit;
26 
27  template<typename OS, typename S>
28  friend OS &operator<<(OS &os, const UT_ContainerPrinter<S> &d);
29 };
30 
31 template<typename OS, typename S>
32 inline OS &
33 operator<<(OS &os, const UT_ContainerPrinter<S> &cp)
34 {
35  os << "{";
36  exint c = 0;
37  for (typename S::const_iterator it = cp.myContainer.begin();
38  it != cp.myContainer.end(); ++it, ++c)
39  {
40  if (c > 0) os << ", ";
41  if (cp.myLimit > 0 && c > cp.myLimit)
42  {
43  os << "...";
44  break;
45  }
46  os << *it;
47  }
48  os << "}[" << cp.myContainer.size() << "]";
49  return os;
50 }
51 
52 #endif // __UT_ContainerPrinter__
int64 exint
Definition: SYS_Types.h:116
UT_ContainerPrinter(const T &c, exint limit=100)