cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vctPrintf.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Ofri Sadowsky
7  Created on: 2006-02-15
8 
9  (C) Copyright 2006-2007 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 
20 */
21 
22 #pragma once
23 #ifndef _vctPrintf_h
24 #define _vctPrintf_h
25 
27 #include <cisstCommon/cmnPrintf.h>
32 
33 template <vct::size_type _size, vct::stride_type _stride, class _elementType, class _dataPtrType>
36 {
37  if (!parser.MatchOutputWithFormatChar(vector[0]) ) {
38  return false;
39  }
40 
41  vct::size_type counter;
42  for (counter = 0; counter < _size; ++counter) {
43  cmnTypePrintf(parser, vector[counter]);
44  if (counter != (_size-1))
45  parser.RawOutput(" ");
46  }
47 
48  return true;
49 }
50 
51 template <class _vectorOwnerType, class _elementType>
54 {
55  const vct::size_type vectorSize = vector.size();
56  if (vectorSize < 1)
57  return true;
58 
59  if (!parser.MatchOutputWithFormatChar(vector[0]) ) {
60  return false;
61  }
62 
63  vct::size_type counter;
64  for (counter = 0; counter < vectorSize; ++counter) {
65  const _elementType element = vector[counter];
66  cmnTypePrintf(parser, element);
67  if (counter != (vectorSize-1))
68  parser.RawOutput(" ");
69  }
70 
71  return true;
72 }
73 
74 
75 template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride,
76 class _elementType, class _dataPtrType>
77  inline bool cmnTypePrintf(cmnPrintfParser & parser,
78  const vctFixedSizeConstMatrixBase<_rows, _cols, _rowStride, _colStride,
79  _elementType, _dataPtrType> & matrix)
80 {
81  if (!parser.MatchOutputWithFormatChar(matrix.Element(0,0)) ) {
82  return false;
83  }
84 
85  vct::size_type rowCounter, colCounter;
86  for (rowCounter = 0; rowCounter < _rows; ++rowCounter) {
87  for (colCounter = 0; colCounter < _cols; ++colCounter) {
88  cmnTypePrintf(parser, matrix.Element(rowCounter, colCounter));
89  if (colCounter != (_cols-1))
90  parser.RawOutput(" ");
91  }
92  if (rowCounter != (_rows - 1))
93  parser.RawOutput("\n");
94  }
95 
96  return true;
97 }
98 
99 
100 template <class _matrixOwnerType, class _elementType>
103 {
104  const vct::size_type rows = matrix.rows();
105  const vct::size_type cols = matrix.cols();
106 
107  if (matrix.size() < 1)
108  return true;
109 
110  if (!parser.MatchOutputWithFormatChar(matrix.Element(0,0)) ) {
111  return false;
112  }
113 
114  vct::size_type rowCounter, colCounter;
115  for (rowCounter = 0; rowCounter < rows; ++rowCounter) {
116  for (colCounter = 0; colCounter < cols; ++colCounter) {
117  cmnTypePrintf(parser, matrix.Element(rowCounter, colCounter));
118  if (colCounter != (cols - 1))
119  parser.RawOutput(" ");
120  }
121  if (rowCounter != (rows - 1))
122  parser.RawOutput("\n");
123  }
124 
125  return true;
126 }
127 
128 
129 #endif // _vctPrintf_h
130 
A template for a fixed size matrix with fixed spacing in memory.
Definition: vctFixedSizeConstMatrixBase.h:103
Declaration of vctDynamicConstMatrixBase.
Portability across compilers and operating systems tools.
Declaration of cmnPrintf and cmnPrintfParser.
bool MatchOutputWithFormatChar(const _outputType &data)
Definition: cmnPrintf.h:451
size_type size(void) const
Definition: vctDynamicConstMatrixBase.h:228
size_t size_type
Definition: vctContainerTraits.h:35
Definition: vctDynamicConstMatrixBase.h:77
size_type size(void) const
Definition: vctDynamicConstVectorBase.h:164
size_type rows() const
Definition: vctDynamicConstMatrixBase.h:238
size_type cols() const
Definition: vctDynamicConstMatrixBase.h:243
bool cmnTypePrintf(cmnPrintfParser &parser, const vctFixedSizeConstVectorBase< _size, _stride, _elementType, _dataPtrType > &vector)
Definition: vctPrintf.h:34
Declaration of vctFixedSizeConstVectorBase.
Declaration of vctDynamicConstVectorBase.
ptrdiff_t stride_type
Definition: vctContainerTraits.h:37
Definition: vctDynamicConstVectorBase.h:77
A template for a fixed length vector with fixed spacing in memory.
Definition: vctFixedSizeConstVectorBase.h:107
void RawOutput(const char *text)
Definition: cmnPrintf.h:243
Parser for cmnPrintf.
Definition: cmnPrintf.h:227
const_reference Element(size_type rowIndex, size_type colIndex) const
Definition: vctDynamicConstMatrixBase.h:362
Declaration of vctFixedSizeConstMatrixBase.