annotate osx/include/capnp/schema.h @ 54:5f67a29f0fc7

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