12
12
#define MRDOX_API_SUPPORT_DOM_HPP
13
13
14
14
#include < mrdox/Platform.hpp>
15
+ #include < fmt/format.h>
15
16
#include < atomic>
16
17
#include < cstdint>
17
18
#include < initializer_list>
@@ -101,7 +102,6 @@ class MRDOX_DECL
101
102
};
102
103
103
104
template <class U , class ... Args>
104
- requires std::derived_from<U, Any>
105
105
auto create (Args&&... args);
106
106
107
107
// ------------------------------------------------
@@ -123,7 +123,8 @@ class Pointer
123
123
friend class Pointer ;
124
124
125
125
explicit
126
- Pointer (Any* any) noexcept
126
+ Pointer (
127
+ Any* any) noexcept
127
128
: any_(any)
128
129
{
129
130
}
@@ -143,22 +144,31 @@ class Pointer
143
144
}
144
145
145
146
template <class U >
146
- requires std::convertible_to<U*, T*>
147
- Pointer (U* u) noexcept
147
+ requires (
148
+ std::convertible_to<U*, T*> &&
149
+ std::derived_from<U, Any>)
150
+ Pointer(
151
+ U* u) noexcept
148
152
: any_(u->addref ())
149
153
{
150
154
}
151
155
152
156
template <class U >
153
- requires std::convertible_to<U*, T*>
154
- Pointer (Pointer<U> const & other) noexcept
157
+ requires (
158
+ std::convertible_to<U*, T*> &&
159
+ std::derived_from<U, Any>)
160
+ Pointer(
161
+ Pointer<U> const & other) noexcept
155
162
: any_(other.any_->addref ())
156
163
{
157
164
}
158
165
159
166
template <class U >
160
- requires std::convertible_to<U*, T*>
161
- Pointer& operator =(
167
+ requires (
168
+ std::convertible_to<U*, T*> &&
169
+ std::derived_from<U, Any>)
170
+ Pointer&
171
+ operator=(
162
172
Pointer<U> const & other) noexcept
163
173
{
164
174
Pointer temp (other);
@@ -196,12 +206,10 @@ class Pointer
196
206
}
197
207
198
208
template <class U , class ... Args>
199
- requires std::derived_from<U, Any>
200
209
friend auto create (Args&&... args);
201
210
};
202
211
203
212
template <class U , class ... Args>
204
- requires std::derived_from<U, Any>
205
213
auto create (Args&&... args)
206
214
{
207
215
return Pointer<U>(new U (
@@ -220,6 +228,11 @@ class MRDOX_DECL
220
228
public:
221
229
virtual std::size_t length () const noexcept ;
222
230
virtual Value get (std::size_t ) const ;
231
+
232
+ /* * Return a diagnostic string.
233
+ */
234
+ std::string
235
+ displayString () const ;
223
236
};
224
237
225
238
using ArrayPtr = Pointer<Array>;
@@ -235,13 +248,8 @@ using ArrayPtr = Pointer<Array>;
235
248
class MRDOX_DECL
236
249
Object : public Any
237
250
{
238
- protected:
239
- /* * Constructor.
240
-
241
- The newly constructed object will retain
242
- a copy of the list of values in `other`.
243
- */
244
- Object (Object const & other);
251
+ template <class U , class ... Args>
252
+ friend auto create (Args&&... args);
245
253
246
254
public:
247
255
/* * The type of an element in this container.
@@ -252,12 +260,20 @@ class MRDOX_DECL
252
260
*/
253
261
using list_type = std::vector<value_type>;
254
262
263
+ protected:
255
264
/* * Constructor.
256
265
257
266
Default-constructed objects are empty.
258
267
*/
259
268
Object () noexcept ;
260
269
270
+ /* * Constructor.
271
+
272
+ The newly constructed object will retain
273
+ a copy of the list of values in `other`.
274
+ */
275
+ Object (Object const & other);
276
+
261
277
/* * Constructor.
262
278
263
279
Upon construction, the object will retain
@@ -269,6 +285,7 @@ class MRDOX_DECL
269
285
*/
270
286
explicit Object (list_type list);
271
287
288
+ public:
272
289
/* * Return an iterable range with the contents.
273
290
*/
274
291
list_type const & list () const noexcept ;
@@ -322,6 +339,11 @@ class MRDOX_DECL
322
339
*/
323
340
virtual void set (std::string_view key, Value value);
324
341
342
+ /* * Return a diagnostic string.
343
+ */
344
+ std::string
345
+ displayString () const ;
346
+
325
347
// VFALCO DEPRECATED (for duktape)
326
348
virtual std::vector<std::string_view> props () const ;
327
349
@@ -405,6 +427,9 @@ class MRDOX_DECL
405
427
LazyObjectPtr lazy_obj_;
406
428
};
407
429
430
+ friend class Array ;
431
+ friend class Object ;
432
+
408
433
public:
409
434
~Value ();
410
435
Value () noexcept ;
@@ -553,6 +578,19 @@ class MRDOX_DECL
553
578
{
554
579
v0.swap (v1);
555
580
}
581
+
582
+ /* * Return a diagnostic string.
583
+ */
584
+ std::string
585
+ displayString () const ;
586
+
587
+ private:
588
+ /* * Return a diagnostic string.
589
+
590
+ This function will not traverse children.
591
+ */
592
+ std::string
593
+ displayString1 () const ;
556
594
};
557
595
558
596
/* * Return a non-empty string, or a null.
@@ -571,4 +609,32 @@ stringOrNull(
571
609
} // mrdox
572
610
} // clang
573
611
612
+ // ------------------------------------------------
613
+
614
+ template <>
615
+ struct fmt ::formatter<clang::mrdox::dom::Object>
616
+ : fmt::formatter<std::string>
617
+ {
618
+ auto format (
619
+ clang::mrdox::dom::Object const & value,
620
+ fmt::format_context& ctx) const
621
+ {
622
+ return fmt::formatter<std::string>::format (
623
+ value.displayString (), ctx);
624
+ }
625
+ };
626
+
627
+ template <>
628
+ struct fmt ::formatter<clang::mrdox::dom::Value>
629
+ : fmt::formatter<std::string>
630
+ {
631
+ auto format (
632
+ clang::mrdox::dom::Value const & value,
633
+ fmt::format_context& ctx) const
634
+ {
635
+ return fmt::formatter<std::string>::format (
636
+ value.displayString (), ctx);
637
+ }
638
+ };
639
+
574
640
#endif
0 commit comments