@@ -3684,18 +3684,28 @@ OIIO_API bool has_error();
36843684// / error messages.
36853685OIIO_API std::string geterror (bool clear = true );
36863686
3687- // / `OIIO::attribute()` sets a global attribute (i.e., a property or
3688- // / option) of OpenImageIO. The `name` designates the name of the attribute,
3689- // / `type` describes the type of data, and `value` is a pointer to memory
3690- // / containing the new value for the attribute.
3687+ // / @defgroup OIIO_attribute (global OIIO::attribute())
3688+ // / @{
36913689// /
3692- // / If the name is known, valid attribute that matches the type specified,
3693- // / the attribute will be set to the new value and `attribute()` will return
3694- // / `true`. If `name` is not recognized, or if the types do not match
3695- // / (e.g., `type` is `TypeFloat` but the named attribute is a string), the
3696- // / attribute will not be modified, and `attribute()` will return `false`.
3690+ // / `OIIO::attribute()` sets a global attribute (i.e., a property or option)
3691+ // / of OpenImageIO. The `name` designates the name of the attribute, `value`
3692+ // / is the value to use for the attribute, and for some varieties of the call,
3693+ // / `type` is a TypeDesc describing the data type.
36973694// /
3698- // / The following are the recognized attributes:
3695+ // / Most varieties of the call will return `true` if `name` is a known
3696+ // / attribute and its expected type is compatible with the type specified. If
3697+ // / `name` is not recognized, or if the types do not match (e.g., `type` is
3698+ // / `TypeFloat` but the named attribute is supposed to be a string), the
3699+ // / internal attribute will not be modified, and `attribute()` will return
3700+ // / `false`.
3701+ // /
3702+ // / In all cases, is up to the caller to ensure that `value` is or refers to
3703+ // / the right kind and size of storage for the given type.
3704+ // /
3705+ // / Note that all attributes set by this call may also be retrieved by
3706+ // / `OIIO::getattribute()`.
3707+ // /
3708+ // / RECOGNIZED ATTRIBUTES
36993709// /
37003710// / - `string options`
37013711// /
@@ -3914,7 +3924,25 @@ OIIO_API std::string geterror(bool clear = true);
39143924// / enable globally in an environment where security is a higher priority
39153925// / than being tolerant of partially broken image files.
39163926// /
3917- // / @version 3.1
3927+ // / EXAMPLES:
3928+ // / ```
3929+ // / // Setting single simple values simply:
3930+ // / bool ok = OIIO::getattribute("threads", 1); // implied: int
3931+ // / ok = OIIO::attribute("plugin_searchpath", "/foo/bar:/baz"); // implied: string
3932+ // /
3933+ // / // Setting a more complex value using a span, with explicit type
3934+ // / float missing[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
3935+ // / ok = OIIO::attribute("missingcolor", TypeDesc("float[4]"), make_span(missing));
3936+ // / ```
3937+ // /
3938+ // / The different varieties of `OIIO::attribute()` call follow:
3939+
3940+ // / Set the attribute's value from a span (which may be a single value). The
3941+ // / total size of `value` must match the `type` (if not, an assertion will be
3942+ // / thrown for debug builds of OIIO, an error will be printed for release
3943+ // / builds).
3944+ // /
3945+ // / @version 3.1+
39183946template <typename T>
39193947inline bool attribute (string_view name, TypeDesc type, span<T> value)
39203948{
@@ -3923,19 +3951,18 @@ inline bool attribute(string_view name, TypeDesc type, span<T> value)
39233951 return attribute (name, type, OIIO::as_bytes (value));
39243952}
39253953
3926- // / A version of `OIIO::attribute()` that takes its value from a span of
3927- // / untyped bytes. The total size of `value` must match the `type` (if not, an
3928- // / assertion will be thrown for debug builds of OIIO, an error will be
3929- // / printed for release builds).
3954+ // / Set the attribute's value from a span of untyped bytes. The total size of
3955+ // / `value` must match the `type` (if not, an assertion will be thrown for
3956+ // / debug builds of OIIO, an error will be printed for release builds).
39303957// /
3931- // / @version 3.1
3958+ // / @version 3.1+
39323959OIIO_API bool attribute (string_view name, TypeDesc type, cspan<std::byte> value);
39333960
3934- // / A version of `OIIO:: attribute()` where the `value` is only a pointer
3935- // / specifying the beginning of the memory where the value should be copied
3936- // / from. This is "unsafe" in the sense that there is no assurance that it
3937- // / points to a sufficient amount of memory , so the span-based versions of
3938- // / `attribute()` are preferred.
3961+ // / Set the named attribute to the contents of memory pointed to by `value`,
3962+ // / with the `type` implying the total size to be copied. This is "unsafe" in
3963+ // / the sense that there is no assurance that it points to a sufficient amount
3964+ // / of memory or value type , so the span-based versions of `attribute()` are
3965+ // / preferred.
39393966// /
39403967// / This was added in version 2.1.
39413968OIIO_API bool attribute (string_view name, TypeDesc type, const void * value);
@@ -3954,12 +3981,23 @@ inline bool attribute(string_view name, string_view value) {
39543981 const char *s = valstr.c_str ();
39553982 return attribute (name, TypeString, &s);
39563983}
3984+ // / @}
3985+
39573986
3958- // / Get the named global attribute of OpenImageIO, store it in `value`.
3959- // / Return `true` if found and it was compatible with the type specified,
3960- // / otherwise return `false` and do not modify the contents of `value`. It
3961- // / is up to the caller to ensure that `val` points to the right kind and
3962- // / size of storage for the given type.
3987+ // / @defgroup OIIO_getattribute (global OIIO::getattribute())
3988+ // / @{
3989+ // /
3990+ // / `OIIO::getattribute()` retrieves a named global attribute of OpenImageIO,
3991+ // / and stores it in `value`. These are the retrieval side of the symmetric
3992+ // / set of `OIIO::attribute()` calls.
3993+ // /
3994+ // / Most varieties of the call will return `true` if the named attribute was
3995+ // / found and it was compatible with the type specified, otherwise return
3996+ // / `false` and do not modify the contents of `value`. In all cases, it is up
3997+ // / to the caller to ensure that `val` points to the right kind and size of
3998+ // / storage for the given type.
3999+ // /
4000+ // / RECOGNIZED ATTRIBUTES
39634001// /
39644002// / In addition to being able to retrieve all the attributes that are
39654003// / documented as settable by the `OIIO::attribute()` call, `getattribute()`
@@ -4091,8 +4129,32 @@ inline bool attribute(string_view name, string_view value) {
40914129// / IBA::resize 20 0.24s (avg 12.18ms)
40924130// / IBA::zero 8 0.66ms (avg 0.08ms)
40934131// /
4132+ // / EXAMPLES:
4133+ // / ```
4134+ // / // Retrieving a single simple value with success/failure return:
4135+ // / int threads;
4136+ // / bool ok = OIIO::getattribute("threads", threads);
4137+ // / std::string path;
4138+ // / ok = OIIO::getattribute("plugin_searchpath", path);
40944139// /
4095- // / @version 3.1
4140+ // / // Directly returning a single simple value, with default to use
4141+ // / // if the attribute is not found:
4142+ // / int threads = OIIO::get_int_attribute("threads", 0);
4143+ // / string_view path = OIIO::get_string_attribute("plugin_searchpath");
4144+ // /
4145+ // / // Returning into a span, with explicit type
4146+ // / float missing[4];
4147+ // / ok = OIIO::getattribute("missingcolor", TypeDesc("float[4]"),
4148+ // / make_span(missing));
4149+ // / ```
4150+ // /
4151+ // / The different varieties of `OIIO::getattribute()` call follow:
4152+
4153+ // / Store the named attribute's current value into a writable span. The total
4154+ // / size of `value` must match the `type` (if not, an assertion will be thrown
4155+ // / for debug OIIO builds, an error will be printed for release builds).
4156+ // /
4157+ // / @version 3.1+
40964158template <typename T>
40974159inline bool getattribute (string_view name, TypeDesc type, span<T> value)
40984160{
@@ -4101,70 +4163,82 @@ inline bool getattribute(string_view name, TypeDesc type, span<T> value)
41014163 return OIIO::v3_1::getattribute (name, type, OIIO::as_writable_bytes (value));
41024164}
41034165
4104- // / A version of `getattribute()` that stores the value in a span of
4105- // / untyped bytes. The total size of `value` must match the `type` (if
4106- // / not, an assertion will be thrown for debug OIIO builds, an error will
4107- // / be printed for release builds).
4166+ // / Store the value in a span of untyped bytes. The total size of `value` must
4167+ // / match the `type` (if not, an assertion will be thrown for debug OIIO
4168+ // / builds, an error will be printed for release builds).
41084169// /
4109- // / @version 3.1
4170+ // / @version 3.1+
41104171OIIO_API bool getattribute (string_view name, TypeDesc type,
41114172 span<std::byte> value);
41124173
4113- // / A version of `OIIO::getattribute()` where the `value` is only a pointer
4114- // / specifying the beginning of the memory where the value should be copied.
4115- // / This is "unsafe" in the sense that there is no assurance that it points to
4116- // / a sufficient amount of memory, so the span-based versions of `attribute()`
4117- // / are preferred.
4174+ // / Store the value into memory pointed to by `val`. This is "unsafe" in the
4175+ // / sense that there is no assurance that it points to a sufficient amount of
4176+ // / memory or will be interpreted as the correct type, so the span-based
4177+ // / versions of `attribute()` are preferred.
41184178OIIO_API bool getattribute (string_view name, TypeDesc type, void * val);
41194179
4120- // / Shortcut getattribute() for retrieving a single integer. The value is
4121- // / placed in `value`, and the function returns `true` if the attribute was
4122- // / found and was legally convertible to an int.
4180+ // / Retrieve a single- integer attribute . The value is placed in `value`, and
4181+ // / the function returns `true` if the attribute was found and was legally
4182+ // / convertible to an int.
41234183inline bool getattribute (string_view name, int &value) {
41244184 return getattribute (name, TypeInt, &value);
41254185}
4126- // / Shortcut getattribute() for retrieving a single float. The value is placed
4127- // / in `value`, and the function returns `true` if the attribute was found and
4128- // / was legally convertible to a float.
4186+
4187+ // / Retrieve a single-float attribute. The value is placed in `value`, and the
4188+ // / function returns `true` if the attribute was found and was legally
4189+ // / convertible to a float.
41294190inline bool getattribute (string_view name, float &value) {
41304191 return getattribute (name, TypeFloat, &value);
41314192}
4132- // / Shortcut getattribute() for retrieving a single string as a `std::string`.
4133- // / The value is placed in `value`, and the function returns `true` if the
4134- // / attribute was found.
4193+
4194+ // / Retrieve a single-string attribute, placed as a `std::string` into
4195+ // / `value`, and the function returns `true` if the attribute was found and
4196+ // / was legally convertible to an string.
41354197inline bool getattribute (string_view name, std::string &value) {
41364198 ustring s;
41374199 bool ok = getattribute (name, TypeString, &s);
41384200 if (ok)
41394201 value = s.string ();
41404202 return ok;
41414203}
4142- // / Shortcut getattribute() for retrieving a single string as a `char*`.
4143- inline bool getattribute (string_view name, char **val) {
4144- return getattribute (name, TypeString, val);
4204+
4205+ // / Retrieve a single-string attribute, placed as a `const char*` into
4206+ // / `*value`, and the function returns `true` if the attribute was found and
4207+ // / was legally convertible to an string. Note that the `const char*`
4208+ // / retrieved is really the characters belonging to a `ustring`, and so is
4209+ // / owned by OIIO and should not be freed by the calling code.
4210+ inline bool getattribute (string_view name, char **value) {
4211+ return getattribute (name, TypeString, value);
41454212}
4146- // / Shortcut getattribute() for retrieving a single integer, with a supplied
4147- // / default value that will be returned if the attribute is not found or
4148- // / could not legally be converted to an int.
4213+
4214+ // / Retrieve a single-integer attribute, with a supplied default value that
4215+ // / will be returned if the attribute is not found or could not legally be
4216+ // / converted to an int.
41494217inline int get_int_attribute (string_view name, int defaultval=0 ) {
41504218 int val;
41514219 return getattribute (name, TypeInt, &val) ? val : defaultval;
41524220}
4153- // / Shortcut getattribute() for retrieving a single float, with a supplied
4154- // / default value that will be returned if the attribute is not found or
4155- // / could not legally be converted to a float.
4221+
4222+ // / Retrieve a single-float attribute, with a supplied default value that
4223+ // / will be returned if the attribute is not found or could not legally be
4224+ // / converted to a float.
41564225inline float get_float_attribute (string_view name, float defaultval=0 ) {
41574226 float val;
41584227 return getattribute (name, TypeFloat, &val) ? val : defaultval;
41594228}
4160- // / Shortcut getattribute() for retrieving a single string, with a supplied
4161- // / default value that will be returned if the attribute is not found.
4229+
4230+ // / Retrieve a single-string attribute, with a supplied default value that
4231+ // / will be returned if the attribute is not found or could not legally be
4232+ // / converted to an int. default value that will be returned if the attribute
4233+ // / is not found.
41624234inline string_view get_string_attribute (string_view name,
41634235 string_view defaultval = string_view()) {
41644236 ustring val;
41654237 return getattribute (name, TypeString, &val) ? string_view (val) : defaultval;
41664238}
41674239
4240+ // / @}
4241+
41684242
41694243// / Set the metadata of the `spec` to presume that color space is `name` (or
41704244// / to assume nothing about the color space if `name` is empty). The core
0 commit comments