OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParameterOutput.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 #ifndef OSGDB_PARAMETEROUTPUT
15 #define OSGDB_PARAMETEROUTPUT 1
16 
17 #include <osgDB/Output>
18 
19 namespace osgDB {
20 
22 {
23  public:
24 
26  _fw(fw),
27  _numItemsPerLine(fw.getNumIndicesPerLine()),
28  _column(0) {}
29 
30  ParameterOutput(Output& fw,int numItemsPerLine):
31  _fw(fw),
32  _numItemsPerLine(numItemsPerLine),
33  _column(0) {}
34 
35  void begin()
36  {
37  _fw.indent() << "{"<<std::endl;
38  _fw.moveIn();
39  }
40 
41  void newLine()
42  {
43  if (_column!=0) _fw << std::endl;
44  _column = 0;
45  }
46 
47  void end()
48  {
49  if (_column!=0) _fw << std::endl;
50  _fw.moveOut();
51  _fw.indent() << "}"<<std::endl;
52  _column = 0;
53  }
54 
55  template<class T>
56  void write(const T& t)
57  {
58  if (_column==0) _fw.indent();
59 
60  _fw << t;
61 
62  ++_column;
64  {
65  _fw << std::endl;
66  _column = 0;
67  }
68  else
69  {
70  _fw << " ";
71  }
72 
73  }
74 
75  template<class Iterator>
76  void write(Iterator first, Iterator last)
77  {
78  for(Iterator itr=first;
79  itr!=last;
80  ++itr)
81  {
82  write(*itr);
83  }
84 
85  }
86 
87  template<class Iterator>
88  void writeAsInts(Iterator first, Iterator last)
89  {
90  for(Iterator itr=first;
91  itr!=last;
92  ++itr)
93  {
94  write((int)*itr);
95  }
96 
97  }
98 
99 
100  protected:
101 
102  ParameterOutput& operator = (const ParameterOutput&) { return *this; }
103 
106  int _column;
107 };
108 
109 
110 template<class Iterator>
111 void writeArray(Output& fw, Iterator first, Iterator last,int noItemsPerLine=0)
112 {
113  if (noItemsPerLine==0) noItemsPerLine=fw.getNumIndicesPerLine();
114 
115  fw.indent() << "{"<<std::endl;
116  fw.moveIn();
117 
118  int column=0;
119 
120  for(Iterator itr=first;
121  itr!=last;
122  ++itr)
123  {
124  if (column==0) fw.indent();
125 
126  fw << *itr;
127 
128  ++column;
129  if (column==noItemsPerLine)
130  {
131  fw << std::endl;
132  column = 0;
133  }
134  else
135  {
136  fw << " ";
137  }
138  }
139  if (column!=0) fw << std::endl;
140 
141  fw.moveOut();
142  fw.indent()<<"}"<<std::endl;
143 
144 }
145 
146 
147 template<class Iterator>
148 void writeArrayAsInts(Output& fw, Iterator first, Iterator last,int noItemsPerLine=0)
149 {
150  if (noItemsPerLine==0) noItemsPerLine=fw.getNumIndicesPerLine();
151 
152  fw.indent() << "{"<<std::endl;
153  fw.moveIn();
154 
155  int column=0;
156 
157  for(Iterator itr=first;
158  itr!=last;
159  ++itr)
160  {
161  if (column==0) fw.indent();
162 
163  fw << (int)*itr;
164 
165  ++column;
166  if (column==noItemsPerLine)
167  {
168  fw << std::endl;
169  column = 0;
170  }
171  else
172  {
173  fw << " ";
174  }
175  }
176  if (column!=0) fw << std::endl;
177 
178  fw.moveOut();
179  fw.indent()<<"}"<<std::endl;
180 
181 }
182 
183 
184 }
185 
186 #endif // __SG_OUTPUT_H
ParameterOutput & operator=(const ParameterOutput &)
void writeAsInts(Iterator first, Iterator last)
void write(const T &t)
Output & indent()
void writeArrayAsInts(Output &fw, Iterator first, Iterator last, int noItemsPerLine=0)
Definition: Archive.h:24
void write(Iterator first, Iterator last)
ParameterOutput(Output &fw, int numItemsPerLine)
int getNumIndicesPerLine() const
Definition: Output.h:64
void writeArray(Output &fw, Iterator first, Iterator last, int noItemsPerLine=0)