MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ ensure_fields()

std::vector< std::string > MayaFlux::Buffers::VolumeGridBuffer::ensure_fields ( const std::vector< FieldDecl > &  decls)

Declare whichever of decls are not already present.

Built for a buffer whose fields were not all declared by the same call: IOManager::load_volume declares one field per grid a file reported, and a caller then wanting to run a simulation over that data needs velocity, pressure and the rest besides. Declaring those blind risks exactly what allocate_field already logs an error for — a name the file also happened to use, silently discarded, cascading into an empty-name ref everywhere that field is passed next. This checks first, so a name already present — whether reported by a loader or declared earlier by hand, nothing here distinguishes the two — is left alone rather than collided with.

A caller who wants a ScalarRef/VectorRef for an entry already present builds one directly: ScalarRef{name, owner} from its own name and this buffer, the same way declare_scalar builds the ref for a field it also just allocated. This does not return refs itself, since FieldDecl does not distinguish scalar from vector cleanly enough to hand back a uniformly typed collection.

Parameters
declsFields to ensure exist. Semantics and stride only take effect for an entry actually declared here; an entry already present keeps whatever it already has.
Returns
Names of the entries actually declared — not already present, and not rejected for the reasons allocate_field logs. A caller seeding initial values should seed exactly these and leave every other named field's existing data untouched.

Definition at line 201 of file VolumeGridBuffer.cpp.

202{
203 std::vector<std::string> declared;
204 declared.reserve(decls.size());
205
206 for (const auto& decl : decls) {
207 if (has_field(decl.name)) {
209 "VolumeGridBuffer::ensure_fields: '{}' already present, reused", decl.name);
210 continue;
211 }
212
213 if (allocate_field(decl.name, decl.stride_bytes, decl.double_buffered, decl.semantics)) {
214 declared.push_back(decl.name);
215 }
216 }
217
218 return declared;
219}
#define MF_DEBUG(comp, ctx,...)
bool allocate_field(const std::string &name, size_t stride_bytes, bool double_buffered)
Allocate one field's slots and register it.
bool has_field(const std::string &name) const
Whether a field of this name was declared.
@ Init
Engine/subsystem initialization.
@ Buffers
Buffers, Managers, processors and processing chains.

References allocate_field(), MayaFlux::Journal::Buffers, has_field(), MayaFlux::Journal::Init, and MF_DEBUG.

+ Here is the call graph for this function: