annotate win32-mingw/include/capnp/schema.h @ 141:1b5b6dfd0d0e

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