Materialx Protobuf API 1.39.5
Serialization API to convert between MaterialX and Google Protobuf formats.
Loading...
Searching...
No Matches
VersionUpgrader Class Reference

Handles schema version upgrades for MaterialX protobuf documents. More...

#include <materialx_serializer.h>

Static Public Member Functions

static void upgradeV0ToV1 (MaterialXDocument &pb_doc)
 Example upgrade from version 0.x to 1.x.
 
static void upgradeV1ToV2 (MaterialXDocument &pb_doc)
 Example upgrade from version 1.x to 2.x.
 
static std::string getVersionString (const MaterialXDocument &pb_doc)
 Get version as a string (e.g., "1.0.0")
 
static int compareVersions (uint32_t v1_major, uint32_t v1_minor, uint32_t v1_patch, uint32_t v2_major, uint32_t v2_minor, uint32_t v2_patch)
 Compare two versions.
 

Detailed Description

Handles schema version upgrades for MaterialX protobuf documents.

  • Add upgrade methods for each major version transition.
  • Upgrade methods should modify the protobuf message in-place or return a new one.

Member Function Documentation

◆ compareVersions()

int VersionUpgrader::compareVersions ( uint32_t v1_major,
uint32_t v1_minor,
uint32_t v1_patch,
uint32_t v2_major,
uint32_t v2_minor,
uint32_t v2_patch )
static

Compare two versions.

Returns
-1 if v1 < v2, 0 if equal, 1 if v1 > v2
351 {
352 if (v1_major != v2_major) {
353 return (v1_major < v2_major) ? -1 : 1;
354 }
355 if (v1_minor != v2_minor) {
356 return (v1_minor < v2_minor) ? -1 : 1;
357 }
358 if (v1_patch != v2_patch) {
359 return (v1_patch < v2_patch) ? -1 : 1;
360 }
361 return 0;
362}

◆ getVersionString()

std::string VersionUpgrader::getVersionString ( const MaterialXDocument & pb_doc)
static

Get version as a string (e.g., "1.0.0")

Parameters
pb_docProtobuf document.
Returns
Version string.
340 {
341 if (pb_doc.has_schema_version()) {
342 const Version& v = pb_doc.schema_version();
343 std::ostringstream oss;
344 oss << v.major() << "." << v.minor() << "." << v.patch();
345 return oss.str();
346 }
347 return "unknown";
348}

◆ upgradeV0ToV1()

void VersionUpgrader::upgradeV0ToV1 ( MaterialXDocument & pb_doc)
static

Example upgrade from version 0.x to 1.x.

Parameters
pb_docThe protobuf document to upgrade (modified in-place).
330 {
331 // Example: If v1 added a new required field, set defaults here
332 // Currently no upgrade needed
333}

◆ upgradeV1ToV2()

void VersionUpgrader::upgradeV1ToV2 ( MaterialXDocument & pb_doc)
static

Example upgrade from version 1.x to 2.x.

Parameters
pb_docThe protobuf document to upgrade (modified in-place).
335 {
336 // Example: If v2 renamed a field, copy old to new
337 // Currently no upgrade needed
338}

The documentation for this class was generated from the following files: