Skip to content

Commit d798169

Browse files
committed
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 <lg@larrygritz.com>
1 parent 55da204 commit d798169

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
@@ -3684,18 +3684,28 @@ OIIO_API bool has_error();
36843684
/// error messages.
36853685
OIIO_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+
39183946
template<typename T>
39193947
inline 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+
39323959
OIIO_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.
39413968
OIIO_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+
40964158
template<typename T>
40974159
inline 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+
41104171
OIIO_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.
41184178
OIIO_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.
41234183
inline 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.
41294190
inline 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.
41354197
inline 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.
41494217
inline 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.
41564225
inline 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.
41624234
inline 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

Comments
 (0)