GL Studio Safety Critical Embedded C++ Runtime Library
gls_string.h
Go to the documentation of this file.
1#ifndef _GLS_STRING_H
2#define _GLS_STRING_H
3
4/*! \file gls_string.h
5
6\brief This header defines the GlsString class
7 in the GL Studio DO-178B Runtime Library.
8
9\par Copyright Information
10Copyright (C) 1999-2012 The DiSTI Corporation<br>
11Orlando, FL USA<br>
12All rights reserved.<br>
13
14 This file is copyrighted software and contains proprietary trade secrets of
15DiSTI, and embodies substantial creative efforts as well as confidential
16information, ideas, and expressions.
17
18 Permission to use, and copy this software and its documentation for any
19purpose is hereby granted per the Distribution Agreement and/or the Licensing
20Agreement signed with DiSTI. This permission is granted provided that:
21 1. The above copyright notice appears in all copies.
22 2. That both the copyright notice and this permission notice appear in
23 the supporting documentation.
24 3. That the names DiSTI and GL Studio not be used in advertising or
25 publicity pertaining to distribution of the software without specific,
26 written prior permission of DiSTI.
27
28 Permission to modify the software is granted, but not the right to
29distribute the source code whether modified, or non-modified. Modifying the
30software might invalidate the DO-178B certification package.
31
32 Permission to distribute binaries produced by compiling source code, or
33modified source code is granted, provided you:
34 1. Provide your name and address as the primary contact for the support
35 of your modified version.
36 2. Retain our contact information in regard to use of the base software.
37
38 DiSTI does not provide warranty for this software or guarantee that it
39satisfies any specification or requirement unless otherwise stated in a
40specific contractual arrangement between the customer and DiSTI.
41
42*/
43
44#include "gls_include.h"
45#include "gls_types.h"
46#include "gls_class_invariant.h"
47
48/** This class is a simple fixed size string wrapper.
49 * \invariant _charBuffer != GLS_NULL, _size <= MAX_STRING_SIZE,
50 * _length <= _size, _charBuffer[ _length ] == GLS_STRING_TERMINATOR
51 */
53{
54public:
56
57 /** maximum number of characters that can be stored ( not including NULL terminator */
58 static const GlsUInt32 MAX_STRING_SIZE = ( GLSUINT32_MAX - 3u );
59
60 /** Constructor - create an instance
61 * \param size number of characters to hold (not including NULL terminator)
62 * \pre size <= MAX_STRING_SIZE
63 * \post instance created, string is set to empty string
64 */
65 GlsString( const GlsUInt32 size );
66
67 /** Destructor - shall never be called
68 * \pre none
69 * \post none
70 */
71 virtual ~GlsString();
72
73 /** Get a const pointer to the string
74 * \return const char pointer to the string
75 * \pre none
76 * \post none
77 */
78 const GlsChar* GetString( void ) const;
79
80 /** Set string value
81 * \param src new desired value for string ( src != GLS_NULL )
82 * \pre src != GLS_NULL
83 * \post string is equal to src if buffer is large enough to hold src,
84 * else is equal to src truncated to fit in buffer
85 */
86 void SetString( const GlsChar* const src );
87
88 /** Get the length of the string
89 * \return length of string, number of characters before terminating NULL
90 * \pre none
91 * \post none
92 */
93 GlsUInt32 GetLength( void ) const;
94
95protected:
96 static const GlsChar STRING_TERMINATOR = '\0'; /**< string terminator (NULL character) */
97
98 GlsChar* const _charBuffer; /**< NULL terminated string, buffer size = _size + 1,
99 * extra char for NULL terminator */
100 const GlsUInt32 _size; /**< number of characters that can be held in _charBuffer
101 * not including NULL terminator */
102 GlsUInt32 _length; /**< length of string contained in char buffer
103 * number of characters before terminating NULL */
104
105private:
106 // Disable implicit generated Members
107 GlsString& operator=( const GlsString &rhs );
108 GlsString( const GlsString &src );
109};
110
111#endif // _GLS_STRING_H
Definition: gls_string.h:53
static const GlsUInt32 MAX_STRING_SIZE
Definition: gls_string.h:58
GlsChar *const _charBuffer
Definition: gls_string.h:98
static const GlsChar STRING_TERMINATOR
Definition: gls_string.h:96
GlsUInt32 GetLength(void) const
const GlsUInt32 _size
Definition: gls_string.h:100
void SetString(const GlsChar *const src)
GlsUInt32 _length
Definition: gls_string.h:102
const GlsChar * GetString(void) const
This header defines a GLS_DEBUG only macro for facilitating evaluating class invariants in the GL Stu...
#define GLS_CLASS_INVARIANT_DECLARATION(ClassName)
Definition: gls_class_invariant.h:80
This header defines any preprocessor defines needed to configure the GL Studio DO-178B Runtime Librar...
This header defines the basic types used by the GL Studio DO-178B Runtime Library.
char GlsChar
Definition: gls_types.h:54
#define GLSUINT32_MAX
Definition: gls_types.h:75
unsigned int GlsUInt32
Definition: gls_types.h:73