Socket/Protocols/INet: Add 'host' and 'subnet' methods to INet4Network
[senf.git] / Socket / Protocols / INet / INet6Address.ct
1 // $Id$
2 //
3 // Copyright (C) 2007 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief INet6Address non-inline template implementation  */
25
26 #include "INet6Address.ih"
27
28 // Custom includes
29
30 #define prefix_
31 ///////////////////////////////ct.p////////////////////////////////////////
32
33 ///////////////////////////////////////////////////////////////////////////
34 // senf::INet6Address
35
36 template <class InputIterator>
37 prefix_ senf::INet6Address senf::INet6Address::from_data(InputIterator i)
38 {
39     INet6Address addr (INet6Address::noinit);
40     iterator j (addr.begin());
41     iterator const j_end (addr.end());
42     for (;j!=j_end;++j,++i)
43         *j = *i;
44     return addr;
45 }
46
47 ///////////////////////////////////////////////////////////////////////////
48 // namespace senf::detail members
49
50 template <class ForwardIterator, class Function>
51 prefix_ void senf::detail::apply_mask(unsigned bits, ForwardIterator b, ForwardIterator e,
52                                       Function fn)
53 {
54     for(; b != e; ++b) {
55         boost::uint8_t mask (0);
56         if (bits > 8) {
57             mask = 0xFFu;
58             bits -= 8;
59         } else if (bits > 0) {
60             mask = ~ low_bits_mask(8-bits);
61             bits = 0;
62         }
63         fn(*b,mask);
64     }
65 }
66
67 template <class ForwardIterator1, class ForwardIterator2, class Function>
68 prefix_ ForwardIterator1 senf::detail::find_if_mask(unsigned bits, ForwardIterator1 b1,
69                                                     ForwardIterator1 e1, ForwardIterator2 b2, 
70                                                     Function fn)
71 {
72     for(; b1 != e1; ++b1, ++b2) {
73         boost::uint8_t mask (0);
74         if (bits > 8) {
75             mask = 0xFFu;
76             bits -= 8;
77         } else if (bits > 0) {
78             mask = ~ low_bits_mask(8-bits);
79             bits = 0;
80         }
81         if (fn(*b1,*b2,mask))
82             return b1;
83     }
84     return e1;
85 }
86
87 ///////////////////////////////ct.e////////////////////////////////////////
88 #undef prefix_
89
90 \f
91 // Local Variables:
92 // mode: c++
93 // fill-column: 100
94 // comment-column: 40
95 // c-file-style: "senf"
96 // indent-tabs-mode: nil
97 // ispell-local-dictionary: "american"
98 // compile-command: "scons -u test"
99 // End: