diff options
| author | David Robillard <d@drobilla.net> | 2012-06-13 16:47:10 +0000 | 
|---|---|---|
| committer | David Robillard <d@drobilla.net> | 2012-06-13 16:47:10 +0000 | 
| commit | 0faeed1d24ce6c9a30c62311c6c409d5bacde0f6 (patch) | |
| tree | 2077fb464d06f3f5f926b41107af55e8f34495c7 /lv2/lv2plug.in/ns/ext | |
| parent | f885fe814c66e761d1f014c3e8428d7a3aafc271 (diff) | |
| download | lv2-0faeed1d24ce6c9a30c62311c6c409d5bacde0f6.tar.xz | |
Add lv2_atom_object_body_get().
Diffstat (limited to 'lv2/lv2plug.in/ns/ext')
| -rw-r--r-- | lv2/lv2plug.in/ns/ext/atom/atom.ttl | 2 | ||||
| -rw-r--r-- | lv2/lv2plug.in/ns/ext/atom/util.h | 39 | 
2 files changed, 40 insertions, 1 deletions
diff --git a/lv2/lv2plug.in/ns/ext/atom/atom.ttl b/lv2/lv2plug.in/ns/ext/atom/atom.ttl index e7ef5a8..ef37293 100644 --- a/lv2/lv2plug.in/ns/ext/atom/atom.ttl +++ b/lv2/lv2plug.in/ns/ext/atom/atom.ttl @@ -29,6 +29,8 @@  				rdfs:label "Fix implicit conversions in forge.h that are invalid in C++11."  			] , [  				rdfs:label "Fix lv2_atom_object_next() on 32-bit platforms." +			] , [ +				rdfs:label "Add lv2_atom_object_body_get()."  			]  		]  	] , [ diff --git a/lv2/lv2plug.in/ns/ext/atom/util.h b/lv2/lv2plug.in/ns/ext/atom/util.h index 6ba178c..ac5eb2f 100644 --- a/lv2/lv2plug.in/ns/ext/atom/util.h +++ b/lv2/lv2plug.in/ns/ext/atom/util.h @@ -300,7 +300,44 @@ lv2_atom_object_query(const LV2_Atom_Object* object,  }  /** -   Variable argument version of lv2_atom_object_get(). +   Body only version of lv2_atom_object_get(). +*/ +static inline int +lv2_atom_object_body_get(uint32_t size, const LV2_Atom_Object_Body* body, ...) +{ +	int matches   = 0; +	int n_queries = 0; + +	/* Count number of keys so we can short-circuit when done */ +	va_list args; +	va_start(args, body); +	for (n_queries = 0; va_arg(args, uint32_t); ++n_queries) { +		if (!va_arg(args, const LV2_Atom**)) { +			return -1; +		} +	} +	va_end(args); + +	LV2_ATOM_OBJECT_BODY_FOREACH(body, size, prop) { +		va_start(args, body); +		for (int i = 0; i < n_queries; ++i) { +			uint32_t         qkey = va_arg(args, uint32_t); +			const LV2_Atom** qval = va_arg(args, const LV2_Atom**); +			if (qkey == prop->key && !*qval) { +				*qval = &prop->value; +				if (++matches == n_queries) { +					return matches; +				} +				break; +			} +		} +		va_end(args); +	} +	return matches; +} + +/** +   Variable argument version of lv2_atom_object_query().     This is nicer-looking in code, but a bit more error-prone since it is not     type safe and the argument list must be terminated.  |