annotate win64-msvc/include/capnp/orphan.h @ 47:d93140aac40b

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