annotate win64-msvc/include/capnp/schema.h @ 58:eab3b14ddc95

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