cisst-saw
Loading...
Searching...
No Matches
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
14This software is provided "as is" under an open source license, with
15no warranty. The complete license can be found in license.txt and
16http://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
32
33template <vct::size_type _size, vct::stride_type _stride, class _elementType, class _dataPtrType>
34bool cmnTypePrintf(cmnPrintfParser & parser,
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
51template <class _vectorOwnerType, class _elementType>
52bool cmnTypePrintf(cmnPrintfParser & parser,
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
75template <vct::size_type _rows, vct::size_type _cols, vct::stride_type _rowStride, vct::stride_type _colStride,
76class _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
100template <class _matrixOwnerType, class _elementType>
101bool cmnTypePrintf(cmnPrintfParser & parser,
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
Definition vctForwardDeclarations.h:145
Definition vctForwardDeclarations.h:119
A template for a fixed size matrix with fixed spacing in memory.
Definition vctFixedSizeConstMatrixBase.h:104
A template for a fixed length vector with fixed spacing in memory.
Definition vctFixedSizeConstVectorBase.h:108
Portability across compilers and operating systems tools.
Declaration of cmnPrintf and cmnPrintfParser.
CISST_EXPORT bool cmnTypePrintf(cmnPrintfParser &parser, const int number)
size_t size_type
Definition vctContainerTraits.h:35
ptrdiff_t stride_type
Definition vctContainerTraits.h:37
Declaration of vctDynamicConstMatrixBase.
size_type cols() const
Definition vctDynamicConstMatrixBase.h:243
size_type rows() const
Definition vctDynamicConstMatrixBase.h:238
Declaration of vctDynamicConstVectorBase.
Declaration of vctFixedSizeConstMatrixBase.
Declaration of vctFixedSizeConstVectorBase.