annotate osx/include/capnp/orphan.h @ 139:413e081fcc6f

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