Initial Import
[profile/ivi/alsa-lib.git] / src / pcm / interval_inline.h
1 /*
2  *  Interval inlines
3  *  Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
4  *
5  *
6  *   This library is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU Lesser General Public License as
8  *   published by the Free Software Foundation; either version 2.1 of
9  *   the License, or (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU Lesser General Public License for more details.
15  *
16  *   You should have received a copy of the GNU Lesser General Public
17  *   License along with this library; if not, write to the Free Software
18  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19  *
20  */
21   
22 #define INTERVAL_INLINE static inline
23
24 INTERVAL_INLINE void snd_interval_any(snd_interval_t *i)
25 {
26         i->min = 0;
27         i->openmin = 0;
28         i->max = UINT_MAX;
29         i->openmax = 0;
30         i->integer = 0;
31         i->empty = 0;
32 }
33
34 INTERVAL_INLINE void snd_interval_none(snd_interval_t *i)
35 {
36         i->empty = 1;
37 }
38
39 INTERVAL_INLINE int snd_interval_checkempty(const snd_interval_t *i)
40 {
41         return (i->min > i->max ||
42                 (i->min == i->max && (i->openmin || i->openmax)));
43 }
44
45 INTERVAL_INLINE int snd_interval_empty(const snd_interval_t *i)
46 {
47         return i->empty;
48 }
49
50 INTERVAL_INLINE int snd_interval_single(const snd_interval_t *i)
51 {
52         assert(!snd_interval_empty(i));
53         return (i->min == i->max || 
54                 (i->min + 1 == i->max && i->openmax));
55 }
56
57 INTERVAL_INLINE int snd_interval_value(const snd_interval_t *i)
58 {
59         assert(snd_interval_single(i));
60         return i->min;
61 }
62
63 INTERVAL_INLINE void snd_interval_set_value(snd_interval_t *i, unsigned int val)
64 {
65         i->openmax = i->openmin = 0;
66         i->min = i->max = val;
67         i->integer = 0;
68         i->empty = 0;
69 }
70
71 INTERVAL_INLINE int snd_interval_min(const snd_interval_t *i)
72 {
73         assert(!snd_interval_empty(i));
74         return i->min;
75 }
76
77 INTERVAL_INLINE int snd_interval_max(const snd_interval_t *i)
78 {
79         assert(!snd_interval_empty(i));
80         return i->max;
81 }
82
83 INTERVAL_INLINE void snd_interval_set_minmax(snd_interval_t *i, unsigned int min, unsigned int max)
84 {
85         i->openmax = i->openmin = 0;
86         i->min = min;
87         i->max = max;
88         i->integer = 0;
89         i->empty = 0;
90 }
91
92 INTERVAL_INLINE int snd_interval_test(const snd_interval_t *i, unsigned int val)
93 {
94         return !((i->min > val || (i->min == val && i->openmin) ||
95                   i->max < val || (i->max == val && i->openmax)));
96 }
97
98 INTERVAL_INLINE void snd_interval_copy(snd_interval_t *d, const snd_interval_t *s)
99 {
100         *d = *s;
101 }
102
103 INTERVAL_INLINE int snd_interval_setinteger(snd_interval_t *i)
104 {
105         if (i->integer)
106                 return 0;
107         if (i->openmin && i->openmax && i->min == i->max)
108                 return -EINVAL;
109         i->integer = 1;
110         return 1;
111 }
112
113 INTERVAL_INLINE void snd_interval_floor(snd_interval_t *i)
114 {
115         if (i->integer || snd_interval_empty(i))
116                 return;
117         i->openmin = 0;
118         if (i->openmax) {
119                 i->max--;
120                 i->openmax = 0;
121         }
122         i->integer = 1;
123 }
124
125 INTERVAL_INLINE void snd_interval_unfloor(snd_interval_t *i)
126 {
127         if (snd_interval_empty(i))
128                 return;
129         if (i->max == UINT_MAX)
130                 return;
131         if (i->openmax)
132                 return;
133         i->max++;
134         i->openmax = 1;
135         i->integer = 0;
136 }
137
138
139 INTERVAL_INLINE int snd_interval_always_eq(const snd_interval_t *i1, const snd_interval_t *i2)
140 {
141         return snd_interval_single(i1) && snd_interval_single(i2) &&
142                 snd_interval_value(i1) == snd_interval_value(i2);
143 }
144
145 INTERVAL_INLINE int snd_interval_never_eq(const snd_interval_t *i1, const snd_interval_t *i2)
146 {
147         
148         return (i1->max < i2->min || 
149                 (i1->max == i2->min &&
150                  (i1->openmax || i1->openmin)) ||
151                 i1->min > i2->max ||
152                 (i1->min == i2->max &&
153                  (i1->openmin || i2->openmax)));
154 }
155
156
157