Skip to content

Commit 4134467

Browse files
authored
docs: fix missing docs for OIIO:attribute() and OIIO::getattribute() (#4987)
Rearrangements in 3.1 dropped the list of recognized attributes from the visible online docs and failed to document the span varieties. We fix and also reword a lot of the descriptions for clarity and uniformity. The previous organization was that there were several varieties of attribute(). In the header, the first one had the overall long explanation, including the list of all the recognized attributes. The other ones had short explanations of how they differed. In the docs, each one was referenced explicitly, pulling in its attendant bit of documentation. What really happened is that in the header, I made the new span-based version the "flagship" one with the full explanation, but I neglected to reference it in the docs, so the long description disappeared. I could have fixed by just adding refs to the new functions to the docs, as I originally meant to. But while I was there, I took the opportunity to surround the whole collection with a group marker, and then include the lot of them with a single reference to the group, rather than need to refer to each function variant individually. And while I was at it, I also reworded (and hopefully improved) some of those explanations. Signed-off-by: Larry Gritz <[email protected]>
1 parent ff89654 commit 4134467

File tree

2 files changed

+135
-98
lines changed

2 files changed

+135
-98
lines changed

src/doc/imageioapi.rst

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -215,49 +215,12 @@ These helper functions are not part of any other OpenImageIO class, they
215215
just exist in the OpenImageIO namespace as general utilities. (See
216216
:ref:`sec-pythonmiscapi` for the corresponding Python bindings.)
217217

218-
.. doxygenfunction:: OIIO::attribute(string_view, TypeDesc, const void *)
219-
220-
.. cpp:function:: bool OIIO::attribute(string_view name, int val)
221-
bool OIIO::attribute(string_view name, float val)
222-
bool OIIO::attribute(string_view name, string_view val)
223-
224-
Shortcuts for setting an attribute to a single int, float, or string.
225-
226-
227-
.. doxygenfunction:: OIIO::getattribute(string_view, TypeDesc, void *)
228-
229-
230-
.. cpp:function:: bool getattribute (string_view name, int &val)
231-
bool getattribute (string_view name, float &val)
232-
bool getattribute (string_view name, char **val)
233-
bool getattribute (string_view name, std::string& val)
234-
235-
Specialized versions of `getattribute()` in which the data type is
236-
implied by the type of the argument (for single int, float, or string).
237-
Two string versions exist: one that retrieves it as a `std::string` and
238-
another that retrieves it as a `char *`. In all cases, the return value
239-
is `true` if the attribute is found and the requested data type
240-
conversion was legal.
241-
242-
EXAMPLES::
243-
244-
int threads;
245-
OIIO::getattribute ("threads", &threads);
246-
std::string path;
247-
OIIO::getattribute ("plugin_searchpath", path);
248-
249-
.. cpp:function:: int get_int_attribute (string_view name, int defaultvalue=0)
250-
float get_float_attribute (string_view name, float defaultvalue=0)
251-
string_view get_string_attribute (string_view name, string_view defaultvalue="")
252-
253-
Specialized versions of `getattribute()` for common types, in which the
254-
data is returned directly, and a supplied default value is returned if
255-
the attribute was not found.
218+
.. doxygengroup:: OIIO_attribute
219+
..
256220
257-
EXAMPLES::
258221

259-
int threads = OIIO::get_int_attribute ("threads", 0);
260-
string_view path = OIIO::get_string_attribute ("plugin_searchpath");
222+
.. doxygengroup:: OIIO_getattribute
223+
..
261224
262225

263226

src/include/OpenImageIO/imageio.h

Lines changed: 131 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3697,18 +3697,28 @@ OIIO_API bool has_error();
36973697
/// error messages.
36983698
OIIO_API std::string geterror(bool clear = true);
36993699

3700-
/// `OIIO::attribute()` sets a global attribute (i.e., a property or
3701-
/// option) of OpenImageIO. The `name` designates the name of the attribute,
3702-
/// `type` describes the type of data, and `value` is a pointer to memory
3703-
/// containing the new value for the attribute.
3700+
/// @defgroup OIIO_attribute (global OIIO::attribute())
3701+
/// @{
37043702
///
3705-
/// If the name is known, valid attribute that matches the type specified,
3706-
/// the attribute will be set to the new value and `attribute()` will return
3707-
/// `true`. If `name` is not recognized, or if the types do not match
3708-
/// (e.g., `type` is `TypeFloat` but the named attribute is a string), the
3709-
/// attribute will not be modified, and `attribute()` will return `false`.
3703+
/// `OIIO::attribute()` sets a global attribute (i.e., a property or option)
3704+
/// of OpenImageIO. The `name` designates the name of the attribute, `value`
3705+
/// is the value to use for the attribute, and for some varieties of the call,
3706+
/// `type` is a TypeDesc describing the data type.
37103707
///
3711-
/// The following are the recognized attributes:
3708+
/// Most varieties of the call will return `true` if `name` is a known
3709+
/// attribute and its expected type is compatible with the type specified. If
3710+
/// `name` is not recognized, or if the types do not match (e.g., `type` is
3711+
/// `TypeFloat` but the named attribute is supposed to be a string), the
3712+
/// internal attribute will not be modified, and `attribute()` will return
3713+
/// `false`.
3714+
///
3715+
/// In all cases, is up to the caller to ensure that `value` is or refers to
3716+
/// the right kind and size of storage for the given type.
3717+
///
3718+
/// Note that all attributes set by this call may also be retrieved by
3719+
/// `OIIO::getattribute()`.
3720+
///
3721+
/// RECOGNIZED ATTRIBUTES
37123722
///
37133723
/// - `string options`
37143724
///
@@ -3927,7 +3937,25 @@ OIIO_API std::string geterror(bool clear = true);
39273937
/// enable globally in an environment where security is a higher priority
39283938
/// than being tolerant of partially broken image files.
39293939
///
3930-
/// @version 3.1
3940+
/// EXAMPLES:
3941+
/// ```
3942+
/// // Setting single simple values simply:
3943+
/// bool ok = OIIO::getattribute("threads", 1); // implied: int
3944+
/// ok = OIIO::attribute("plugin_searchpath", "/foo/bar:/baz"); // implied: string
3945+
///
3946+
/// // Setting a more complex value using a span, with explicit type
3947+
/// float missing[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
3948+
/// ok = OIIO::attribute("missingcolor", TypeDesc("float[4]"), make_span(missing));
3949+
/// ```
3950+
///
3951+
/// The different varieties of `OIIO::attribute()` call follow:
3952+
3953+
/// Set the attribute's value from a span (which may be a single value). The
3954+
/// total size of `value` must match the `type` (if not, an assertion will be
3955+
/// thrown for debug builds of OIIO, an error will be printed for release
3956+
/// builds).
3957+
///
3958+
/// @version 3.1+
39313959
template<typename T>
39323960
inline bool attribute(string_view name, TypeDesc type, span<T> value)
39333961
{
@@ -3936,19 +3964,18 @@ inline bool attribute(string_view name, TypeDesc type, span<T> value)
39363964
return attribute(name, type, OIIO::as_bytes(value));
39373965
}
39383966

3939-
/// A version of `OIIO::attribute()` that takes its value from a span of
3940-
/// untyped bytes. The total size of `value` must match the `type` (if not, an
3941-
/// assertion will be thrown for debug builds of OIIO, an error will be
3942-
/// printed for release builds).
3967+
/// Set the attribute's value from a span of untyped bytes. The total size of
3968+
/// `value` must match the `type` (if not, an assertion will be thrown for
3969+
/// debug builds of OIIO, an error will be printed for release builds).
39433970
///
3944-
/// @version 3.1
3971+
/// @version 3.1+
39453972
OIIO_API bool attribute(string_view name, TypeDesc type, cspan<std::byte> value);
39463973

3947-
/// A version of `OIIO::attribute()` where the `value` is only a pointer
3948-
/// specifying the beginning of the memory where the value should be copied
3949-
/// from. This is "unsafe" in the sense that there is no assurance that it
3950-
/// points to a sufficient amount of memory, so the span-based versions of
3951-
/// `attribute()` are preferred.
3974+
/// Set the named attribute to the contents of memory pointed to by `value`,
3975+
/// with the `type` implying the total size to be copied. This is "unsafe" in
3976+
/// the sense that there is no assurance that it points to a sufficient amount
3977+
/// of memory or value type, so the span-based versions of `attribute()` are
3978+
/// preferred.
39523979
///
39533980
/// This was added in version 2.1.
39543981
OIIO_API bool attribute(string_view name, TypeDesc type, const void* value);
@@ -3967,12 +3994,23 @@ inline bool attribute(string_view name, string_view value) {
39673994
const char *s = valstr.c_str();
39683995
return attribute(name, TypeString, &s);
39693996
}
3997+
/// @}
3998+
39703999

3971-
/// Get the named global attribute of OpenImageIO, store it in `value`.
3972-
/// Return `true` if found and it was compatible with the type specified,
3973-
/// otherwise return `false` and do not modify the contents of `value`. It
3974-
/// is up to the caller to ensure that `val` points to the right kind and
3975-
/// size of storage for the given type.
4000+
/// @defgroup OIIO_getattribute (global OIIO::getattribute())
4001+
/// @{
4002+
///
4003+
/// `OIIO::getattribute()` retrieves a named global attribute of OpenImageIO,
4004+
/// and stores it in `value`. These are the retrieval side of the symmetric
4005+
/// set of `OIIO::attribute()` calls.
4006+
///
4007+
/// Most varieties of the call will return `true` if the named attribute was
4008+
/// found and it was compatible with the type specified, otherwise return
4009+
/// `false` and do not modify the contents of `value`. In all cases, it is up
4010+
/// to the caller to ensure that `val` points to the right kind and size of
4011+
/// storage for the given type.
4012+
///
4013+
/// RECOGNIZED ATTRIBUTES
39764014
///
39774015
/// In addition to being able to retrieve all the attributes that are
39784016
/// documented as settable by the `OIIO::attribute()` call, `getattribute()`
@@ -4104,8 +4142,32 @@ inline bool attribute(string_view name, string_view value) {
41044142
/// IBA::resize 20 0.24s (avg 12.18ms)
41054143
/// IBA::zero 8 0.66ms (avg 0.08ms)
41064144
///
4145+
/// EXAMPLES:
4146+
/// ```
4147+
/// // Retrieving a single simple value with success/failure return:
4148+
/// int threads;
4149+
/// bool ok = OIIO::getattribute("threads", threads);
4150+
/// std::string path;
4151+
/// ok = OIIO::getattribute("plugin_searchpath", path);
41074152
///
4108-
/// @version 3.1
4153+
/// // Directly returning a single simple value, with default to use
4154+
/// // if the attribute is not found:
4155+
/// int threads = OIIO::get_int_attribute("threads", 0);
4156+
/// string_view path = OIIO::get_string_attribute("plugin_searchpath");
4157+
///
4158+
/// // Returning into a span, with explicit type
4159+
/// float missing[4];
4160+
/// ok = OIIO::getattribute("missingcolor", TypeDesc("float[4]"),
4161+
/// make_span(missing));
4162+
/// ```
4163+
///
4164+
/// The different varieties of `OIIO::getattribute()` call follow:
4165+
4166+
/// Store the named attribute's current value into a writable span. The total
4167+
/// size of `value` must match the `type` (if not, an assertion will be thrown
4168+
/// for debug OIIO builds, an error will be printed for release builds).
4169+
///
4170+
/// @version 3.1+
41094171
template<typename T>
41104172
inline bool getattribute(string_view name, TypeDesc type, span<T> value)
41114173
{
@@ -4114,70 +4176,82 @@ inline bool getattribute(string_view name, TypeDesc type, span<T> value)
41144176
return OIIO::v3_1::getattribute(name, type, OIIO::as_writable_bytes(value));
41154177
}
41164178

4117-
/// A version of `getattribute()` that stores the value in a span of
4118-
/// untyped bytes. The total size of `value` must match the `type` (if
4119-
/// not, an assertion will be thrown for debug OIIO builds, an error will
4120-
/// be printed for release builds).
4179+
/// Store the value in a span of untyped bytes. The total size of `value` must
4180+
/// match the `type` (if not, an assertion will be thrown for debug OIIO
4181+
/// builds, an error will be printed for release builds).
41214182
///
4122-
/// @version 3.1
4183+
/// @version 3.1+
41234184
OIIO_API bool getattribute(string_view name, TypeDesc type,
41244185
span<std::byte> value);
41254186

4126-
/// A version of `OIIO::getattribute()` where the `value` is only a pointer
4127-
/// specifying the beginning of the memory where the value should be copied.
4128-
/// This is "unsafe" in the sense that there is no assurance that it points to
4129-
/// a sufficient amount of memory, so the span-based versions of `attribute()`
4130-
/// are preferred.
4187+
/// Store the value into memory pointed to by `val`. This is "unsafe" in the
4188+
/// sense that there is no assurance that it points to a sufficient amount of
4189+
/// memory or will be interpreted as the correct type, so the span-based
4190+
/// versions of `attribute()` are preferred.
41314191
OIIO_API bool getattribute(string_view name, TypeDesc type, void* val);
41324192

4133-
/// Shortcut getattribute() for retrieving a single integer. The value is
4134-
/// placed in `value`, and the function returns `true` if the attribute was
4135-
/// found and was legally convertible to an int.
4193+
/// Retrieve a single-integer attribute. The value is placed in `value`, and
4194+
/// the function returns `true` if the attribute was found and was legally
4195+
/// convertible to an int.
41364196
inline bool getattribute (string_view name, int &value) {
41374197
return getattribute (name, TypeInt, &value);
41384198
}
4139-
/// Shortcut getattribute() for retrieving a single float. The value is placed
4140-
/// in `value`, and the function returns `true` if the attribute was found and
4141-
/// was legally convertible to a float.
4199+
4200+
/// Retrieve a single-float attribute. The value is placed in `value`, and the
4201+
/// function returns `true` if the attribute was found and was legally
4202+
/// convertible to a float.
41424203
inline bool getattribute (string_view name, float &value) {
41434204
return getattribute (name, TypeFloat, &value);
41444205
}
4145-
/// Shortcut getattribute() for retrieving a single string as a `std::string`.
4146-
/// The value is placed in `value`, and the function returns `true` if the
4147-
/// attribute was found.
4206+
4207+
/// Retrieve a single-string attribute, placed as a `std::string` into
4208+
/// `value`, and the function returns `true` if the attribute was found and
4209+
/// was legally convertible to an string.
41484210
inline bool getattribute (string_view name, std::string &value) {
41494211
ustring s;
41504212
bool ok = getattribute (name, TypeString, &s);
41514213
if (ok)
41524214
value = s.string();
41534215
return ok;
41544216
}
4155-
/// Shortcut getattribute() for retrieving a single string as a `char*`.
4156-
inline bool getattribute (string_view name, char **val) {
4157-
return getattribute (name, TypeString, val);
4217+
4218+
/// Retrieve a single-string attribute, placed as a `const char*` into
4219+
/// `*value`, and the function returns `true` if the attribute was found and
4220+
/// was legally convertible to an string. Note that the `const char*`
4221+
/// retrieved is really the characters belonging to a `ustring`, and so is
4222+
/// owned by OIIO and should not be freed by the calling code.
4223+
inline bool getattribute (string_view name, char **value) {
4224+
return getattribute (name, TypeString, value);
41584225
}
4159-
/// Shortcut getattribute() for retrieving a single integer, with a supplied
4160-
/// default value that will be returned if the attribute is not found or
4161-
/// could not legally be converted to an int.
4226+
4227+
/// Retrieve a single-integer attribute, with a supplied default value that
4228+
/// will be returned if the attribute is not found or could not legally be
4229+
/// converted to an int.
41624230
inline int get_int_attribute (string_view name, int defaultval=0) {
41634231
int val;
41644232
return getattribute (name, TypeInt, &val) ? val : defaultval;
41654233
}
4166-
/// Shortcut getattribute() for retrieving a single float, with a supplied
4167-
/// default value that will be returned if the attribute is not found or
4168-
/// could not legally be converted to a float.
4234+
4235+
/// Retrieve a single-float attribute, with a supplied default value that
4236+
/// will be returned if the attribute is not found or could not legally be
4237+
/// converted to a float.
41694238
inline float get_float_attribute (string_view name, float defaultval=0) {
41704239
float val;
41714240
return getattribute (name, TypeFloat, &val) ? val : defaultval;
41724241
}
4173-
/// Shortcut getattribute() for retrieving a single string, with a supplied
4174-
/// default value that will be returned if the attribute is not found.
4242+
4243+
/// Retrieve a single-string attribute, with a supplied default value that
4244+
/// will be returned if the attribute is not found or could not legally be
4245+
/// converted to an int. default value that will be returned if the attribute
4246+
/// is not found.
41754247
inline string_view get_string_attribute (string_view name,
41764248
string_view defaultval = string_view()) {
41774249
ustring val;
41784250
return getattribute (name, TypeString, &val) ? string_view(val) : defaultval;
41794251
}
41804252

4253+
/// @}
4254+
41814255

41824256
/// Set the metadata of the `spec` to presume that color space is `name` (or
41834257
/// to assume nothing about the color space if `name` is empty). The core

0 commit comments

Comments
 (0)