annotate win32-mingw/include/capnp/schema.h @ 79:91c729825bca pa_catalina

Update build for AUDIO_COMPONENT_FIX
author Chris Cannam
date Wed, 30 Oct 2019 12:40:34 +0000
parents eccd51b72864
children
rev   line source
Chris@64 1 // Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors
Chris@64 2 // Licensed under the MIT License:
Chris@64 3 //
Chris@64 4 // Permission is hereby granted, free of charge, to any person obtaining a copy
Chris@64 5 // of this software and associated documentation files (the "Software"), to deal
Chris@64 6 // in the Software without restriction, including without limitation the rights
Chris@64 7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Chris@64 8 // copies of the Software, and to permit persons to whom the Software is
Chris@64 9 // furnished to do so, subject to the following conditions:
Chris@64 10 //
Chris@64 11 // The above copyright notice and this permission notice shall be included in
Chris@64 12 // all copies or substantial portions of the Software.
Chris@64 13 //
Chris@64 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Chris@64 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Chris@64 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Chris@64 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Chris@64 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Chris@64 19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Chris@64 20 // THE SOFTWARE.
Chris@64 21
Chris@64 22 #ifndef CAPNP_SCHEMA_H_
Chris@64 23 #define CAPNP_SCHEMA_H_
Chris@64 24
Chris@64 25 #if defined(__GNUC__) && !defined(CAPNP_HEADER_WARNINGS)
Chris@64 26 #pragma GCC system_header
Chris@64 27 #endif
Chris@64 28
Chris@64 29 #if CAPNP_LITE
Chris@64 30 #error "Reflection APIs, including this header, are not available in lite mode."
Chris@64 31 #endif
Chris@64 32
Chris@64 33 #include <capnp/schema.capnp.h>
Chris@64 34
Chris@64 35 namespace capnp {
Chris@64 36
Chris@64 37 class Schema;
Chris@64 38 class StructSchema;
Chris@64 39 class EnumSchema;
Chris@64 40 class InterfaceSchema;
Chris@64 41 class ConstSchema;
Chris@64 42 class ListSchema;
Chris@64 43 class Type;
Chris@64 44
Chris@64 45 template <typename T, Kind k = kind<T>()> struct SchemaType_ { typedef Schema Type; };
Chris@64 46 template <typename T> struct SchemaType_<T, Kind::PRIMITIVE> { typedef schema::Type::Which Type; };
Chris@64 47 template <typename T> struct SchemaType_<T, Kind::BLOB> { typedef schema::Type::Which Type; };
Chris@64 48 template <typename T> struct SchemaType_<T, Kind::ENUM> { typedef EnumSchema Type; };
Chris@64 49 template <typename T> struct SchemaType_<T, Kind::STRUCT> { typedef StructSchema Type; };
Chris@64 50 template <typename T> struct SchemaType_<T, Kind::INTERFACE> { typedef InterfaceSchema Type; };
Chris@64 51 template <typename T> struct SchemaType_<T, Kind::LIST> { typedef ListSchema Type; };
Chris@64 52
Chris@64 53 template <typename T>
Chris@64 54 using SchemaType = typename SchemaType_<T>::Type;
Chris@64 55 // SchemaType<T> is the type of T's schema, e.g. StructSchema if T is a struct.
Chris@64 56
Chris@64 57 namespace _ { // private
Chris@64 58 extern const RawSchema NULL_SCHEMA;
Chris@64 59 extern const RawSchema NULL_STRUCT_SCHEMA;
Chris@64 60 extern const RawSchema NULL_ENUM_SCHEMA;
Chris@64 61 extern const RawSchema NULL_INTERFACE_SCHEMA;
Chris@64 62 extern const RawSchema NULL_CONST_SCHEMA;
Chris@64 63 // The schema types default to these null (empty) schemas in case of error, especially when
Chris@64 64 // exceptions are disabled.
Chris@64 65 } // namespace _ (private)
Chris@64 66
Chris@64 67 class Schema {
Chris@64 68 // Convenience wrapper around capnp::schema::Node.
Chris@64 69
Chris@64 70 public:
Chris@64 71 inline Schema(): raw(&_::NULL_SCHEMA.defaultBrand) {}
Chris@64 72
Chris@64 73 template <typename T>
Chris@64 74 static inline SchemaType<T> from() { return SchemaType<T>::template fromImpl<T>(); }
Chris@64 75 // Get the Schema for a particular compiled-in type.
Chris@64 76
Chris@64 77 schema::Node::Reader getProto() const;
Chris@64 78 // Get the underlying Cap'n Proto representation of the schema node. (Note that this accessor
Chris@64 79 // has performance comparable to accessors of struct-typed fields on Reader classes.)
Chris@64 80
Chris@64 81 kj::ArrayPtr<const word> asUncheckedMessage() const;
Chris@64 82 // Get the encoded schema node content as a single message segment. It is safe to read as an
Chris@64 83 // unchecked message.
Chris@64 84
Chris@64 85 Schema getDependency(uint64_t id) const KJ_DEPRECATED("Does not handle generics correctly.");
Chris@64 86 // DEPRECATED: This method cannot correctly account for generic type parameter bindings that
Chris@64 87 // may apply to the dependency. Instead of using this method, use a method of the Schema API
Chris@64 88 // that corresponds to the exact kind of dependency. For example, to get a field type, use
Chris@64 89 // StructSchema::Field::getType().
Chris@64 90 //
Chris@64 91 // Gets the Schema for one of this Schema's dependencies. For example, if this Schema is for a
Chris@64 92 // struct, you could look up the schema for one of its fields' types. Throws an exception if this
Chris@64 93 // schema doesn't actually depend on the given id.
Chris@64 94 //
Chris@64 95 // Note that not all type IDs found in the schema node are considered "dependencies" -- only the
Chris@64 96 // ones that are needed to implement the dynamic API are. That includes:
Chris@64 97 // - Field types.
Chris@64 98 // - Group types.
Chris@64 99 // - scopeId for group nodes, but NOT otherwise.
Chris@64 100 // - Method parameter and return types.
Chris@64 101 //
Chris@64 102 // The following are NOT considered dependencies:
Chris@64 103 // - Nested nodes.
Chris@64 104 // - scopeId for a non-group node.
Chris@64 105 // - Annotations.
Chris@64 106 //
Chris@64 107 // To obtain schemas for those, you would need a SchemaLoader.
Chris@64 108
Chris@64 109 bool isBranded() const;
Chris@64 110 // Returns true if this schema represents a non-default parameterization of this type.
Chris@64 111
Chris@64 112 Schema getGeneric() const;
Chris@64 113 // Get the version of this schema with any brands removed.
Chris@64 114
Chris@64 115 class BrandArgumentList;
Chris@64 116 BrandArgumentList getBrandArgumentsAtScope(uint64_t scopeId) const;
Chris@64 117 // Gets the values bound to the brand parameters at the given scope.
Chris@64 118
Chris@64 119 StructSchema asStruct() const;
Chris@64 120 EnumSchema asEnum() const;
Chris@64 121 InterfaceSchema asInterface() const;
Chris@64 122 ConstSchema asConst() const;
Chris@64 123 // Cast the Schema to a specific type. Throws an exception if the type doesn't match. Use
Chris@64 124 // getProto() to determine type, e.g. getProto().isStruct().
Chris@64 125
Chris@64 126 inline bool operator==(const Schema& other) const { return raw == other.raw; }
Chris@64 127 inline bool operator!=(const Schema& other) const { return raw != other.raw; }
Chris@64 128 // Determine whether two Schemas are wrapping the exact same underlying data, by identity. If
Chris@64 129 // you want to check if two Schemas represent the same type (but possibly different versions of
Chris@64 130 // it), compare their IDs instead.
Chris@64 131
Chris@64 132 template <typename T>
Chris@64 133 void requireUsableAs() const;
Chris@64 134 // Throws an exception if a value with this Schema cannot safely be cast to a native value of
Chris@64 135 // the given type. This passes if either:
Chris@64 136 // - *this == from<T>()
Chris@64 137 // - This schema was loaded with SchemaLoader, the type ID matches typeId<T>(), and
Chris@64 138 // loadCompiledTypeAndDependencies<T>() was called on the SchemaLoader.
Chris@64 139
Chris@64 140 kj::StringPtr getShortDisplayName() const;
Chris@64 141 // Get the short version of the node's display name.
Chris@64 142
Chris@64 143 private:
Chris@64 144 const _::RawBrandedSchema* raw;
Chris@64 145
Chris@64 146 inline explicit Schema(const _::RawBrandedSchema* raw): raw(raw) {
Chris@64 147 KJ_IREQUIRE(raw->lazyInitializer == nullptr,
Chris@64 148 "Must call ensureInitialized() on RawSchema before constructing Schema.");
Chris@64 149 }
Chris@64 150
Chris@64 151 template <typename T> static inline Schema fromImpl() {
Chris@64 152 return Schema(&_::rawSchema<T>());
Chris@64 153 }
Chris@64 154
Chris@64 155 void requireUsableAs(const _::RawSchema* expected) const;
Chris@64 156
Chris@64 157 uint32_t getSchemaOffset(const schema::Value::Reader& value) const;
Chris@64 158
Chris@64 159 Type getBrandBinding(uint64_t scopeId, uint index) const;
Chris@64 160 // Look up the binding for a brand parameter used by this Schema. Returns `AnyPointer` if the
Chris@64 161 // parameter is not bound.
Chris@64 162 //
Chris@64 163 // TODO(someday): Public interface for iterating over all bindings?
Chris@64 164
Chris@64 165 Schema getDependency(uint64_t id, uint location) const;
Chris@64 166 // Look up schema for a particular dependency of this schema. `location` is the dependency
Chris@64 167 // location number as defined in _::RawBrandedSchema.
Chris@64 168
Chris@64 169 Type interpretType(schema::Type::Reader proto, uint location) const;
Chris@64 170 // Interpret a schema::Type in the given location within the schema, compiling it into a
Chris@64 171 // Type object.
Chris@64 172
Chris@64 173 friend class StructSchema;
Chris@64 174 friend class EnumSchema;
Chris@64 175 friend class InterfaceSchema;
Chris@64 176 friend class ConstSchema;
Chris@64 177 friend class ListSchema;
Chris@64 178 friend class SchemaLoader;
Chris@64 179 friend class Type;
Chris@64 180 friend kj::StringTree _::structString(
Chris@64 181 _::StructReader reader, const _::RawBrandedSchema& schema);
Chris@64 182 friend kj::String _::enumString(uint16_t value, const _::RawBrandedSchema& schema);
Chris@64 183 };
Chris@64 184
Chris@64 185 kj::StringPtr KJ_STRINGIFY(const Schema& schema);
Chris@64 186
Chris@64 187 class Schema::BrandArgumentList {
Chris@64 188 // A list of generic parameter bindings for parameters of some particular type. Note that since
Chris@64 189 // parameters on an outer type apply to all inner types as well, a deeply-nested type can have
Chris@64 190 // multiple BrandArgumentLists that apply to it.
Chris@64 191 //
Chris@64 192 // A BrandArgumentList only represents the arguments that the client of the type specified. Since
Chris@64 193 // new parameters can be added over time, this list may not cover all defined parameters for the
Chris@64 194 // type. Missing parameters should be treated as AnyPointer. This class's implementation of
Chris@64 195 // operator[] already does this for you; out-of-bounds access will safely return AnyPointer.
Chris@64 196
Chris@64 197 public:
Chris@64 198 inline BrandArgumentList(): scopeId(0), size_(0), bindings(nullptr) {}
Chris@64 199
Chris@64 200 inline uint size() const { return size_; }
Chris@64 201 Type operator[](uint index) const;
Chris@64 202
Chris@64 203 typedef _::IndexingIterator<const BrandArgumentList, Type> Iterator;
Chris@64 204 inline Iterator begin() const { return Iterator(this, 0); }
Chris@64 205 inline Iterator end() const { return Iterator(this, size()); }
Chris@64 206
Chris@64 207 private:
Chris@64 208 uint64_t scopeId;
Chris@64 209 uint size_;
Chris@64 210 bool isUnbound;
Chris@64 211 const _::RawBrandedSchema::Binding* bindings;
Chris@64 212
Chris@64 213 inline BrandArgumentList(uint64_t scopeId, bool isUnbound)
Chris@64 214 : scopeId(scopeId), size_(0), isUnbound(isUnbound), bindings(nullptr) {}
Chris@64 215 inline BrandArgumentList(uint64_t scopeId, uint size,
Chris@64 216 const _::RawBrandedSchema::Binding* bindings)
Chris@64 217 : scopeId(scopeId), size_(size), isUnbound(false), bindings(bindings) {}
Chris@64 218
Chris@64 219 friend class Schema;
Chris@64 220 };
Chris@64 221
Chris@64 222 // -------------------------------------------------------------------
Chris@64 223
Chris@64 224 class StructSchema: public Schema {
Chris@64 225 public:
Chris@64 226 inline StructSchema(): Schema(&_::NULL_STRUCT_SCHEMA.defaultBrand) {}
Chris@64 227
Chris@64 228 class Field;
Chris@64 229 class FieldList;
Chris@64 230 class FieldSubset;
Chris@64 231
Chris@64 232 FieldList getFields() const;
Chris@64 233 // List top-level fields of this struct. This list will contain top-level groups (including
Chris@64 234 // named unions) but not the members of those groups. The list does, however, contain the
Chris@64 235 // members of the unnamed union, if there is one.
Chris@64 236
Chris@64 237 FieldSubset getUnionFields() const;
Chris@64 238 // If the field contains an unnamed union, get a list of fields in the union, ordered by
Chris@64 239 // ordinal. Since discriminant values are assigned sequentially by ordinal, you may index this
Chris@64 240 // list by discriminant value.
Chris@64 241
Chris@64 242 FieldSubset getNonUnionFields() const;
Chris@64 243 // Get the fields of this struct which are not in an unnamed union, ordered by ordinal.
Chris@64 244
Chris@64 245 kj::Maybe<Field> findFieldByName(kj::StringPtr name) const;
Chris@64 246 // Find the field with the given name, or return null if there is no such field. If the struct
Chris@64 247 // contains an unnamed union, then this will find fields of that union in addition to fields
Chris@64 248 // of the outer struct, since they exist in the same namespace. It will not, however, find
Chris@64 249 // members of groups (including named unions) -- you must first look up the group itself,
Chris@64 250 // then dig into its type.
Chris@64 251
Chris@64 252 Field getFieldByName(kj::StringPtr name) const;
Chris@64 253 // Like findFieldByName() but throws an exception on failure.
Chris@64 254
Chris@64 255 kj::Maybe<Field> getFieldByDiscriminant(uint16_t discriminant) const;
Chris@64 256 // Finds the field whose `discriminantValue` is equal to the given value, or returns null if
Chris@64 257 // there is no such field. (If the schema does not represent a union or a struct containing
Chris@64 258 // an unnamed union, then this always returns null.)
Chris@64 259
Chris@64 260 private:
Chris@64 261 StructSchema(Schema base): Schema(base) {}
Chris@64 262 template <typename T> static inline StructSchema fromImpl() {
Chris@64 263 return StructSchema(Schema(&_::rawBrandedSchema<T>()));
Chris@64 264 }
Chris@64 265 friend class Schema;
Chris@64 266 friend class Type;
Chris@64 267 };
Chris@64 268
Chris@64 269 class StructSchema::Field {
Chris@64 270 public:
Chris@64 271 Field() = default;
Chris@64 272
Chris@64 273 inline schema::Field::Reader getProto() const { return proto; }
Chris@64 274 inline StructSchema getContainingStruct() const { return parent; }
Chris@64 275
Chris@64 276 inline uint getIndex() const { return index; }
Chris@64 277 // Get the index of this field within the containing struct or union.
Chris@64 278
Chris@64 279 Type getType() const;
Chris@64 280 // Get the type of this field. Note that this is preferred over getProto().getType() as this
Chris@64 281 // method will apply generics.
Chris@64 282
Chris@64 283 uint32_t getDefaultValueSchemaOffset() const;
Chris@64 284 // For struct, list, and object fields, returns the offset, in words, within the first segment of
Chris@64 285 // the struct's schema, where this field's default value pointer is located. The schema is
Chris@64 286 // always stored as a single-segment unchecked message, which in turn means that the default
Chris@64 287 // value pointer itself can be treated as the root of an unchecked message -- if you know where
Chris@64 288 // to find it, which is what this method helps you with.
Chris@64 289 //
Chris@64 290 // For blobs, returns the offset of the beginning of the blob's content within the first segment
Chris@64 291 // of the struct's schema.
Chris@64 292 //
Chris@64 293 // This is primarily useful for code generators. The C++ code generator, for example, embeds
Chris@64 294 // the entire schema as a raw word array within the generated code. Of course, to implement
Chris@64 295 // field accessors, it needs access to those fields' default values. Embedding separate copies
Chris@64 296 // of those default values would be redundant since they are already included in the schema, but
Chris@64 297 // seeking through the schema at runtime to find the default values would be ugly. Instead,
Chris@64 298 // the code generator can use getDefaultValueSchemaOffset() to find the offset of the default
Chris@64 299 // value within the schema, and can simply apply that offset at runtime.
Chris@64 300 //
Chris@64 301 // If the above does not make sense, you probably don't need this method.
Chris@64 302
Chris@64 303 inline bool operator==(const Field& other) const;
Chris@64 304 inline bool operator!=(const Field& other) const { return !(*this == other); }
Chris@64 305
Chris@64 306 private:
Chris@64 307 StructSchema parent;
Chris@64 308 uint index;
Chris@64 309 schema::Field::Reader proto;
Chris@64 310
Chris@64 311 inline Field(StructSchema parent, uint index, schema::Field::Reader proto)
Chris@64 312 : parent(parent), index(index), proto(proto) {}
Chris@64 313
Chris@64 314 friend class StructSchema;
Chris@64 315 };
Chris@64 316
Chris@64 317 kj::StringPtr KJ_STRINGIFY(const StructSchema::Field& field);
Chris@64 318
Chris@64 319 class StructSchema::FieldList {
Chris@64 320 public:
Chris@64 321 FieldList() = default; // empty list
Chris@64 322
Chris@64 323 inline uint size() const { return list.size(); }
Chris@64 324 inline Field operator[](uint index) const { return Field(parent, index, list[index]); }
Chris@64 325
Chris@64 326 typedef _::IndexingIterator<const FieldList, Field> Iterator;
Chris@64 327 inline Iterator begin() const { return Iterator(this, 0); }
Chris@64 328 inline Iterator end() const { return Iterator(this, size()); }
Chris@64 329
Chris@64 330 private:
Chris@64 331 StructSchema parent;
Chris@64 332 List<schema::Field>::Reader list;
Chris@64 333
Chris@64 334 inline FieldList(StructSchema parent, List<schema::Field>::Reader list)
Chris@64 335 : parent(parent), list(list) {}
Chris@64 336
Chris@64 337 friend class StructSchema;
Chris@64 338 };
Chris@64 339
Chris@64 340 class StructSchema::FieldSubset {
Chris@64 341 public:
Chris@64 342 FieldSubset() = default; // empty list
Chris@64 343
Chris@64 344 inline uint size() const { return size_; }
Chris@64 345 inline Field operator[](uint index) const {
Chris@64 346 return Field(parent, indices[index], list[indices[index]]);
Chris@64 347 }
Chris@64 348
Chris@64 349 typedef _::IndexingIterator<const FieldSubset, Field> Iterator;
Chris@64 350 inline Iterator begin() const { return Iterator(this, 0); }
Chris@64 351 inline Iterator end() const { return Iterator(this, size()); }
Chris@64 352
Chris@64 353 private:
Chris@64 354 StructSchema parent;
Chris@64 355 List<schema::Field>::Reader list;
Chris@64 356 const uint16_t* indices;
Chris@64 357 uint size_;
Chris@64 358
Chris@64 359 inline FieldSubset(StructSchema parent, List<schema::Field>::Reader list,
Chris@64 360 const uint16_t* indices, uint size)
Chris@64 361 : parent(parent), list(list), indices(indices), size_(size) {}
Chris@64 362
Chris@64 363 friend class StructSchema;
Chris@64 364 };
Chris@64 365
Chris@64 366 // -------------------------------------------------------------------
Chris@64 367
Chris@64 368 class EnumSchema: public Schema {
Chris@64 369 public:
Chris@64 370 inline EnumSchema(): Schema(&_::NULL_ENUM_SCHEMA.defaultBrand) {}
Chris@64 371
Chris@64 372 class Enumerant;
Chris@64 373 class EnumerantList;
Chris@64 374
Chris@64 375 EnumerantList getEnumerants() const;
Chris@64 376
Chris@64 377 kj::Maybe<Enumerant> findEnumerantByName(kj::StringPtr name) const;
Chris@64 378
Chris@64 379 Enumerant getEnumerantByName(kj::StringPtr name) const;
Chris@64 380 // Like findEnumerantByName() but throws an exception on failure.
Chris@64 381
Chris@64 382 private:
Chris@64 383 EnumSchema(Schema base): Schema(base) {}
Chris@64 384 template <typename T> static inline EnumSchema fromImpl() {
Chris@64 385 return EnumSchema(Schema(&_::rawBrandedSchema<T>()));
Chris@64 386 }
Chris@64 387 friend class Schema;
Chris@64 388 friend class Type;
Chris@64 389 };
Chris@64 390
Chris@64 391 class EnumSchema::Enumerant {
Chris@64 392 public:
Chris@64 393 Enumerant() = default;
Chris@64 394
Chris@64 395 inline schema::Enumerant::Reader getProto() const { return proto; }
Chris@64 396 inline EnumSchema getContainingEnum() const { return parent; }
Chris@64 397
Chris@64 398 inline uint16_t getOrdinal() const { return ordinal; }
Chris@64 399 inline uint getIndex() const { return ordinal; }
Chris@64 400
Chris@64 401 inline bool operator==(const Enumerant& other) const;
Chris@64 402 inline bool operator!=(const Enumerant& other) const { return !(*this == other); }
Chris@64 403
Chris@64 404 private:
Chris@64 405 EnumSchema parent;
Chris@64 406 uint16_t ordinal;
Chris@64 407 schema::Enumerant::Reader proto;
Chris@64 408
Chris@64 409 inline Enumerant(EnumSchema parent, uint16_t ordinal, schema::Enumerant::Reader proto)
Chris@64 410 : parent(parent), ordinal(ordinal), proto(proto) {}
Chris@64 411
Chris@64 412 friend class EnumSchema;
Chris@64 413 };
Chris@64 414
Chris@64 415 class EnumSchema::EnumerantList {
Chris@64 416 public:
Chris@64 417 EnumerantList() = default; // empty list
Chris@64 418
Chris@64 419 inline uint size() const { return list.size(); }
Chris@64 420 inline Enumerant operator[](uint index) const { return Enumerant(parent, index, list[index]); }
Chris@64 421
Chris@64 422 typedef _::IndexingIterator<const EnumerantList, Enumerant> Iterator;
Chris@64 423 inline Iterator begin() const { return Iterator(this, 0); }
Chris@64 424 inline Iterator end() const { return Iterator(this, size()); }
Chris@64 425
Chris@64 426 private:
Chris@64 427 EnumSchema parent;
Chris@64 428 List<schema::Enumerant>::Reader list;
Chris@64 429
Chris@64 430 inline EnumerantList(EnumSchema parent, List<schema::Enumerant>::Reader list)
Chris@64 431 : parent(parent), list(list) {}
Chris@64 432
Chris@64 433 friend class EnumSchema;
Chris@64 434 };
Chris@64 435
Chris@64 436 // -------------------------------------------------------------------
Chris@64 437
Chris@64 438 class InterfaceSchema: public Schema {
Chris@64 439 public:
Chris@64 440 inline InterfaceSchema(): Schema(&_::NULL_INTERFACE_SCHEMA.defaultBrand) {}
Chris@64 441
Chris@64 442 class Method;
Chris@64 443 class MethodList;
Chris@64 444
Chris@64 445 MethodList getMethods() const;
Chris@64 446
Chris@64 447 kj::Maybe<Method> findMethodByName(kj::StringPtr name) const;
Chris@64 448
Chris@64 449 Method getMethodByName(kj::StringPtr name) const;
Chris@64 450 // Like findMethodByName() but throws an exception on failure.
Chris@64 451
Chris@64 452 class SuperclassList;
Chris@64 453
Chris@64 454 SuperclassList getSuperclasses() const;
Chris@64 455 // Get the immediate superclasses of this type, after applying generics.
Chris@64 456
Chris@64 457 bool extends(InterfaceSchema other) const;
Chris@64 458 // Returns true if `other` is a superclass of this interface (including if `other == *this`).
Chris@64 459
Chris@64 460 kj::Maybe<InterfaceSchema> findSuperclass(uint64_t typeId) const;
Chris@64 461 // Find the superclass of this interface with the given type ID. Returns null if the interface
Chris@64 462 // extends no such type.
Chris@64 463
Chris@64 464 private:
Chris@64 465 InterfaceSchema(Schema base): Schema(base) {}
Chris@64 466 template <typename T> static inline InterfaceSchema fromImpl() {
Chris@64 467 return InterfaceSchema(Schema(&_::rawBrandedSchema<T>()));
Chris@64 468 }
Chris@64 469 friend class Schema;
Chris@64 470 friend class Type;
Chris@64 471
Chris@64 472 kj::Maybe<Method> findMethodByName(kj::StringPtr name, uint& counter) const;
Chris@64 473 bool extends(InterfaceSchema other, uint& counter) const;
Chris@64 474 kj::Maybe<InterfaceSchema> findSuperclass(uint64_t typeId, uint& counter) const;
Chris@64 475 // We protect against malicious schemas with large or cyclic hierarchies by cutting off the
Chris@64 476 // search when the counter reaches a threshold.
Chris@64 477 };
Chris@64 478
Chris@64 479 class InterfaceSchema::Method {
Chris@64 480 public:
Chris@64 481 Method() = default;
Chris@64 482
Chris@64 483 inline schema::Method::Reader getProto() const { return proto; }
Chris@64 484 inline InterfaceSchema getContainingInterface() const { return parent; }
Chris@64 485
Chris@64 486 inline uint16_t getOrdinal() const { return ordinal; }
Chris@64 487 inline uint getIndex() const { return ordinal; }
Chris@64 488
Chris@64 489 StructSchema getParamType() const;
Chris@64 490 StructSchema getResultType() const;
Chris@64 491 // Get the parameter and result types, including substituting generic parameters.
Chris@64 492
Chris@64 493 inline bool operator==(const Method& other) const;
Chris@64 494 inline bool operator!=(const Method& other) const { return !(*this == other); }
Chris@64 495
Chris@64 496 private:
Chris@64 497 InterfaceSchema parent;
Chris@64 498 uint16_t ordinal;
Chris@64 499 schema::Method::Reader proto;
Chris@64 500
Chris@64 501 inline Method(InterfaceSchema parent, uint16_t ordinal,
Chris@64 502 schema::Method::Reader proto)
Chris@64 503 : parent(parent), ordinal(ordinal), proto(proto) {}
Chris@64 504
Chris@64 505 friend class InterfaceSchema;
Chris@64 506 };
Chris@64 507
Chris@64 508 class InterfaceSchema::MethodList {
Chris@64 509 public:
Chris@64 510 MethodList() = default; // empty list
Chris@64 511
Chris@64 512 inline uint size() const { return list.size(); }
Chris@64 513 inline Method operator[](uint index) const { return Method(parent, index, list[index]); }
Chris@64 514
Chris@64 515 typedef _::IndexingIterator<const MethodList, Method> Iterator;
Chris@64 516 inline Iterator begin() const { return Iterator(this, 0); }
Chris@64 517 inline Iterator end() const { return Iterator(this, size()); }
Chris@64 518
Chris@64 519 private:
Chris@64 520 InterfaceSchema parent;
Chris@64 521 List<schema::Method>::Reader list;
Chris@64 522
Chris@64 523 inline MethodList(InterfaceSchema parent, List<schema::Method>::Reader list)
Chris@64 524 : parent(parent), list(list) {}
Chris@64 525
Chris@64 526 friend class InterfaceSchema;
Chris@64 527 };
Chris@64 528
Chris@64 529 class InterfaceSchema::SuperclassList {
Chris@64 530 public:
Chris@64 531 SuperclassList() = default; // empty list
Chris@64 532
Chris@64 533 inline uint size() const { return list.size(); }
Chris@64 534 InterfaceSchema operator[](uint index) const;
Chris@64 535
Chris@64 536 typedef _::IndexingIterator<const SuperclassList, InterfaceSchema> Iterator;
Chris@64 537 inline Iterator begin() const { return Iterator(this, 0); }
Chris@64 538 inline Iterator end() const { return Iterator(this, size()); }
Chris@64 539
Chris@64 540 private:
Chris@64 541 InterfaceSchema parent;
Chris@64 542 List<schema::Superclass>::Reader list;
Chris@64 543
Chris@64 544 inline SuperclassList(InterfaceSchema parent, List<schema::Superclass>::Reader list)
Chris@64 545 : parent(parent), list(list) {}
Chris@64 546
Chris@64 547 friend class InterfaceSchema;
Chris@64 548 };
Chris@64 549
Chris@64 550 // -------------------------------------------------------------------
Chris@64 551
Chris@64 552 class ConstSchema: public Schema {
Chris@64 553 // Represents a constant declaration.
Chris@64 554 //
Chris@64 555 // `ConstSchema` can be implicitly cast to DynamicValue to read its value.
Chris@64 556
Chris@64 557 public:
Chris@64 558 inline ConstSchema(): Schema(&_::NULL_CONST_SCHEMA.defaultBrand) {}
Chris@64 559
Chris@64 560 template <typename T>
Chris@64 561 ReaderFor<T> as() const;
Chris@64 562 // Read the constant's value. This is a convenience method equivalent to casting the ConstSchema
Chris@64 563 // to a DynamicValue and then calling its `as<T>()` method. For dependency reasons, this method
Chris@64 564 // is defined in <capnp/dynamic.h>, which you must #include explicitly.
Chris@64 565
Chris@64 566 uint32_t getValueSchemaOffset() const;
Chris@64 567 // Much like StructSchema::Field::getDefaultValueSchemaOffset(), if the constant has pointer
Chris@64 568 // type, this gets the offset from the beginning of the constant's schema node to a pointer
Chris@64 569 // representing the constant value.
Chris@64 570
Chris@64 571 Type getType() const;
Chris@64 572
Chris@64 573 private:
Chris@64 574 ConstSchema(Schema base): Schema(base) {}
Chris@64 575 friend class Schema;
Chris@64 576 };
Chris@64 577
Chris@64 578 // -------------------------------------------------------------------
Chris@64 579
Chris@64 580 class Type {
Chris@64 581 public:
Chris@64 582 struct BrandParameter {
Chris@64 583 uint64_t scopeId;
Chris@64 584 uint index;
Chris@64 585 };
Chris@64 586 struct ImplicitParameter {
Chris@64 587 uint index;
Chris@64 588 };
Chris@64 589
Chris@64 590 inline Type();
Chris@64 591 inline Type(schema::Type::Which primitive);
Chris@64 592 inline Type(StructSchema schema);
Chris@64 593 inline Type(EnumSchema schema);
Chris@64 594 inline Type(InterfaceSchema schema);
Chris@64 595 inline Type(ListSchema schema);
Chris@64 596 inline Type(schema::Type::AnyPointer::Unconstrained::Which anyPointerKind);
Chris@64 597 inline Type(BrandParameter param);
Chris@64 598 inline Type(ImplicitParameter param);
Chris@64 599
Chris@64 600 template <typename T>
Chris@64 601 inline static Type from();
Chris@64 602
Chris@64 603 inline schema::Type::Which which() const;
Chris@64 604
Chris@64 605 StructSchema asStruct() const;
Chris@64 606 EnumSchema asEnum() const;
Chris@64 607 InterfaceSchema asInterface() const;
Chris@64 608 ListSchema asList() const;
Chris@64 609 // Each of these methods may only be called if which() returns the corresponding type.
Chris@64 610
Chris@64 611 kj::Maybe<BrandParameter> getBrandParameter() const;
Chris@64 612 // Only callable if which() returns ANY_POINTER. Returns null if the type is just a regular
Chris@64 613 // AnyPointer and not a parameter.
Chris@64 614
Chris@64 615 kj::Maybe<ImplicitParameter> getImplicitParameter() const;
Chris@64 616 // Only callable if which() returns ANY_POINTER. Returns null if the type is just a regular
Chris@64 617 // AnyPointer and not a parameter. "Implicit parameters" refer to type parameters on methods.
Chris@64 618
Chris@64 619 inline schema::Type::AnyPointer::Unconstrained::Which whichAnyPointerKind() const;
Chris@64 620 // Only callable if which() returns ANY_POINTER.
Chris@64 621
Chris@64 622 inline bool isVoid() const;
Chris@64 623 inline bool isBool() const;
Chris@64 624 inline bool isInt8() const;
Chris@64 625 inline bool isInt16() const;
Chris@64 626 inline bool isInt32() const;
Chris@64 627 inline bool isInt64() const;
Chris@64 628 inline bool isUInt8() const;
Chris@64 629 inline bool isUInt16() const;
Chris@64 630 inline bool isUInt32() const;
Chris@64 631 inline bool isUInt64() const;
Chris@64 632 inline bool isFloat32() const;
Chris@64 633 inline bool isFloat64() const;
Chris@64 634 inline bool isText() const;
Chris@64 635 inline bool isData() const;
Chris@64 636 inline bool isList() const;
Chris@64 637 inline bool isEnum() const;
Chris@64 638 inline bool isStruct() const;
Chris@64 639 inline bool isInterface() const;
Chris@64 640 inline bool isAnyPointer() const;
Chris@64 641
Chris@64 642 bool operator==(const Type& other) const;
Chris@64 643 inline bool operator!=(const Type& other) const { return !(*this == other); }
Chris@64 644
Chris@64 645 size_t hashCode() const;
Chris@64 646
Chris@64 647 inline Type wrapInList(uint depth = 1) const;
Chris@64 648 // Return the Type formed by wrapping this type in List() `depth` times.
Chris@64 649
Chris@64 650 inline Type(schema::Type::Which derived, const _::RawBrandedSchema* schema);
Chris@64 651 // For internal use.
Chris@64 652
Chris@64 653 private:
Chris@64 654 schema::Type::Which baseType; // type not including applications of List()
Chris@64 655 uint8_t listDepth; // 0 for T, 1 for List(T), 2 for List(List(T)), ...
Chris@64 656
Chris@64 657 bool isImplicitParam;
Chris@64 658 // If true, this refers to an implicit method parameter. baseType must be ANY_POINTER, scopeId
Chris@64 659 // must be zero, and paramIndex indicates the parameter index.
Chris@64 660
Chris@64 661 union {
Chris@64 662 uint16_t paramIndex;
Chris@64 663 // If baseType is ANY_POINTER but this Type actually refers to a type parameter, this is the
Chris@64 664 // index of the parameter among the parameters at its scope, and `scopeId` below is the type ID
Chris@64 665 // of the scope where the parameter was defined.
Chris@64 666
Chris@64 667 schema::Type::AnyPointer::Unconstrained::Which anyPointerKind;
Chris@64 668 // If scopeId is zero and isImplicitParam is false.
Chris@64 669 };
Chris@64 670
Chris@64 671 union {
Chris@64 672 const _::RawBrandedSchema* schema; // if type is struct, enum, interface...
Chris@64 673 uint64_t scopeId; // if type is AnyPointer but it's actually a type parameter...
Chris@64 674 };
Chris@64 675
Chris@64 676 Type(schema::Type::Which baseType, uint8_t listDepth, const _::RawBrandedSchema* schema)
Chris@64 677 : baseType(baseType), listDepth(listDepth), schema(schema) {
Chris@64 678 KJ_IREQUIRE(baseType != schema::Type::ANY_POINTER);
Chris@64 679 }
Chris@64 680
Chris@64 681 void requireUsableAs(Type expected) const;
Chris@64 682
Chris@64 683 friend class ListSchema; // only for requireUsableAs()
Chris@64 684 };
Chris@64 685
Chris@64 686 // -------------------------------------------------------------------
Chris@64 687
Chris@64 688 class ListSchema {
Chris@64 689 // ListSchema is a little different because list types are not described by schema nodes. So,
Chris@64 690 // ListSchema doesn't subclass Schema.
Chris@64 691
Chris@64 692 public:
Chris@64 693 ListSchema() = default;
Chris@64 694
Chris@64 695 static ListSchema of(schema::Type::Which primitiveType);
Chris@64 696 static ListSchema of(StructSchema elementType);
Chris@64 697 static ListSchema of(EnumSchema elementType);
Chris@64 698 static ListSchema of(InterfaceSchema elementType);
Chris@64 699 static ListSchema of(ListSchema elementType);
Chris@64 700 static ListSchema of(Type elementType);
Chris@64 701 // Construct the schema for a list of the given type.
Chris@64 702
Chris@64 703 static ListSchema of(schema::Type::Reader elementType, Schema context)
Chris@64 704 KJ_DEPRECATED("Does not handle generics correctly.");
Chris@64 705 // DEPRECATED: This method cannot correctly account for generic type parameter bindings that
Chris@64 706 // may apply to the input type. Instead of using this method, use a method of the Schema API
Chris@64 707 // that corresponds to the exact kind of dependency. For example, to get a field type, use
Chris@64 708 // StructSchema::Field::getType().
Chris@64 709 //
Chris@64 710 // Construct from an element type schema. Requires a context which can handle getDependency()
Chris@64 711 // requests for any type ID found in the schema.
Chris@64 712
Chris@64 713 Type getElementType() const;
Chris@64 714
Chris@64 715 inline schema::Type::Which whichElementType() const;
Chris@64 716 // Get the element type's "which()". ListSchema does not actually store a schema::Type::Reader
Chris@64 717 // describing the element type, but if it did, this would be equivalent to calling
Chris@64 718 // .getBody().which() on that type.
Chris@64 719
Chris@64 720 StructSchema getStructElementType() const;
Chris@64 721 EnumSchema getEnumElementType() const;
Chris@64 722 InterfaceSchema getInterfaceElementType() const;
Chris@64 723 ListSchema getListElementType() const;
Chris@64 724 // Get the schema for complex element types. Each of these throws an exception if the element
Chris@64 725 // type is not of the requested kind.
Chris@64 726
Chris@64 727 inline bool operator==(const ListSchema& other) const { return elementType == other.elementType; }
Chris@64 728 inline bool operator!=(const ListSchema& other) const { return elementType != other.elementType; }
Chris@64 729
Chris@64 730 template <typename T>
Chris@64 731 void requireUsableAs() const;
Chris@64 732
Chris@64 733 private:
Chris@64 734 Type elementType;
Chris@64 735
Chris@64 736 inline explicit ListSchema(Type elementType): elementType(elementType) {}
Chris@64 737
Chris@64 738 template <typename T>
Chris@64 739 struct FromImpl;
Chris@64 740 template <typename T> static inline ListSchema fromImpl() {
Chris@64 741 return FromImpl<T>::get();
Chris@64 742 }
Chris@64 743
Chris@64 744 void requireUsableAs(ListSchema expected) const;
Chris@64 745
Chris@64 746 friend class Schema;
Chris@64 747 };
Chris@64 748
Chris@64 749 // =======================================================================================
Chris@64 750 // inline implementation
Chris@64 751
Chris@64 752 template <> inline schema::Type::Which Schema::from<Void>() { return schema::Type::VOID; }
Chris@64 753 template <> inline schema::Type::Which Schema::from<bool>() { return schema::Type::BOOL; }
Chris@64 754 template <> inline schema::Type::Which Schema::from<int8_t>() { return schema::Type::INT8; }
Chris@64 755 template <> inline schema::Type::Which Schema::from<int16_t>() { return schema::Type::INT16; }
Chris@64 756 template <> inline schema::Type::Which Schema::from<int32_t>() { return schema::Type::INT32; }
Chris@64 757 template <> inline schema::Type::Which Schema::from<int64_t>() { return schema::Type::INT64; }
Chris@64 758 template <> inline schema::Type::Which Schema::from<uint8_t>() { return schema::Type::UINT8; }
Chris@64 759 template <> inline schema::Type::Which Schema::from<uint16_t>() { return schema::Type::UINT16; }
Chris@64 760 template <> inline schema::Type::Which Schema::from<uint32_t>() { return schema::Type::UINT32; }
Chris@64 761 template <> inline schema::Type::Which Schema::from<uint64_t>() { return schema::Type::UINT64; }
Chris@64 762 template <> inline schema::Type::Which Schema::from<float>() { return schema::Type::FLOAT32; }
Chris@64 763 template <> inline schema::Type::Which Schema::from<double>() { return schema::Type::FLOAT64; }
Chris@64 764 template <> inline schema::Type::Which Schema::from<Text>() { return schema::Type::TEXT; }
Chris@64 765 template <> inline schema::Type::Which Schema::from<Data>() { return schema::Type::DATA; }
Chris@64 766
Chris@64 767 inline Schema Schema::getDependency(uint64_t id) const {
Chris@64 768 return getDependency(id, 0);
Chris@64 769 }
Chris@64 770
Chris@64 771 inline bool Schema::isBranded() const {
Chris@64 772 return raw != &raw->generic->defaultBrand;
Chris@64 773 }
Chris@64 774
Chris@64 775 inline Schema Schema::getGeneric() const {
Chris@64 776 return Schema(&raw->generic->defaultBrand);
Chris@64 777 }
Chris@64 778
Chris@64 779 template <typename T>
Chris@64 780 inline void Schema::requireUsableAs() const {
Chris@64 781 requireUsableAs(&_::rawSchema<T>());
Chris@64 782 }
Chris@64 783
Chris@64 784 inline bool StructSchema::Field::operator==(const Field& other) const {
Chris@64 785 return parent == other.parent && index == other.index;
Chris@64 786 }
Chris@64 787 inline bool EnumSchema::Enumerant::operator==(const Enumerant& other) const {
Chris@64 788 return parent == other.parent && ordinal == other.ordinal;
Chris@64 789 }
Chris@64 790 inline bool InterfaceSchema::Method::operator==(const Method& other) const {
Chris@64 791 return parent == other.parent && ordinal == other.ordinal;
Chris@64 792 }
Chris@64 793
Chris@64 794 inline ListSchema ListSchema::of(StructSchema elementType) {
Chris@64 795 return ListSchema(Type(elementType));
Chris@64 796 }
Chris@64 797 inline ListSchema ListSchema::of(EnumSchema elementType) {
Chris@64 798 return ListSchema(Type(elementType));
Chris@64 799 }
Chris@64 800 inline ListSchema ListSchema::of(InterfaceSchema elementType) {
Chris@64 801 return ListSchema(Type(elementType));
Chris@64 802 }
Chris@64 803 inline ListSchema ListSchema::of(ListSchema elementType) {
Chris@64 804 return ListSchema(Type(elementType));
Chris@64 805 }
Chris@64 806 inline ListSchema ListSchema::of(Type elementType) {
Chris@64 807 return ListSchema(elementType);
Chris@64 808 }
Chris@64 809
Chris@64 810 inline Type ListSchema::getElementType() const {
Chris@64 811 return elementType;
Chris@64 812 }
Chris@64 813
Chris@64 814 inline schema::Type::Which ListSchema::whichElementType() const {
Chris@64 815 return elementType.which();
Chris@64 816 }
Chris@64 817
Chris@64 818 inline StructSchema ListSchema::getStructElementType() const {
Chris@64 819 return elementType.asStruct();
Chris@64 820 }
Chris@64 821
Chris@64 822 inline EnumSchema ListSchema::getEnumElementType() const {
Chris@64 823 return elementType.asEnum();
Chris@64 824 }
Chris@64 825
Chris@64 826 inline InterfaceSchema ListSchema::getInterfaceElementType() const {
Chris@64 827 return elementType.asInterface();
Chris@64 828 }
Chris@64 829
Chris@64 830 inline ListSchema ListSchema::getListElementType() const {
Chris@64 831 return elementType.asList();
Chris@64 832 }
Chris@64 833
Chris@64 834 template <typename T>
Chris@64 835 inline void ListSchema::requireUsableAs() const {
Chris@64 836 static_assert(kind<T>() == Kind::LIST,
Chris@64 837 "ListSchema::requireUsableAs<T>() requires T is a list type.");
Chris@64 838 requireUsableAs(Schema::from<T>());
Chris@64 839 }
Chris@64 840
Chris@64 841 inline void ListSchema::requireUsableAs(ListSchema expected) const {
Chris@64 842 elementType.requireUsableAs(expected.elementType);
Chris@64 843 }
Chris@64 844
Chris@64 845 template <typename T>
Chris@64 846 struct ListSchema::FromImpl<List<T>> {
Chris@64 847 static inline ListSchema get() { return of(Schema::from<T>()); }
Chris@64 848 };
Chris@64 849
Chris@64 850 inline Type::Type(): baseType(schema::Type::VOID), listDepth(0), schema(nullptr) {}
Chris@64 851 inline Type::Type(schema::Type::Which primitive)
Chris@64 852 : baseType(primitive), listDepth(0), isImplicitParam(false) {
Chris@64 853 KJ_IREQUIRE(primitive != schema::Type::STRUCT &&
Chris@64 854 primitive != schema::Type::ENUM &&
Chris@64 855 primitive != schema::Type::INTERFACE &&
Chris@64 856 primitive != schema::Type::LIST);
Chris@64 857 if (primitive == schema::Type::ANY_POINTER) {
Chris@64 858 scopeId = 0;
Chris@64 859 anyPointerKind = schema::Type::AnyPointer::Unconstrained::ANY_KIND;
Chris@64 860 } else {
Chris@64 861 schema = nullptr;
Chris@64 862 }
Chris@64 863 }
Chris@64 864 inline Type::Type(schema::Type::Which derived, const _::RawBrandedSchema* schema)
Chris@64 865 : baseType(derived), listDepth(0), isImplicitParam(false), schema(schema) {
Chris@64 866 KJ_IREQUIRE(derived == schema::Type::STRUCT ||
Chris@64 867 derived == schema::Type::ENUM ||
Chris@64 868 derived == schema::Type::INTERFACE);
Chris@64 869 }
Chris@64 870
Chris@64 871 inline Type::Type(StructSchema schema)
Chris@64 872 : baseType(schema::Type::STRUCT), listDepth(0), schema(schema.raw) {}
Chris@64 873 inline Type::Type(EnumSchema schema)
Chris@64 874 : baseType(schema::Type::ENUM), listDepth(0), schema(schema.raw) {}
Chris@64 875 inline Type::Type(InterfaceSchema schema)
Chris@64 876 : baseType(schema::Type::INTERFACE), listDepth(0), schema(schema.raw) {}
Chris@64 877 inline Type::Type(ListSchema schema)
Chris@64 878 : Type(schema.getElementType()) { ++listDepth; }
Chris@64 879 inline Type::Type(schema::Type::AnyPointer::Unconstrained::Which anyPointerKind)
Chris@64 880 : baseType(schema::Type::ANY_POINTER), listDepth(0), isImplicitParam(false),
Chris@64 881 anyPointerKind(anyPointerKind), scopeId(0) {}
Chris@64 882 inline Type::Type(BrandParameter param)
Chris@64 883 : baseType(schema::Type::ANY_POINTER), listDepth(0), isImplicitParam(false),
Chris@64 884 paramIndex(param.index), scopeId(param.scopeId) {}
Chris@64 885 inline Type::Type(ImplicitParameter param)
Chris@64 886 : baseType(schema::Type::ANY_POINTER), listDepth(0), isImplicitParam(true),
Chris@64 887 paramIndex(param.index), scopeId(0) {}
Chris@64 888
Chris@64 889 inline schema::Type::Which Type::which() const {
Chris@64 890 return listDepth > 0 ? schema::Type::LIST : baseType;
Chris@64 891 }
Chris@64 892
Chris@64 893 inline schema::Type::AnyPointer::Unconstrained::Which Type::whichAnyPointerKind() const {
Chris@64 894 KJ_IREQUIRE(baseType == schema::Type::ANY_POINTER);
Chris@64 895 return !isImplicitParam && scopeId == 0 ? anyPointerKind
Chris@64 896 : schema::Type::AnyPointer::Unconstrained::ANY_KIND;
Chris@64 897 }
Chris@64 898
Chris@64 899 template <typename T>
Chris@64 900 inline Type Type::from() { return Type(Schema::from<T>()); }
Chris@64 901
Chris@64 902 inline bool Type::isVoid () const { return baseType == schema::Type::VOID && listDepth == 0; }
Chris@64 903 inline bool Type::isBool () const { return baseType == schema::Type::BOOL && listDepth == 0; }
Chris@64 904 inline bool Type::isInt8 () const { return baseType == schema::Type::INT8 && listDepth == 0; }
Chris@64 905 inline bool Type::isInt16 () const { return baseType == schema::Type::INT16 && listDepth == 0; }
Chris@64 906 inline bool Type::isInt32 () const { return baseType == schema::Type::INT32 && listDepth == 0; }
Chris@64 907 inline bool Type::isInt64 () const { return baseType == schema::Type::INT64 && listDepth == 0; }
Chris@64 908 inline bool Type::isUInt8 () const { return baseType == schema::Type::UINT8 && listDepth == 0; }
Chris@64 909 inline bool Type::isUInt16 () const { return baseType == schema::Type::UINT16 && listDepth == 0; }
Chris@64 910 inline bool Type::isUInt32 () const { return baseType == schema::Type::UINT32 && listDepth == 0; }
Chris@64 911 inline bool Type::isUInt64 () const { return baseType == schema::Type::UINT64 && listDepth == 0; }
Chris@64 912 inline bool Type::isFloat32() const { return baseType == schema::Type::FLOAT32 && listDepth == 0; }
Chris@64 913 inline bool Type::isFloat64() const { return baseType == schema::Type::FLOAT64 && listDepth == 0; }
Chris@64 914 inline bool Type::isText () const { return baseType == schema::Type::TEXT && listDepth == 0; }
Chris@64 915 inline bool Type::isData () const { return baseType == schema::Type::DATA && listDepth == 0; }
Chris@64 916 inline bool Type::isList () const { return listDepth > 0; }
Chris@64 917 inline bool Type::isEnum () const { return baseType == schema::Type::ENUM && listDepth == 0; }
Chris@64 918 inline bool Type::isStruct () const { return baseType == schema::Type::STRUCT && listDepth == 0; }
Chris@64 919 inline bool Type::isInterface() const {
Chris@64 920 return baseType == schema::Type::INTERFACE && listDepth == 0;
Chris@64 921 }
Chris@64 922 inline bool Type::isAnyPointer() const {
Chris@64 923 return baseType == schema::Type::ANY_POINTER && listDepth == 0;
Chris@64 924 }
Chris@64 925
Chris@64 926 inline Type Type::wrapInList(uint depth) const {
Chris@64 927 Type result = *this;
Chris@64 928 result.listDepth += depth;
Chris@64 929 return result;
Chris@64 930 }
Chris@64 931
Chris@64 932 } // namespace capnp
Chris@64 933
Chris@64 934 #endif // CAPNP_SCHEMA_H_