annotate osx/include/capnp/orphan.h @ 49:3ab5a40c4e3b

Add Capnp and KJ builds for OSX
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 25 Oct 2016 14:48:23 +0100
parents
children 0994c39f1e94
rev   line source
cannam@49 1 // Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors
cannam@49 2 // Licensed under the MIT License:
cannam@49 3 //
cannam@49 4 // Permission is hereby granted, free of charge, to any person obtaining a copy
cannam@49 5 // of this software and associated documentation files (the "Software"), to deal
cannam@49 6 // in the Software without restriction, including without limitation the rights
cannam@49 7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
cannam@49 8 // copies of the Software, and to permit persons to whom the Software is
cannam@49 9 // furnished to do so, subject to the following conditions:
cannam@49 10 //
cannam@49 11 // The above copyright notice and this permission notice shall be included in
cannam@49 12 // all copies or substantial portions of the Software.
cannam@49 13 //
cannam@49 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
cannam@49 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
cannam@49 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
cannam@49 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
cannam@49 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
cannam@49 19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
cannam@49 20 // THE SOFTWARE.
cannam@49 21
cannam@49 22 #ifndef CAPNP_ORPHAN_H_
cannam@49 23 #define CAPNP_ORPHAN_H_
cannam@49 24
cannam@49 25 #if defined(__GNUC__) && !defined(CAPNP_HEADER_WARNINGS)
cannam@49 26 #pragma GCC system_header
cannam@49 27 #endif
cannam@49 28
cannam@49 29 #include "layout.h"
cannam@49 30
cannam@49 31 namespace capnp {
cannam@49 32
cannam@49 33 class StructSchema;
cannam@49 34 class ListSchema;
cannam@49 35 struct DynamicStruct;
cannam@49 36 struct DynamicList;
cannam@49 37 namespace _ { struct OrphanageInternal; }
cannam@49 38
cannam@49 39 template <typename T>
cannam@49 40 class Orphan {
cannam@49 41 // Represents an object which is allocated within some message builder but has no pointers
cannam@49 42 // pointing at it. An Orphan can later be "adopted" by some other object as one of that object's
cannam@49 43 // fields, without having to copy the orphan. For a field `foo` of pointer type, the generated
cannam@49 44 // code will define builder methods `void adoptFoo(Orphan<T>)` and `Orphan<T> disownFoo()`.
cannam@49 45 // Orphans can also be created independently of any parent using an Orphanage.
cannam@49 46 //
cannam@49 47 // `Orphan<T>` can be moved but not copied, like `Own<T>`, so that it is impossible for one
cannam@49 48 // orphan to be adopted multiple times. If an orphan is destroyed without being adopted, its
cannam@49 49 // contents are zero'd out (and possibly reused, if we ever implement the ability to reuse space
cannam@49 50 // in a message arena).
cannam@49 51
cannam@49 52 public:
cannam@49 53 Orphan() = default;
cannam@49 54 KJ_DISALLOW_COPY(Orphan);
cannam@49 55 Orphan(Orphan&&) = default;
cannam@49 56 Orphan& operator=(Orphan&&) = default;
cannam@49 57 inline Orphan(_::OrphanBuilder&& builder): builder(kj::mv(builder)) {}
cannam@49 58
cannam@49 59 inline BuilderFor<T> get();
cannam@49 60 // Get the underlying builder. If the orphan is null, this will allocate and return a default
cannam@49 61 // object rather than crash. This is done for security -- otherwise, you might enable a DoS
cannam@49 62 // attack any time you disown a field and fail to check if it is null. In the case of structs,
cannam@49 63 // this means that the orphan is no longer null after get() returns. In the case of lists,
cannam@49 64 // no actual object is allocated since a simple empty ListBuilder can be returned.
cannam@49 65
cannam@49 66 inline ReaderFor<T> getReader() const;
cannam@49 67
cannam@49 68 inline bool operator==(decltype(nullptr)) const { return builder == nullptr; }
cannam@49 69 inline bool operator!=(decltype(nullptr)) const { return builder != nullptr; }
cannam@49 70
cannam@49 71 inline void truncate(uint size);
cannam@49 72 // Resize an object (which must be a list or a blob) to the given size.
cannam@49 73 //
cannam@49 74 // If the new size is less than the original, the remaining elements will be discarded. The
cannam@49 75 // list is never moved in this case. If the list happens to be located at the end of its segment
cannam@49 76 // (which is always true if the list was the last thing allocated), the removed memory will be
cannam@49 77 // reclaimed (reducing the messag size), otherwise it is simply zeroed. The reclaiming behavior
cannam@49 78 // is particularly useful for allocating buffer space when you aren't sure how much space you
cannam@49 79 // actually need: you can pre-allocate, say, a 4k byte array, read() from a file into it, and
cannam@49 80 // then truncate it back to the amount of space actually used.
cannam@49 81 //
cannam@49 82 // If the new size is greater than the original, the list is extended with default values. If
cannam@49 83 // the list is the last object in its segment *and* there is enough space left in the segment to
cannam@49 84 // extend it to cover the new values, then the list is extended in-place. Otherwise, it must be
cannam@49 85 // moved to a new location, leaving a zero'd hole in the previous space that won't be filled.
cannam@49 86 // This copy is shallow; sub-objects will simply be reparented, not copied.
cannam@49 87 //
cannam@49 88 // Any existing readers or builders pointing at the object are invalidated by this call (even if
cannam@49 89 // it doesn't move). You must call `get()` or `getReader()` again to get the new, valid pointer.
cannam@49 90
cannam@49 91 private:
cannam@49 92 _::OrphanBuilder builder;
cannam@49 93
cannam@49 94 template <typename, Kind>
cannam@49 95 friend struct _::PointerHelpers;
cannam@49 96 template <typename, Kind>
cannam@49 97 friend struct List;
cannam@49 98 template <typename U>
cannam@49 99 friend class Orphan;
cannam@49 100 friend class Orphanage;
cannam@49 101 friend class MessageBuilder;
cannam@49 102 };
cannam@49 103
cannam@49 104 class Orphanage: private kj::DisallowConstCopy {
cannam@49 105 // Use to directly allocate Orphan objects, without having a parent object allocate and then
cannam@49 106 // disown the object.
cannam@49 107
cannam@49 108 public:
cannam@49 109 inline Orphanage(): arena(nullptr) {}
cannam@49 110
cannam@49 111 template <typename BuilderType>
cannam@49 112 static Orphanage getForMessageContaining(BuilderType builder);
cannam@49 113 // Construct an Orphanage that allocates within the message containing the given Builder. This
cannam@49 114 // allows the constructed Orphans to be adopted by objects within said message.
cannam@49 115 //
cannam@49 116 // This constructor takes the builder rather than having the builder have a getOrphanage() method
cannam@49 117 // because this is an advanced feature and we don't want to pollute the builder APIs with it.
cannam@49 118 //
cannam@49 119 // Note that if you have a direct pointer to the `MessageBuilder`, you can simply call its
cannam@49 120 // `getOrphanage()` method.
cannam@49 121
cannam@49 122 template <typename RootType>
cannam@49 123 Orphan<RootType> newOrphan() const;
cannam@49 124 // Allocate a new orphaned struct.
cannam@49 125
cannam@49 126 template <typename RootType>
cannam@49 127 Orphan<RootType> newOrphan(uint size) const;
cannam@49 128 // Allocate a new orphaned list or blob.
cannam@49 129
cannam@49 130 Orphan<DynamicStruct> newOrphan(StructSchema schema) const;
cannam@49 131 // Dynamically create an orphan struct with the given schema. You must
cannam@49 132 // #include <capnp/dynamic.h> to use this.
cannam@49 133
cannam@49 134 Orphan<DynamicList> newOrphan(ListSchema schema, uint size) const;
cannam@49 135 // Dynamically create an orphan list with the given schema. You must #include <capnp/dynamic.h>
cannam@49 136 // to use this.
cannam@49 137
cannam@49 138 template <typename Reader>
cannam@49 139 Orphan<FromReader<Reader>> newOrphanCopy(Reader copyFrom) const;
cannam@49 140 // Allocate a new orphaned object (struct, list, or blob) and initialize it as a copy of the
cannam@49 141 // given object.
cannam@49 142
cannam@49 143 template <typename T>
cannam@49 144 Orphan<List<ListElementType<FromReader<T>>>> newOrphanConcat(kj::ArrayPtr<T> lists) const;
cannam@49 145 template <typename T>
cannam@49 146 Orphan<List<ListElementType<FromReader<T>>>> newOrphanConcat(kj::ArrayPtr<const T> lists) const;
cannam@49 147 // Given an array of List readers, copy and concatenate the lists, creating a new Orphan.
cannam@49 148 //
cannam@49 149 // Note that compared to allocating the list yourself and using `setWithCaveats()` to set each
cannam@49 150 // item, this method avoids the "caveats": the new list will be allocated with the element size
cannam@49 151 // being the maximum of that from all the input lists. This is particularly important when
cannam@49 152 // concatenating struct lists: if the lists were created using a newer version of the protocol
cannam@49 153 // in which some new fields had been added to the struct, using `setWithCaveats()` would
cannam@49 154 // truncate off those new fields.
cannam@49 155
cannam@49 156 Orphan<Data> referenceExternalData(Data::Reader data) const;
cannam@49 157 // Creates an Orphan<Data> that points at an existing region of memory (e.g. from another message)
cannam@49 158 // without copying it. There are some SEVERE restrictions on how this can be used:
cannam@49 159 // - The memory must remain valid until the `MessageBuilder` is destroyed (even if the orphan is
cannam@49 160 // abandoned).
cannam@49 161 // - Because the data is const, you will not be allowed to obtain a `Data::Builder`
cannam@49 162 // for this blob. Any call which would return such a builder will throw an exception. You
cannam@49 163 // can, however, obtain a Reader, e.g. via orphan.getReader() or from a parent Reader (once
cannam@49 164 // the orphan is adopted). It is your responsibility to make sure your code can deal with
cannam@49 165 // these problems when using this optimization; if you can't, allocate a copy instead.
cannam@49 166 // - `data.begin()` must be aligned to a machine word boundary (32-bit or 64-bit depending on
cannam@49 167 // the CPU). Any pointer returned by malloc() as well as any data blob obtained from another
cannam@49 168 // Cap'n Proto message satisfies this.
cannam@49 169 // - If `data.size()` is not a multiple of 8, extra bytes past data.end() up until the next 8-byte
cannam@49 170 // boundary will be visible in the raw message when it is written out. Thus, there must be no
cannam@49 171 // secrets in these bytes. Data blobs obtained from other Cap'n Proto messages should be safe
cannam@49 172 // as these bytes should be zero (unless the sender had the same problem).
cannam@49 173 //
cannam@49 174 // The array will actually become one of the message's segments. The data can thus be adopted
cannam@49 175 // into the message tree without copying it. This is particularly useful when referencing very
cannam@49 176 // large blobs, such as whole mmap'd files.
cannam@49 177
cannam@49 178 private:
cannam@49 179 _::BuilderArena* arena;
cannam@49 180 _::CapTableBuilder* capTable;
cannam@49 181
cannam@49 182 inline explicit Orphanage(_::BuilderArena* arena, _::CapTableBuilder* capTable)
cannam@49 183 : arena(arena), capTable(capTable) {}
cannam@49 184
cannam@49 185 template <typename T, Kind = CAPNP_KIND(T)>
cannam@49 186 struct GetInnerBuilder;
cannam@49 187 template <typename T, Kind = CAPNP_KIND(T)>
cannam@49 188 struct GetInnerReader;
cannam@49 189 template <typename T>
cannam@49 190 struct NewOrphanListImpl;
cannam@49 191
cannam@49 192 friend class MessageBuilder;
cannam@49 193 friend struct _::OrphanageInternal;
cannam@49 194 };
cannam@49 195
cannam@49 196 // =======================================================================================
cannam@49 197 // Inline implementation details.
cannam@49 198
cannam@49 199 namespace _ { // private
cannam@49 200
cannam@49 201 template <typename T, Kind = CAPNP_KIND(T)>
cannam@49 202 struct OrphanGetImpl;
cannam@49 203
cannam@49 204 template <typename T>
cannam@49 205 struct OrphanGetImpl<T, Kind::PRIMITIVE> {
cannam@49 206 static inline void truncateListOf(_::OrphanBuilder& builder, ElementCount size) {
cannam@49 207 builder.truncate(size, _::elementSizeForType<T>());
cannam@49 208 }
cannam@49 209 };
cannam@49 210
cannam@49 211 template <typename T>
cannam@49 212 struct OrphanGetImpl<T, Kind::STRUCT> {
cannam@49 213 static inline typename T::Builder apply(_::OrphanBuilder& builder) {
cannam@49 214 return typename T::Builder(builder.asStruct(_::structSize<T>()));
cannam@49 215 }
cannam@49 216 static inline typename T::Reader applyReader(const _::OrphanBuilder& builder) {
cannam@49 217 return typename T::Reader(builder.asStructReader(_::structSize<T>()));
cannam@49 218 }
cannam@49 219 static inline void truncateListOf(_::OrphanBuilder& builder, ElementCount size) {
cannam@49 220 builder.truncate(size, _::structSize<T>());
cannam@49 221 }
cannam@49 222 };
cannam@49 223
cannam@49 224 #if !CAPNP_LITE
cannam@49 225 template <typename T>
cannam@49 226 struct OrphanGetImpl<T, Kind::INTERFACE> {
cannam@49 227 static inline typename T::Client apply(_::OrphanBuilder& builder) {
cannam@49 228 return typename T::Client(builder.asCapability());
cannam@49 229 }
cannam@49 230 static inline typename T::Client applyReader(const _::OrphanBuilder& builder) {
cannam@49 231 return typename T::Client(builder.asCapability());
cannam@49 232 }
cannam@49 233 static inline void truncateListOf(_::OrphanBuilder& builder, ElementCount size) {
cannam@49 234 builder.truncate(size, ElementSize::POINTER);
cannam@49 235 }
cannam@49 236 };
cannam@49 237 #endif // !CAPNP_LITE
cannam@49 238
cannam@49 239 template <typename T, Kind k>
cannam@49 240 struct OrphanGetImpl<List<T, k>, Kind::LIST> {
cannam@49 241 static inline typename List<T>::Builder apply(_::OrphanBuilder& builder) {
cannam@49 242 return typename List<T>::Builder(builder.asList(_::ElementSizeForType<T>::value));
cannam@49 243 }
cannam@49 244 static inline typename List<T>::Reader applyReader(const _::OrphanBuilder& builder) {
cannam@49 245 return typename List<T>::Reader(builder.asListReader(_::ElementSizeForType<T>::value));
cannam@49 246 }
cannam@49 247 static inline void truncateListOf(_::OrphanBuilder& builder, ElementCount size) {
cannam@49 248 builder.truncate(size, ElementSize::POINTER);
cannam@49 249 }
cannam@49 250 };
cannam@49 251
cannam@49 252 template <typename T>
cannam@49 253 struct OrphanGetImpl<List<T, Kind::STRUCT>, Kind::LIST> {
cannam@49 254 static inline typename List<T>::Builder apply(_::OrphanBuilder& builder) {
cannam@49 255 return typename List<T>::Builder(builder.asStructList(_::structSize<T>()));
cannam@49 256 }
cannam@49 257 static inline typename List<T>::Reader applyReader(const _::OrphanBuilder& builder) {
cannam@49 258 return typename List<T>::Reader(builder.asListReader(_::ElementSizeForType<T>::value));
cannam@49 259 }
cannam@49 260 static inline void truncateListOf(_::OrphanBuilder& builder, ElementCount size) {
cannam@49 261 builder.truncate(size, ElementSize::POINTER);
cannam@49 262 }
cannam@49 263 };
cannam@49 264
cannam@49 265 template <>
cannam@49 266 struct OrphanGetImpl<Text, Kind::BLOB> {
cannam@49 267 static inline Text::Builder apply(_::OrphanBuilder& builder) {
cannam@49 268 return Text::Builder(builder.asText());
cannam@49 269 }
cannam@49 270 static inline Text::Reader applyReader(const _::OrphanBuilder& builder) {
cannam@49 271 return Text::Reader(builder.asTextReader());
cannam@49 272 }
cannam@49 273 static inline void truncateListOf(_::OrphanBuilder& builder, ElementCount size) {
cannam@49 274 builder.truncate(size, ElementSize::POINTER);
cannam@49 275 }
cannam@49 276 };
cannam@49 277
cannam@49 278 template <>
cannam@49 279 struct OrphanGetImpl<Data, Kind::BLOB> {
cannam@49 280 static inline Data::Builder apply(_::OrphanBuilder& builder) {
cannam@49 281 return Data::Builder(builder.asData());
cannam@49 282 }
cannam@49 283 static inline Data::Reader applyReader(const _::OrphanBuilder& builder) {
cannam@49 284 return Data::Reader(builder.asDataReader());
cannam@49 285 }
cannam@49 286 static inline void truncateListOf(_::OrphanBuilder& builder, ElementCount size) {
cannam@49 287 builder.truncate(size, ElementSize::POINTER);
cannam@49 288 }
cannam@49 289 };
cannam@49 290
cannam@49 291 struct OrphanageInternal {
cannam@49 292 static inline _::BuilderArena* getArena(Orphanage orphanage) { return orphanage.arena; }
cannam@49 293 static inline _::CapTableBuilder* getCapTable(Orphanage orphanage) { return orphanage.capTable; }
cannam@49 294 };
cannam@49 295
cannam@49 296 } // namespace _ (private)
cannam@49 297
cannam@49 298 template <typename T>
cannam@49 299 inline BuilderFor<T> Orphan<T>::get() {
cannam@49 300 return _::OrphanGetImpl<T>::apply(builder);
cannam@49 301 }
cannam@49 302
cannam@49 303 template <typename T>
cannam@49 304 inline ReaderFor<T> Orphan<T>::getReader() const {
cannam@49 305 return _::OrphanGetImpl<T>::applyReader(builder);
cannam@49 306 }
cannam@49 307
cannam@49 308 template <typename T>
cannam@49 309 inline void Orphan<T>::truncate(uint size) {
cannam@49 310 _::OrphanGetImpl<ListElementType<T>>::truncateListOf(builder, size * ELEMENTS);
cannam@49 311 }
cannam@49 312
cannam@49 313 template <>
cannam@49 314 inline void Orphan<Text>::truncate(uint size) {
cannam@49 315 builder.truncateText(size * ELEMENTS);
cannam@49 316 }
cannam@49 317
cannam@49 318 template <>
cannam@49 319 inline void Orphan<Data>::truncate(uint size) {
cannam@49 320 builder.truncate(size * ELEMENTS, ElementSize::BYTE);
cannam@49 321 }
cannam@49 322
cannam@49 323 template <typename T>
cannam@49 324 struct Orphanage::GetInnerBuilder<T, Kind::STRUCT> {
cannam@49 325 static inline _::StructBuilder apply(typename T::Builder& t) {
cannam@49 326 return t._builder;
cannam@49 327 }
cannam@49 328 };
cannam@49 329
cannam@49 330 template <typename T>
cannam@49 331 struct Orphanage::GetInnerBuilder<T, Kind::LIST> {
cannam@49 332 static inline _::ListBuilder apply(typename T::Builder& t) {
cannam@49 333 return t.builder;
cannam@49 334 }
cannam@49 335 };
cannam@49 336
cannam@49 337 template <typename BuilderType>
cannam@49 338 Orphanage Orphanage::getForMessageContaining(BuilderType builder) {
cannam@49 339 auto inner = GetInnerBuilder<FromBuilder<BuilderType>>::apply(builder);
cannam@49 340 return Orphanage(inner.getArena(), inner.getCapTable());
cannam@49 341 }
cannam@49 342
cannam@49 343 template <typename RootType>
cannam@49 344 Orphan<RootType> Orphanage::newOrphan() const {
cannam@49 345 return Orphan<RootType>(_::OrphanBuilder::initStruct(arena, capTable, _::structSize<RootType>()));
cannam@49 346 }
cannam@49 347
cannam@49 348 template <typename T, Kind k>
cannam@49 349 struct Orphanage::NewOrphanListImpl<List<T, k>> {
cannam@49 350 static inline _::OrphanBuilder apply(
cannam@49 351 _::BuilderArena* arena, _::CapTableBuilder* capTable, uint size) {
cannam@49 352 return _::OrphanBuilder::initList(
cannam@49 353 arena, capTable, size * ELEMENTS, _::ElementSizeForType<T>::value);
cannam@49 354 }
cannam@49 355 };
cannam@49 356
cannam@49 357 template <typename T>
cannam@49 358 struct Orphanage::NewOrphanListImpl<List<T, Kind::STRUCT>> {
cannam@49 359 static inline _::OrphanBuilder apply(
cannam@49 360 _::BuilderArena* arena, _::CapTableBuilder* capTable, uint size) {
cannam@49 361 return _::OrphanBuilder::initStructList(
cannam@49 362 arena, capTable, size * ELEMENTS, _::structSize<T>());
cannam@49 363 }
cannam@49 364 };
cannam@49 365
cannam@49 366 template <>
cannam@49 367 struct Orphanage::NewOrphanListImpl<Text> {
cannam@49 368 static inline _::OrphanBuilder apply(
cannam@49 369 _::BuilderArena* arena, _::CapTableBuilder* capTable, uint size) {
cannam@49 370 return _::OrphanBuilder::initText(arena, capTable, size * BYTES);
cannam@49 371 }
cannam@49 372 };
cannam@49 373
cannam@49 374 template <>
cannam@49 375 struct Orphanage::NewOrphanListImpl<Data> {
cannam@49 376 static inline _::OrphanBuilder apply(
cannam@49 377 _::BuilderArena* arena, _::CapTableBuilder* capTable, uint size) {
cannam@49 378 return _::OrphanBuilder::initData(arena, capTable, size * BYTES);
cannam@49 379 }
cannam@49 380 };
cannam@49 381
cannam@49 382 template <typename RootType>
cannam@49 383 Orphan<RootType> Orphanage::newOrphan(uint size) const {
cannam@49 384 return Orphan<RootType>(NewOrphanListImpl<RootType>::apply(arena, capTable, size));
cannam@49 385 }
cannam@49 386
cannam@49 387 template <typename T>
cannam@49 388 struct Orphanage::GetInnerReader<T, Kind::STRUCT> {
cannam@49 389 static inline _::StructReader apply(const typename T::Reader& t) {
cannam@49 390 return t._reader;
cannam@49 391 }
cannam@49 392 };
cannam@49 393
cannam@49 394 template <typename T>
cannam@49 395 struct Orphanage::GetInnerReader<T, Kind::LIST> {
cannam@49 396 static inline _::ListReader apply(const typename T::Reader& t) {
cannam@49 397 return t.reader;
cannam@49 398 }
cannam@49 399 };
cannam@49 400
cannam@49 401 template <typename T>
cannam@49 402 struct Orphanage::GetInnerReader<T, Kind::BLOB> {
cannam@49 403 static inline const typename T::Reader& apply(const typename T::Reader& t) {
cannam@49 404 return t;
cannam@49 405 }
cannam@49 406 };
cannam@49 407
cannam@49 408 template <typename Reader>
cannam@49 409 inline Orphan<FromReader<Reader>> Orphanage::newOrphanCopy(Reader copyFrom) const {
cannam@49 410 return Orphan<FromReader<Reader>>(_::OrphanBuilder::copy(
cannam@49 411 arena, capTable, GetInnerReader<FromReader<Reader>>::apply(copyFrom)));
cannam@49 412 }
cannam@49 413
cannam@49 414 template <typename T>
cannam@49 415 inline Orphan<List<ListElementType<FromReader<T>>>>
cannam@49 416 Orphanage::newOrphanConcat(kj::ArrayPtr<T> lists) const {
cannam@49 417 return newOrphanConcat(kj::implicitCast<kj::ArrayPtr<const T>>(lists));
cannam@49 418 }
cannam@49 419 template <typename T>
cannam@49 420 inline Orphan<List<ListElementType<FromReader<T>>>>
cannam@49 421 Orphanage::newOrphanConcat(kj::ArrayPtr<const T> lists) const {
cannam@49 422 // Optimization / simplification: Rely on List<T>::Reader containing nothing except a
cannam@49 423 // _::ListReader.
cannam@49 424 static_assert(sizeof(T) == sizeof(_::ListReader), "lists are not bare readers?");
cannam@49 425 kj::ArrayPtr<const _::ListReader> raw(
cannam@49 426 reinterpret_cast<const _::ListReader*>(lists.begin()), lists.size());
cannam@49 427 typedef ListElementType<FromReader<T>> Element;
cannam@49 428 return Orphan<List<Element>>(
cannam@49 429 _::OrphanBuilder::concat(arena, capTable,
cannam@49 430 _::elementSizeForType<Element>(),
cannam@49 431 _::minStructSizeForElement<Element>(), raw));
cannam@49 432 }
cannam@49 433
cannam@49 434 inline Orphan<Data> Orphanage::referenceExternalData(Data::Reader data) const {
cannam@49 435 return Orphan<Data>(_::OrphanBuilder::referenceExternalData(arena, data));
cannam@49 436 }
cannam@49 437
cannam@49 438 } // namespace capnp
cannam@49 439
cannam@49 440 #endif // CAPNP_ORPHAN_H_