Bond
 
Loading...
Searching...
No Matches
validate.h
1// Copyright (c) Microsoft. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4#pragma once
5
6#include <bond/core/config.h>
7
8#include "apply.h"
9#include "detail/validate.h"
10#include "exception.h"
11#include "schema.h"
12
13namespace bond
14{
15
23template <typename Protocols = BuiltInProtocols>
24inline bool Validate(const RuntimeSchema& src,
25 const RuntimeSchema& dst)
26{
27 // Create instances to drop the shared_ptr member of the original objects
28 // for performance
29 RuntimeSchema r_dst(RuntimeSchema(dst.GetSchema()), dst.GetType());
30 RuntimeSchema r_src(RuntimeSchema(src.GetSchema()), src.GetType());
31 bool identical = true;
32 detail::ValidateStruct(r_src, r_dst, NULL, identical);
33 return identical;
34}
35
36
44template <typename Protocols = BuiltInProtocols>
45inline bool Validate(const bonded<SchemaDef>& src,
46 const RuntimeSchema& dst)
47{
48 Apply<Protocols>(detail::SchemaValidator<Protocols>(), src);
49
50 SchemaDef schema;
51 src.template Deserialize<Protocols>(schema);
52 return Validate<Protocols>(RuntimeSchema(schema), dst);
53}
54
55
63template <typename Protocols = BuiltInProtocols>
64inline bool Validate(const RuntimeSchema& src,
65 const bonded<SchemaDef>& dst)
66{
67 Apply<Protocols>(detail::SchemaValidator<Protocols>(), dst);
68
69 SchemaDef schema;
70 dst.template Deserialize<Protocols>(schema);
71 return Validate<Protocols>(src, RuntimeSchema(schema));
72}
73
74
83template <typename Protocols = BuiltInProtocols, typename T1, typename T2>
84inline bool ValidateTwoWay(const T1& s1, const T2& s2)
85{
86 return Validate<Protocols>(s1, s2) & Validate<Protocols>(s2, s1);
87}
88
89} // namespace bond
Represents runtime schema See User's Manual
Definition: runtime_schema.h:26
const SchemaDef & GetSchema() const
Returns constant reference to SchemaDef object.
Definition: runtime_schema.h:64
Represents data for a struct T known at compile-time.
Definition: bonded.h:63
namespace bond
Definition: apply.h:17
bool ValidateTwoWay(const T1 &s1, const T2 &s2)
Validate two-way compatibility of schemas.
Definition: validate.h:84
bool Validate(const RuntimeSchema &src, const RuntimeSchema &dst)
Validate compatibility of schemas.
Definition: validate.h:24