This repository has been archived by the owner on Oct 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
/
SourceAnnotation.h
176 lines (150 loc) · 4.22 KB
/
SourceAnnotation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//
// SourceAnnotation.h
// snowcrash
//
// Created by Zdenek Nemec on 7/12/13.
// Copyright (c) 2013 Apiary Inc. All rights reserved.
//
#ifndef SNOWCRASH_SOURCEANNOTATION_H
#define SNOWCRASH_SOURCEANNOTATION_H
#include <string>
#include <vector>
#include "ByteBuffer.h"
namespace snowcrash
{
/**
* \brief A source data annotation.
*
* Annotation bound to a source data block. Includes an
* annotation code and an optional message.
*/
struct SourceAnnotation {
/**
* \brief Default annotation code representing success.
*/
static const int OK;
/**
* \brief %SourceAnnotation default constructor.
*
* Creates an empty annotation with the default annotation code.
*/
SourceAnnotation() : code(OK)
{
}
/**
* \brief %SourceAnnotation copy constructor.
* \param rhs An annotation to be copied.
*/
SourceAnnotation(const SourceAnnotation& rhs)
{
this->message = rhs.message;
this->code = rhs.code;
this->location = rhs.location;
}
/**
* \brief %SourceAnnotation constructor.
* \param message An annotation message.
* \param code Annotation code.
* \param location A location of the annotation.
*/
SourceAnnotation(const std::string& message,
int code = OK,
const mdp::CharactersRangeSet& location = mdp::CharactersRangeSet())
{
this->message = message;
this->code = code;
this->location.clear();
if (!location.empty())
this->location.assign(location.begin(), location.end());
}
/** \brief %SourceAnnotation destructor. */
~SourceAnnotation()
{
}
/**
* \brief %SourceAnnotation assignment operator
* \param rhs An annotation to be assigned to this annotation.
*/
SourceAnnotation& operator=(const SourceAnnotation& rhs)
{
this->message = rhs.message;
this->code = rhs.code;
this->location = rhs.location;
return *this;
}
/** The location of this annotation within the source data buffer. */
mdp::CharactersRangeSet location;
/** An annotation code. */
int code;
/** A annotation message. */
std::string message;
};
/**
* Error source annotation.
*/
typedef SourceAnnotation Error;
/**
* Error codes
*/
enum ErrorCode
{
NoError = 0,
ApplicationError = 1,
BusinessError = 2,
ModelError = 3,
MSONError = 4
};
/**
* Warning source annotation.
*/
typedef SourceAnnotation Warning;
/**
* Warning codes
*/
enum WarningCode
{
NoWarning = 0,
APINameWarning = 1,
DuplicateWarning = 2,
FormattingWarning = 3,
RedefinitionWarning = 4,
IgnoringWarning = 5,
EmptyDefinitionWarning = 6,
NotEmptyDefinitionWarning = 7,
LogicalErrorWarning = 8,
DeprecatedWarning = 9,
IndentationWarning = 10,
AmbiguityWarning = 11,
URIWarning = 12,
HTTPWarning = 13
};
/**
* A set of warning source annotations.
*/
typedef std::vector<Warning> Warnings;
/**
* \brief A parsing report Report.
*
* Result of a source data parsing operation.
* Composed of ONE error source annotation
* and a set of warning source annotations.
*/
struct Report {
/**
* \brief Append a report to this one, replacing the error source annotation.
*
* NOTE: A binding does not need to wrap this action.
*/
Report& operator+=(const Report& rhs)
{
error = rhs.error;
warnings.insert(warnings.end(), rhs.warnings.begin(), rhs.warnings.end());
return *this;
}
/** Result error source annotation */
Error error;
/** Result warning source annotations */
Warnings warnings;
};
}
#endif