annotate win32-mingw/include/capnp/schema.h @ 159:f4b37539fcc7

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