SerializationContext.h Source File

Back to the index.

SerializationContext.h
Go to the documentation of this file.
1 #ifndef SERIALIZATIONCONTEXT_H
2 #define SERIALIZATIONCONTEXT_H
3 
4 /*
5  * Copyright (C) 2007-2010 Anders Gavare. All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  * derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #include "misc.h"
32 
33 
34 /**
35  * \brief A context used during serialization of objects.
36  */
38 {
39 public:
40  /**
41  * \brief Constructs a default SerializationContext.
42  */
44  : m_indentation(0)
45  {
46  }
47 
48  /**
49  * \brief Gets the indentation level of the context.
50  *
51  * @return the indentation level
52  */
53  int GetIndentation() const
54  {
55  return m_indentation;
56  }
57 
58  /**
59  * \brief Sets the indentation level.
60  *
61  * @param indentation The new indentation level.
62  */
63  void SetIndentation(int indentation)
64  {
65  m_indentation = indentation;
66  }
67 
68  /**
69  * \brief Constructs a SerializationContext which is indented (1
70  * step) compared to the current context.
71  *
72  * @return An indented context.
73  */
75  {
76  SerializationContext newContext;
77  newContext.SetIndentation(GetIndentation() + 1);
78  return newContext;
79  }
80 
81  /**
82  * \brief Generates a string of Tab characters, based on the
83  * indentation level.
84  *
85  * @return a string of tab characters
86  */
87  string Tabs() const
88  {
89  string retValue;
90  for (int i=0; i<m_indentation; i++)
91  retValue += "\t";
92  return retValue;
93  }
94 
95 private:
96  int m_indentation;
97 };
98 
99 
100 #endif // SERIALIZATIONCONTEXT_H
SerializationContext::SerializationContext
SerializationContext()
Constructs a default SerializationContext.
Definition: SerializationContext.h:43
SerializationContext::GetIndentation
int GetIndentation() const
Gets the indentation level of the context.
Definition: SerializationContext.h:53
SerializationContext::Indented
SerializationContext Indented()
Constructs a SerializationContext which is indented (1 step) compared to the current context.
Definition: SerializationContext.h:74
SerializationContext::SetIndentation
void SetIndentation(int indentation)
Sets the indentation level.
Definition: SerializationContext.h:63
misc.h
SerializationContext
A context used during serialization of objects.
Definition: SerializationContext.h:37
SerializationContext::Tabs
string Tabs() const
Generates a string of Tab characters, based on the indentation level.
Definition: SerializationContext.h:87

Generated on Tue Mar 24 2020 14:04:48 for GXemul by doxygen 1.8.17