blob: ec78e8febb1148bf1dce425ad00ffc0a262b0c0d (
plain)
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
|
// file : odb/relational/validator.cxx
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
// license : GNU GPL v3; see accompanying LICENSE file
#include <iostream>
#include <odb/diagnostics.hxx>
#include <odb/traversal.hxx>
#include <odb/relational/common.hxx>
#include <odb/relational/context.hxx>
#include <odb/relational/validator.hxx>
using namespace std;
namespace relational
{
void validator::
validate (options const&,
features&,
semantics::unit& u,
semantics::path const&,
unsigned short pass)
{
bool valid (true);
// Validate custom type mapping.
//
if (pass == 1)
{
// Create an empty list if we don't have one. This makes the
// rest of the code simpler.
//
if (!u.count ("custom-db-types"))
u.set ("custom-db-types", custom_db_types ());
custom_db_types & cts (u.get<custom_db_types> ("custom-db-types"));
for (custom_db_types::iterator i (cts.begin ()); i != cts.end (); ++i)
{
custom_db_type& ct (*i);
if (ct.type.empty ())
{
error (ct.loc) << "'type' clause expected in db pragma map" << endl;
valid = false;
}
if (ct.as.empty ())
{
error (ct.loc) << "'as' clause expected in db pragma map" << endl;
valid = false;
}
if (ct.to.empty ())
ct.to = "(?)";
else
{
size_t p (ct.to.find ("(?)"));
if (p == string::npos)
{
error (ct.loc) << "no '(?)' expression in the 'to' clause "
<< "of db pragma map" << endl;
valid = false;
}
else if (ct.to.find ("(?)", p + 3) != string::npos)
{
error (ct.loc) << "multiple '(?)' expressions in the 'to' "
<< "clause of db pragma map" << endl;
valid = false;
}
}
if (ct.from.empty ())
ct.from = "(?)";
else
{
size_t p (ct.from.find ("(?)"));
if (p == string::npos)
{
error (ct.loc) << "no '(?)' expression in the 'from' clause "
<< "of db pragma map" << endl;
valid = false;
}
else if (ct.from.find ("(?)", p + 3) != string::npos)
{
error (ct.loc) << "multiple '(?)' expressions in the 'from' "
<< "clause of db pragma map" << endl;
valid = false;
}
}
}
}
if (!valid)
throw failed ();
}
}
|