annotate win32-mingw/include/capnp/orphan.h @ 50:37d53a7e8262

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