|
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
| 2 | +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
| 3 | + |
| 4 | +#pragma once |
| 5 | + |
| 6 | +#include <string> |
| 7 | +#include <vector> |
| 8 | +#include <map> |
| 9 | + |
| 10 | +namespace signalr |
| 11 | +{ |
| 12 | + /** |
| 13 | + * An enum defining the types a signalr::value may be. |
| 14 | + */ |
| 15 | + enum class type |
| 16 | + { |
| 17 | + map, |
| 18 | + array, |
| 19 | + string, |
| 20 | + float64, |
| 21 | + null, |
| 22 | + boolean |
| 23 | + }; |
| 24 | + |
| 25 | + /** |
| 26 | + * Represents a value to be provided to a SignalR method as a parameter, or returned as a return value. |
| 27 | + */ |
| 28 | + class value |
| 29 | + { |
| 30 | + public: |
| 31 | + value(); |
| 32 | + value(int val); |
| 33 | + value(double val); |
| 34 | + value(const std::string& val); |
| 35 | + value(const std::vector<value>& val); |
| 36 | + value(const std::map<std::string, value>& map); |
| 37 | + |
| 38 | + /** |
| 39 | + * True if the object stored is a Key-Value pair. |
| 40 | + */ |
| 41 | + bool is_map() const; |
| 42 | + |
| 43 | + /** |
| 44 | + * True if the object stored is double. |
| 45 | + */ |
| 46 | + bool is_double() const; |
| 47 | + |
| 48 | + /** |
| 49 | + * True if the object stored is a string. |
| 50 | + */ |
| 51 | + bool is_string() const; |
| 52 | + |
| 53 | + /** |
| 54 | + * True if the object stored is empty. |
| 55 | + */ |
| 56 | + bool is_null() const; |
| 57 | + |
| 58 | + /** |
| 59 | + * True if the object stored is an array of signalr::value's. |
| 60 | + */ |
| 61 | + bool is_array() const; |
| 62 | + |
| 63 | + /** |
| 64 | + * True if the object stored is a bool. |
| 65 | + */ |
| 66 | + bool is_bool() const; |
| 67 | + |
| 68 | + /** |
| 69 | + * Returns the stored object as a double. This will throw if the underlying object is not a signalr::type::float64. |
| 70 | + */ |
| 71 | + double as_double() const; |
| 72 | + |
| 73 | + /** |
| 74 | + * Returns the stored object as a bool. This will throw if the underlying object is not a signalr::type::boolean. |
| 75 | + */ |
| 76 | + bool as_bool() const; |
| 77 | + |
| 78 | + /** |
| 79 | + * Returns the stored object as a string. This will throw if the underlying object is not a signalr::type::string. |
| 80 | + */ |
| 81 | + const std::string& as_string() const; |
| 82 | + |
| 83 | + /** |
| 84 | + * Returns the stored object as an array of signalr::value's. This will throw if the underlying object is not a signalr::type::array. |
| 85 | + */ |
| 86 | + std::vector<value> as_array() const; |
| 87 | + |
| 88 | + /** |
| 89 | + * Returns the stored object as a map of property name to signalr::value. This will throw if the underlying object is not a signalr::type::map. |
| 90 | + */ |
| 91 | + std::map<std::string, value> as_map() const; |
| 92 | + |
| 93 | + /** |
| 94 | + * Returns the signalr::type that represents the stored object. |
| 95 | + */ |
| 96 | + type type() const; |
| 97 | + }; |
| 98 | +} |
0 commit comments