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