annotate win64-msvc/include/capnp/schema.h @ 148:b4bfdf10c4b3

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