Transferred copyright to the OpenFOAM Foundation
[OpenFOAM-2.0.x.git] / src / OpenFOAM / primitives / strings / lists / hashedWordList.C
blobde0e43052a0f778617c37e0b59d9cfeb5832596c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "hashedWordList.H"
28 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
30 void Foam::hashedWordList::rehash()
32     indices_.clear();
33     forAll(*this, i)
34     {
35         indices_.insert(List<word>::operator[](i), i);
36     }
40 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
42 Foam::hashedWordList::hashedWordList()
44     List<word>()
48 Foam::hashedWordList::hashedWordList(const UList<word>& names)
50     List<word>(names)
52     rehash();
56 Foam::hashedWordList::hashedWordList(const hashedWordList& names)
58     List<word>(static_cast<const UList<word>&>(names))
60     rehash();
64 Foam::hashedWordList::hashedWordList(const Xfer< List<word> >& names)
66     List<word>(names)
68     rehash();
72 Foam::hashedWordList::hashedWordList
74     const label nNames,
75     const char** names
78     List<word>(nNames)
80     forAll(*this, i)
81     {
82         List<word>::operator[](i) = names[i];
83     }
85     rehash();
89 Foam::hashedWordList::hashedWordList
91     const char** names
94     // count names
95     label nNames = 0;
96     for (unsigned i = 0; names[i] && *(names[i]); ++i)
97     {
98         ++nNames;
99     }
101     List<word>::setSize(nNames);
102     forAll(*this, i)
103     {
104         List<word>::operator[](i) = names[i];
105     }
107     rehash();
111 Foam::hashedWordList::hashedWordList(Istream& is)
113     is  >> *this;
117 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
119 void Foam::hashedWordList::clear()
121     List<word>::clear();
122     indices_.clear();
126 void Foam::hashedWordList::append(const word& name)
128     const label idx = size();
129     List<word>::append(name);
130     indices_.insert(name, idx);
134 void Foam::hashedWordList::transfer(List<word>& lst)
136     List<word>::transfer(lst);
137     rehash();
141 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
143 Foam::Istream& Foam::operator>>(Istream& is, hashedWordList& lst)
145     is  >> static_cast<List<word>&>(lst);
146     lst.rehash();
148     return is;
152 Foam::Ostream& Foam::operator<<(Ostream& os, const hashedWordList& lst)
154     os  << static_cast<const List<word>&>(lst);
155     return os;
159 // ************************************************************************* //