Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Core Modules
dune-common
Commits
d3018701
Commit
d3018701
authored
14 years ago
by
Jorrit Fahlke
Browse files
Options
Downloads
Patches
Plain Diff
[Indent] A class to help ease the use of nested indentation in output.
[[Imported from SVN: r6044]]
parent
b5d7f45e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dune/common/Makefile.am
+1
-0
1 addition, 0 deletions
dune/common/Makefile.am
dune/common/indent.hh
+115
-0
115 additions, 0 deletions
dune/common/indent.hh
with
116 additions
and
0 deletions
dune/common/Makefile.am
+
1
−
0
View file @
d3018701
...
...
@@ -42,6 +42,7 @@ commoninclude_HEADERS = \
genericiterator.hh
\
geometrytype.hh
\
gmpfield.hh
\
indent.hh
\
interfaces.hh
\
ios_state.hh
\
iteratorfacades.hh
\
...
...
This diff is collapsed.
Click to expand it.
dune/common/indent.hh
0 → 100644
+
115
−
0
View file @
d3018701
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_COMMON_INDENT_HH
#define DUNE_COMMON_INDENT_HH
#include
<ostream>
#include
<string>
namespace
Dune
{
/** @addtogroup Common
*
* @{
*/
/**
* @file
* @brief Utility class for handling nested indentation in output.
* @author Jö Fahlke
*/
//! Utility class for handling nested indentation in output.
/**
* An indentation object hast a string basic_indent and an indentation
* level. When it is put into a std::ostream using << it will print its
* basic_indent as many times as its indentation level. By default the
* basic_indent will be two spaces and the indentation level will be 0.
*
* An Indent object may also have a reference to a parent Indent object. If
* it has, that object it put into the stream with the << operator before
* the indentation of this object is put into the stream. This effectively
* chains Indent objects together.
*
* You can use the ++ operator to raise and the -- operator to lower the
* indentation by one level.
*
* You can use the + operator with a numeric second argument morelevel to
* create a copy of the Indent object with the indentation level increased
* morelevel times. This is mainly useful to pass indent+1 to a function,
* where indent is an indentation object.
*
* You can use the + operator with a string second argument newindent to
* create a new Indent object with this object as parent, a basic_indent of
* newindent, and an indentation level of one. This is mainly useful to
* pass indent+"> " to a function, where "> " is a possibly different
* indentation string then the one used by indent indentation object.
*
* \note The idea is for functions receive indentation objects as call by
* value parameters. This way, the indentation object of the caller
* will not be modified by the function and the function can simply
* return at anytime without having to clean up.
*/
class
Indent
{
const
Indent
*
parent
;
std
::
string
basic_indent
;
unsigned
level
;
public:
//! setup without parent
/**
* \note Initial indentation level is 0 by default for this constructor.
*/
inline
Indent
(
const
std
::
string
&
basic_indent_
=
" "
,
unsigned
level_
=
0
)
:
parent
(
0
),
basic_indent
(
basic_indent_
),
level
(
level_
)
{
}
//! setup without parent and basic_indentation of two spaces
inline
Indent
(
unsigned
level_
)
:
parent
(
0
),
basic_indent
(
" "
),
level
(
level_
)
{
}
//! setup with parent
/**
* \note Initial indentation level is 1 by default for this constructor.
*/
inline
Indent
(
const
Indent
*
parent_
,
const
std
::
string
&
basic_indent_
=
" "
,
unsigned
level_
=
1
)
:
parent
(
parent_
),
basic_indent
(
basic_indent_
),
level
(
level_
)
{
}
//! setup with parent
inline
Indent
(
const
Indent
*
parent_
,
unsigned
level_
)
:
parent
(
parent_
),
basic_indent
(
" "
),
level
(
level_
)
{
}
//! create new indentation object with this one as parent
inline
Indent
operator
+
(
const
std
::
string
&
newindent
)
const
{
return
Indent
(
this
,
newindent
);
}
//! create a copy of this indetation object with raised level
inline
Indent
operator
+
(
unsigned
morelevel
)
const
{
return
Indent
(
parent
,
basic_indent
,
level
+
morelevel
);
}
//! raise indentation level
inline
Indent
&
operator
++
()
{
++
level
;
return
*
this
;
}
//! lower indentation level
inline
Indent
&
operator
--
()
{
--
level
;
return
*
this
;
}
//! write indentation to a stream
friend
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
s
,
const
Indent
&
indent
);
};
//! write indentation to a stream
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
s
,
const
Indent
&
indent
)
{
if
(
indent
.
parent
)
s
<<
*
indent
.
parent
;
for
(
unsigned
i
=
0
;
i
<
indent
.
level
;
++
i
)
s
<<
indent
.
basic_indent
;
return
s
;
}
/** }@ group Common */
}
// namespace Dune
#endif // DUNE_COMMON_INDENT_HH
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment