Blame src/pcm/interval_inline.h

Packit 4a16fb
/*
Packit 4a16fb
 *  Interval inlines
Packit 4a16fb
 *  Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
Packit 4a16fb
 *
Packit 4a16fb
 *
Packit 4a16fb
 *   This library is free software; you can redistribute it and/or modify
Packit 4a16fb
 *   it under the terms of the GNU Lesser General Public License as
Packit 4a16fb
 *   published by the Free Software Foundation; either version 2.1 of
Packit 4a16fb
 *   the License, or (at your option) any later version.
Packit 4a16fb
 *
Packit 4a16fb
 *   This program is distributed in the hope that it will be useful,
Packit 4a16fb
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 4a16fb
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 4a16fb
 *   GNU Lesser General Public License for more details.
Packit 4a16fb
 *
Packit 4a16fb
 *   You should have received a copy of the GNU Lesser General Public
Packit 4a16fb
 *   License along with this library; if not, write to the Free Software
Packit 4a16fb
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit 4a16fb
 *
Packit 4a16fb
 */
Packit 4a16fb
  
Packit 4a16fb
#define INTERVAL_INLINE static inline
Packit 4a16fb
Packit 4a16fb
INTERVAL_INLINE void snd_interval_any(snd_interval_t *i)
Packit 4a16fb
{
Packit 4a16fb
	i->min = 0;
Packit 4a16fb
	i->openmin = 0;
Packit 4a16fb
	i->max = UINT_MAX;
Packit 4a16fb
	i->openmax = 0;
Packit 4a16fb
	i->integer = 0;
Packit 4a16fb
	i->empty = 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
INTERVAL_INLINE void snd_interval_none(snd_interval_t *i)
Packit 4a16fb
{
Packit 4a16fb
	i->empty = 1;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
INTERVAL_INLINE int snd_interval_checkempty(const snd_interval_t *i)
Packit 4a16fb
{
Packit 4a16fb
	return (i->min > i->max ||
Packit 4a16fb
		(i->min == i->max && (i->openmin || i->openmax)));
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
INTERVAL_INLINE int snd_interval_empty(const snd_interval_t *i)
Packit 4a16fb
{
Packit 4a16fb
	return i->empty;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
INTERVAL_INLINE int snd_interval_single(const snd_interval_t *i)
Packit 4a16fb
{
Packit 4a16fb
	assert(!snd_interval_empty(i));
Packit 4a16fb
	return (i->min == i->max || 
Packit 4a16fb
		(i->min + 1 == i->max && (i->openmin || i->openmax)));
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
INTERVAL_INLINE int snd_interval_value(const snd_interval_t *i)
Packit 4a16fb
{
Packit 4a16fb
	assert(snd_interval_single(i));
Packit 4a16fb
	if (i->openmin && !i->openmax)
Packit 4a16fb
		return i->max;
Packit 4a16fb
	return i->min;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
INTERVAL_INLINE void snd_interval_set_value(snd_interval_t *i, unsigned int val)
Packit 4a16fb
{
Packit 4a16fb
	i->openmax = i->openmin = 0;
Packit 4a16fb
	i->min = i->max = val;
Packit 4a16fb
	i->integer = 0;
Packit 4a16fb
	i->empty = 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
INTERVAL_INLINE int snd_interval_min(const snd_interval_t *i)
Packit 4a16fb
{
Packit 4a16fb
	assert(!snd_interval_empty(i));
Packit 4a16fb
	return i->min;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
INTERVAL_INLINE int snd_interval_max(const snd_interval_t *i)
Packit 4a16fb
{
Packit 4a16fb
	assert(!snd_interval_empty(i));
Packit 4a16fb
	return i->max;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
INTERVAL_INLINE void snd_interval_set_minmax(snd_interval_t *i, unsigned int min, unsigned int max)
Packit 4a16fb
{
Packit 4a16fb
	i->openmax = i->openmin = 0;
Packit 4a16fb
	i->min = min;
Packit 4a16fb
	i->max = max;
Packit 4a16fb
	i->integer = 0;
Packit 4a16fb
	i->empty = 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
INTERVAL_INLINE int snd_interval_test(const snd_interval_t *i, unsigned int val)
Packit 4a16fb
{
Packit 4a16fb
	return !((i->min > val || (i->min == val && i->openmin) ||
Packit 4a16fb
		  i->max < val || (i->max == val && i->openmax)));
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
INTERVAL_INLINE void snd_interval_copy(snd_interval_t *d, const snd_interval_t *s)
Packit 4a16fb
{
Packit 4a16fb
	*d = *s;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
INTERVAL_INLINE int snd_interval_setinteger(snd_interval_t *i)
Packit 4a16fb
{
Packit 4a16fb
	if (i->integer)
Packit 4a16fb
		return 0;
Packit 4a16fb
	if (i->openmin && i->openmax && i->min == i->max)
Packit 4a16fb
		return -EINVAL;
Packit 4a16fb
	i->integer = 1;
Packit 4a16fb
	return 1;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
INTERVAL_INLINE void snd_interval_floor(snd_interval_t *i)
Packit 4a16fb
{
Packit 4a16fb
	if (i->integer || snd_interval_empty(i))
Packit 4a16fb
		return;
Packit 4a16fb
	i->openmin = 0;
Packit 4a16fb
	if (i->openmax) {
Packit 4a16fb
		i->max--;
Packit 4a16fb
		i->openmax = 0;
Packit 4a16fb
	}
Packit 4a16fb
	i->integer = 1;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
INTERVAL_INLINE void snd_interval_unfloor(snd_interval_t *i)
Packit 4a16fb
{
Packit 4a16fb
	if (snd_interval_empty(i))
Packit 4a16fb
		return;
Packit 4a16fb
	if (i->max == UINT_MAX)
Packit 4a16fb
		return;
Packit 4a16fb
	if (i->openmax)
Packit 4a16fb
		return;
Packit 4a16fb
	i->max++;
Packit 4a16fb
	i->openmax = 1;
Packit 4a16fb
	i->integer = 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
Packit 4a16fb
INTERVAL_INLINE int snd_interval_always_eq(const snd_interval_t *i1, const snd_interval_t *i2)
Packit 4a16fb
{
Packit 4a16fb
	return snd_interval_single(i1) && snd_interval_single(i2) &&
Packit 4a16fb
		snd_interval_value(i1) == snd_interval_value(i2);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
INTERVAL_INLINE int snd_interval_never_eq(const snd_interval_t *i1, const snd_interval_t *i2)
Packit 4a16fb
{
Packit 4a16fb
	
Packit 4a16fb
	return (i1->max < i2->min || 
Packit 4a16fb
		(i1->max == i2->min &&
Packit 4a16fb
		 (i1->openmax || i1->openmin)) ||
Packit 4a16fb
		i1->min > i2->max ||
Packit 4a16fb
		(i1->min == i2->max &&
Packit 4a16fb
		 (i1->openmin || i2->openmax)));
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
Packit 4a16fb