aboutsummaryrefslogtreecommitdiff
path: root/paludis/util/visitor-impl.hh
blob: cb2c73d59e4330ae602daa40a18e3fb83230f667 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2006, 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
 *
 * This file is part of the Paludis package manager. Paludis is free software;
 * you can redistribute it and/or modify it under the terms of the GNU General
 * Public License version 2, as published by the Free Software Foundation.
 *
 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef PALUDIS_GUARD_PALUDIS_UTIL_VISITOR_IMPL_HH
#define PALUDIS_GUARD_PALUDIS_UTIL_VISITOR_IMPL_HH 1

#include <paludis/util/visitor.hh>
#include <paludis/util/sequence.hh>
#include <paludis/util/sequence-impl.hh>
#include <paludis/util/iterator.hh>

/** \file
 * Implementation for paludis/util/visitor.hh .
 *
 * \ingroup g_visitors
 */

namespace paludis
{
    namespace visitor_internals
    {
        template <typename H_>
        template <bool b_, typename T_>
        void
        ConstAcceptInterface<H_>::ConstAccept<b_, T_>::forward(const ConstAcceptInterface * const h, T_ & t)
        {
            h->real_const_accept(t);
        }

        template <typename H_>
        template <typename T_>
        void
        ConstAcceptInterface<H_>::ConstAccept<false, T_>::forward(const ConstAcceptInterface * const h, T_ & t)
        {
            ConstProxyVisitor<typename H_::Heirarchy, typename T_::Heirarchy> p(&t);
            h->accept(p);
        }

        template <typename H_>
        ConstAcceptInterface<H_>::~ConstAcceptInterface()
        {
        }

        template <typename H_, typename T_>
        void
        ConstAcceptInterfaceVisitsThis<H_, T_>::real_const_accept(ConstVisitor<H_> & v) const
        {
            static_cast<Visits<const T_> *>(&v)->visit(*static_cast<const T_ *>(this));
        }

        template <typename H_>
        template <bool b_, typename T_>
        void
        AcceptInterface<H_>::ConstAccept<b_, T_>::forward(AcceptInterface * const h, T_ & t)
        {
            h->mutable_accept(t);
        }

        template <typename H_>
        template <typename T_>
        void
        AcceptInterface<H_>::ConstAccept<true, T_>::forward(AcceptInterface * const h, T_ & t)
        {
            h->const_accept(t);
        }

        template <typename H_>
        template <bool b_, typename T_>
        void
        AcceptInterface<H_>::Accept<b_, T_>::forward(AcceptInterface * const h, T_ & t)
        {
            h->real_mutable_accept(t);
        }

        template <typename H_>
        template <typename T_>
        void
        AcceptInterface<H_>::Accept<false, T_>::forward(AcceptInterface * const h, T_ & t)
        {
            ProxyVisitor<typename H_::Heirarchy, typename T_::Heirarchy> p(&t);
            h->accept(p);
        }

        template <typename H_>
        AcceptInterface<H_>::~AcceptInterface()
        {
        }

        template <typename H_, typename T_>
        void
        AcceptInterfaceVisitsThis<H_, T_>::real_const_accept(ConstVisitor<H_> & v) const
        {
            static_cast<Visits<const T_> *>(&v)->visit(*static_cast<const T_ *>(this));
        }

        template <typename H_, typename T_>
        void
        AcceptInterfaceVisitsThis<H_, T_>::real_mutable_accept(Visitor<H_> & v)
        {
            static_cast<Visits<T_> *>(&v)->visit(*static_cast<T_ *>(this));
        }

        template <typename H_, typename T_>
        void
        TreeLeaf<H_, T_>::real_mutable_accept(Visitor<H_> & v)
        {
            static_cast<Visits<TreeLeaf<H_, T_> > *>(&v)->visit(*this);
        }

        template <typename H_, typename T_>
        void
        TreeLeaf<H_, T_>::real_const_accept(ConstVisitor<H_> & v) const
        {
            static_cast<Visits<const TreeLeaf<H_, T_> > *>(&v)->visit(*this);
        }

        template <typename H_, typename T_>
        TreeLeaf<H_, T_>::~TreeLeaf()
        {
        }

        template <typename H_, typename T_>
        TreeLeaf<H_, T_>::TreeLeaf(const tr1::shared_ptr<T_> & i) :
            _item(i)
        {
        }

        template <typename H_, typename T_>
        tr1::shared_ptr<T_>
        TreeLeaf<H_, T_>::item()
        {
            return _item;
        }

        template <typename H_, typename T_>
        tr1::shared_ptr<const T_>
        TreeLeaf<H_, T_>::item() const
        {
            return _item;
        }

        template <typename H_, typename T_>
        void
        TreeSequence<H_, T_>::real_mutable_accept(Visitor<H_> & v)
        {
            static_cast<Visits<TreeSequence<H_, T_> > *>(&v)->visit(*this);
        }

        template <typename H_, typename T_>
        void
        TreeSequence<H_, T_>::real_const_accept(ConstVisitor<H_> & v) const
        {
            static_cast<Visits<const TreeSequence<H_, T_> > *>(&v)->visit(*this);
        }

        template <typename H_, typename T_>
        TreeSequence<H_, T_>::~TreeSequence()
        {
        }

        template <typename H_, typename T_>
        TreeSequence<H_, T_>::TreeSequence(tr1::shared_ptr<T_> i) :
            _item(i),
            _items(new Sequence<tr1::shared_ptr<AcceptInterface<H_> > >)
        {
        }

        template <typename H_, typename T_>
        tr1::shared_ptr<const T_>
        TreeSequence<H_, T_>::item() const
        {
            return _item;
        }

        template <typename H_, typename T_>
        tr1::shared_ptr<T_>
        TreeSequence<H_, T_>::item()
        {
            return _item;
        }

        template <typename H_, typename T_>
        void
        TreeSequence<H_, T_>::add(tr1::shared_ptr<AcceptInterface<H_> > i)
        {
            _items->push_back(i);
        }

        template <typename H_, typename T_>
        typename H_::ConstSequenceIterator
        TreeSequence<H_, T_>::const_begin() const
        {
            return typename H_::ConstSequenceIterator(
                    paludis::indirect_iterator(_items->begin()));
        }

        template <typename H_, typename T_>
        typename H_::ConstSequenceIterator
        TreeSequence<H_, T_>::const_end() const
        {
            return typename H_::ConstSequenceIterator(
                    paludis::indirect_iterator(_items->end()));
        }

        template <typename H_, typename T_>
        typename H_::SequenceIterator
        TreeSequence<H_, T_>::mutable_begin()
        {
            return typename H_::SequenceIterator(
                    paludis::indirect_iterator(_items->begin()));
        }

        template <typename H_, typename T_>
        typename H_::SequenceIterator
        TreeSequence<H_, T_>::mutable_end()
        {
            return typename H_::SequenceIterator(
                    paludis::indirect_iterator(_items->end()));
        }

        template <typename H_, typename T_>
        void
        ConstTreeSequence<H_, T_>::real_const_accept(ConstVisitor<H_> & v) const
        {
            static_cast<Visits<const ConstTreeSequence<H_, T_> > *>(&v)->visit(*this);
        }

        template <typename H_, typename T_>
        ConstTreeSequence<H_, T_>::~ConstTreeSequence()
        {
        }

        template <typename H_, typename T_>
        ConstTreeSequence<H_, T_>::ConstTreeSequence(tr1::shared_ptr<T_> i) :
            _item(i),
            _items(new Sequence<tr1::shared_ptr<const ConstAcceptInterface<H_> > >)
        {
        }

        template <typename H_, typename T_>
        tr1::shared_ptr<T_>
        ConstTreeSequence<H_, T_>::item()
        {
            return _item;
        }

        template <typename H_, typename T_>
        tr1::shared_ptr<const T_>
        ConstTreeSequence<H_, T_>::item() const
        {
            return _item;
        }

        template <typename H_, typename T_>
        void
        ConstTreeSequence<H_, T_>::add(tr1::shared_ptr<const ConstAcceptInterface<H_> > i)
        {
            _items->push_back(i);
        }

        template <typename H_, typename T_>
        typename H_::ConstSequenceIterator
        ConstTreeSequence<H_, T_>::const_begin() const
        {
            return typename H_::ConstSequenceIterator(
                    paludis::indirect_iterator(_items->begin()));
        }

        template <typename H_, typename T_>
        typename H_::ConstSequenceIterator
        ConstTreeSequence<H_, T_>::const_end() const
        {
            return typename H_::ConstSequenceIterator(
                    paludis::indirect_iterator(_items->end()));
        }

        template <typename T_>
        Visits<T_>::~Visits()
        {
        }

        template <typename H_, typename T_>
        Visits<TreeLeaf<H_, T_> >::~Visits()
        {
        }

        template <typename H_, typename T_>
        void
        Visits<TreeLeaf<H_, T_> >::visit(TreeLeaf<H_, T_> & l)
        {
            visit_leaf(*l.item());
        }

        template <typename H_, typename T_>
        Visits<const TreeLeaf<H_, T_> >::~Visits()
        {
        }

        template <typename H_, typename T_>
        void
        Visits<const TreeLeaf<H_, T_> >::visit(const TreeLeaf<H_, T_> & l)
        {
            visit_leaf(*l.item());
        }

        template <typename H_, typename T_>
        Visits<TreeSequence<H_, T_> >::~Visits()
        {
        }

        template <typename H_, typename T_>
        void
        Visits<TreeSequence<H_, T_> >::visit(TreeSequence<H_, T_> & s)
        {
            visit_sequence(*s.item(), s.mutable_begin(), s.mutable_end());
        }

        template <typename H_, typename T_>
        Visits<const TreeSequence<H_, T_> >::~Visits()
        {
        }

        template <typename H_, typename T_>
        void
        Visits<const TreeSequence<H_, T_> >::visit(const TreeSequence<H_, T_> & s)
        {
            visit_sequence(*s.item(), s.const_begin(), s.const_end());
        }

        template <typename H_, typename T_>
        Visits<ConstTreeSequence<H_, T_> >::~Visits()
        {
        }

        template <typename H_, typename T_>
        void
        Visits<ConstTreeSequence<H_, T_> >::visit(ConstTreeSequence<H_, T_> & s)
        {
            visit_sequence(*s.item(), s.const_begin(), s.const_end());
        }

        template <typename H_, typename T_>
        Visits<const ConstTreeSequence<H_, T_> >::~Visits()
        {
        }

        template <typename H_, typename T_>
        void
        Visits<const ConstTreeSequence<H_, T_> >::visit(const ConstTreeSequence<H_, T_> & s)
        {
            visit_sequence(*s.item(), s.const_begin(), s.const_end());
        }

        template <typename H_, typename LargerH_, typename T_>
        ProxyVisits<H_, LargerH_, const TreeLeaf<H_, T_> >::~ProxyVisits()
        {
        }

        template <typename H_, typename LargerH_, typename T_>
        void
        ProxyVisits<H_, LargerH_, const TreeLeaf<H_, T_> >::visit_leaf(const T_ & v)
        {
            static_cast<Visits<const TreeLeaf<LargerH_, T_> > *>(
                    static_cast<ConstProxyVisitor<H_, LargerH_> *>(this)->larger_visitor())->visit_leaf(v);
        }

        template <typename H_, typename LargerH_, typename T_>
        ProxyVisits<H_, LargerH_, TreeLeaf<H_, T_> >::~ProxyVisits()
        {
        }

        template <typename H_, typename LargerH_, typename T_>
        void
        ProxyVisits<H_, LargerH_, TreeLeaf<H_, T_> >::visit_leaf(T_ & v)
        {
            static_cast<Visits<TreeLeaf<LargerH_, T_> > *>(
                    static_cast<ProxyVisitor<H_, LargerH_> *>(this)->larger_visitor())->visit_leaf(v);
        }

        template <typename H_, typename LargerH_, typename T_>
        ProxyVisits<H_, LargerH_, const ConstTreeSequence<H_, T_> >::~ProxyVisits()
        {
        }

        template <typename H_, typename LargerH_, typename T_>
        void
        ProxyVisits<H_, LargerH_, const ConstTreeSequence<H_, T_> >::visit_sequence(const T_ & t,
                typename TreeSequenceIteratorTypes<H_>::ConstIterator c,
                typename TreeSequenceIteratorTypes<H_>::ConstIterator e)
        {
            static_cast<Visits<const ConstTreeSequence<LargerH_, T_> > *>(
                    static_cast<ConstProxyVisitor<H_, LargerH_> *>(this)->larger_visitor())->visit_sequence(t,
                    typename TreeSequenceIteratorTypes<LargerH_>::ConstIterator(ConstProxyIterator<H_, LargerH_>(c)),
                    typename TreeSequenceIteratorTypes<LargerH_>::ConstIterator(ConstProxyIterator<H_, LargerH_>(e)));
        }

        template <typename H_, typename LargerH_, typename T_>
        ProxyVisits<H_, LargerH_, const TreeSequence<H_, T_> >::~ProxyVisits()
        {
        }

        template <typename H_, typename LargerH_, typename T_>
        void
        ProxyVisits<H_, LargerH_, const TreeSequence<H_, T_> >::visit_sequence(const T_ & t,
                typename TreeSequenceIteratorTypes<H_>::ConstIterator c,
                typename TreeSequenceIteratorTypes<H_>::ConstIterator e)
        {
            static_cast<Visits<const TreeSequence<LargerH_, T_> > *>(
                    static_cast<ConstProxyVisitor<H_, LargerH_> *>(this)->larger_visitor())->visit_sequence(t,
                    typename TreeSequenceIteratorTypes<LargerH_>::ConstIterator(ConstProxyIterator<H_, LargerH_>(c)),
                    typename TreeSequenceIteratorTypes<LargerH_>::ConstIterator(ConstProxyIterator<H_, LargerH_>(e)));
        }

        template <typename H_, typename LargerH_, typename T_>
        ProxyVisits<H_, LargerH_, TreeSequence<H_, T_> >::~ProxyVisits()
        {
        }

        template <typename H_, typename LargerH_, typename T_>
        void
        ProxyVisits<H_, LargerH_, TreeSequence<H_, T_> >::visit_sequence(T_ & t,
                typename TreeSequenceIteratorTypes<H_>::Iterator c,
                typename TreeSequenceIteratorTypes<H_>::Iterator e)
        {
            static_cast<Visits<TreeSequence<LargerH_, T_> > *>(
                    static_cast<ProxyVisitor<H_, LargerH_> *>(this)->larger_visitor())->visit_sequence(t,
                    typename TreeSequenceIteratorTypes<LargerH_>::Iterator(ProxyIterator<H_, LargerH_>(c)),
                    typename TreeSequenceIteratorTypes<LargerH_>::Iterator(ProxyIterator<H_, LargerH_>(e)));
        }

        template <typename H_, typename LargerH_>
        ConstProxyVisitor<H_, LargerH_>::ConstProxyVisitor(ConstVisitor<LargerH_> * const l) :
            _larger_h(l)
        {
        }

        template <typename H_, typename LargerH_>
        ConstVisitor<LargerH_> *
        ConstProxyVisitor<H_, LargerH_>::larger_visitor() const
        {
            return _larger_h;
        }

        template <typename H_, typename LargerH_>
        ProxyVisitor<H_, LargerH_>::ProxyVisitor(Visitor<LargerH_> * const l) :
            _larger_h(l)
        {
        }

        template <typename H_, typename LargerH_>
        Visitor<LargerH_> *
        ProxyVisitor<H_, LargerH_>::larger_visitor() const
        {
            return _larger_h;
        }

        template <typename H_, typename LargerH_>
        ConstProxyIterator<H_, LargerH_>::Adapter::Adapter(const ConstAcceptInterface<H_> & i) :
            _i(i)
        {
        }

        template <typename H_, typename LargerH_>
        void
        ConstProxyIterator<H_, LargerH_>::Adapter::real_const_accept(ConstVisitor<LargerH_> & v) const
        {
            _i.accept(v);
        }

        template <typename H_, typename LargerH_>
        ConstProxyIterator<H_, LargerH_>::ConstProxyIterator(typename TreeSequenceIteratorTypes<H_>::ConstIterator i) :
            _i(i)
        {
        }

        template <typename H_, typename LargerH_>
        bool
        ConstProxyIterator<H_, LargerH_>::operator== (const ConstProxyIterator & other) const
        {
            return _i == other._i;
        }

        template <typename H_, typename LargerH_>
        const ConstAcceptInterface<LargerH_> *
        ConstProxyIterator<H_, LargerH_>::operator-> () const
        {
            if (! _c)
                _c.reset(new Adapter(*_i));
            return _c.get();
        }

        template <typename H_, typename LargerH_>
        const ConstAcceptInterface<LargerH_> &
        ConstProxyIterator<H_, LargerH_>::operator* () const
        {
            return *operator-> ();
        }

        template <typename H_, typename LargerH_>
        ConstProxyIterator<H_, LargerH_> &
        ConstProxyIterator<H_, LargerH_>::operator++ ()
        {
            _c.reset();
            _i++;
            return *this;
        }

        template <typename H_, typename LargerH_>
        ProxyIterator<H_, LargerH_>::Adapter::Adapter(AcceptInterface<H_> & i) :
            _i(i)
        {
        }

        template <typename H_, typename LargerH_>
        void
        ProxyIterator<H_, LargerH_>::Adapter::real_const_accept(ConstVisitor<LargerH_> & v) const
        {
            _i.accept(v);
        }

        template <typename H_, typename LargerH_>
        void
        ProxyIterator<H_, LargerH_>::Adapter::real_mutable_accept(Visitor<LargerH_> & v)
        {
            _i.accept(v);
        }

        template <typename H_, typename LargerH_>
        ProxyIterator<H_, LargerH_>::ProxyIterator(typename TreeSequenceIteratorTypes<H_>::Iterator i) :
            _i(i)
        {
        }

        template <typename H_, typename LargerH_>
        bool
        ProxyIterator<H_, LargerH_>::operator== (const ProxyIterator & other) const
        {
            return _i == other._i;
        }

        template <typename H_, typename LargerH_>
        AcceptInterface<LargerH_> *
        ProxyIterator<H_, LargerH_>::operator-> () const
        {
            if (! _c)
                _c.reset(new Adapter(*_i));
            return _c.get();
        }

        template <typename H_, typename LargerH_>
        AcceptInterface<LargerH_> &
        ProxyIterator<H_, LargerH_>::operator* () const
        {
            return *operator-> ();
        }

        template <typename H_, typename LargerH_>
        ProxyIterator<H_, LargerH_> &
        ProxyIterator<H_, LargerH_>::operator++ ()
        {
            _c.reset();
            _i++;
            return *this;
        }

        template <typename H_>
        template <typename A_, typename B_>
        void
        ConstVisitor<H_>::VisitConstSequence<A_, B_>::visit_sequence(const B_ &,
                typename TreeSequenceIteratorTypes<Heirarchy>::ConstIterator c,
                typename TreeSequenceIteratorTypes<Heirarchy>::ConstIterator e)
        {
            std::for_each(c, e, accept_visitor(*static_cast<A_ *>(this)));
        }

        template <typename H_>
        template <typename A_, typename B_>
        void
        ConstVisitor<H_>::VisitSequence<A_, B_>::visit_sequence(const B_ &,
                typename TreeSequenceIteratorTypes<Heirarchy>::ConstIterator c,
                typename TreeSequenceIteratorTypes<Heirarchy>::ConstIterator e)
        {
            std::for_each(c, e, accept_visitor(*static_cast<A_ *>(this)));
        }

        template <typename H_>
        template <typename A_, typename B_>
        void
        Visitor<H_>::VisitSequence<A_, B_>::visit_sequence(B_ &,
                typename TreeSequenceIteratorTypes<Heirarchy>::Iterator c,
                typename TreeSequenceIteratorTypes<Heirarchy>::Iterator e)
        {
            std::for_each(c, e, accept_visitor(*static_cast<A_ *>(this)));
        }

        template <typename I_, typename T_, typename H_>
        void
        GetConstItemVisits<I_, H_, const TreeLeaf<H_, T_> >::visit_leaf(const T_ & t)
        {
            static_cast<I_ *>(this)->item = &t;
        }

        template <typename I_, typename H_, typename T_>
        void
        GetConstItemVisits<I_, H_, const ConstTreeSequence<H_, T_> >::visit_sequence(const T_ & t,
                typename H_::ConstSequenceIterator,
                typename H_::ConstSequenceIterator)
        {
                static_cast<I_ *>(this)->item = &t;
        }

        template <typename I_, typename H_, typename T_>
        void
        GetConstItemVisits<I_, H_, const TreeSequence<H_, T_> >::visit_sequence(const T_ & t,
                typename H_::ConstSequenceIterator,
                typename H_::ConstSequenceIterator)
        {
            static_cast<I_ *>(this)->item = &t;
        }

        template <typename I_>
        GetConstItemVisitor<I_>::GetConstItemVisitor() :
            item(0)
        {
        }

        template <typename I_>
        const typename I_::Heirarchy::BasicNode *
        get_const_item(const I_ & i)
        {
            GetConstItemVisitor<I_> v;
            i.accept(v);
            return v.item;
        }
    }
}

#endif