annotate win64-msvc/include/capnp/orphan.h @ 136:ce0478b62770

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