source: XIOS/dev/dev_olga/src/extern/blitz/include/blitz/tinyvec2io.cc @ 1022

Last change on this file since 1022 was 1022, checked in by mhnguyen, 7 years ago
File size: 2.8 KB
Line 
1/***************************************************************************
2 * blitz/tinyvecio.cc      TinyVector I/O methods
3 *
4 * $Id$
5 *
6 * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
7 *
8 * This file is a part of Blitz.
9 *
10 * Blitz is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation, either version 3
13 * of the License, or (at your option) any later version.
14 *
15 * Blitz is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with Blitz.  If not, see <http://www.gnu.org/licenses/>.
22 *
23 * Suggestions:          blitz-devel@lists.sourceforge.net
24 * Bugs:                 blitz-support@lists.sourceforge.net   
25 *
26 * For more information, please see the Blitz++ Home Page:
27 *    https://sourceforge.net/projects/blitz/
28 *
29 ***************************************************************************/
30#ifndef BZ_TINYVEC2IO_CC
31#define BZ_TINYVEC2IO_CC
32
33#include <blitz/tinyvec2.h>
34
35BZ_NAMESPACE(blitz)
36
37// NEEDS_WORK???
38// This version of operator<< is updated on August 2005
39// by Sergei Mingaleev <mingaleev@gmail.com>. The output
40// format for 2D TinyVector is the same as for complex
41// numbers - so that one can read Array of complex numbers
42// into Array of TinyVectors for speed-up of calculations.
43// Also, the corresponding operator>> is updated.
44
45template<typename P_numtype, int N_length>
46ostream& operator<<(ostream& os, const TinyVector<P_numtype, N_length>& x)
47{
48    os << "(" << x[0];
49    for (int i=1; i < N_length; ++i)
50    {
51        os << "," << x[i];
52    }
53    os << ")";
54    return os;
55}
56
57// Input of tinyvec contribute by Adam Levar <adaml@mcneilhouse.com>
58// and updated by Sergei Mingaleev <mingaleev@gmail.com>
59template <typename T_numtype, int N_length>
60istream& operator>>(istream& is, TinyVector<T_numtype, N_length>& x)
61{
62    char sep;
63             
64    is >> sep;
65    BZPRECHECK(sep == '(', "Format error while scanning input TinyVector"
66        << endl << " (expected '(' opening TinyVector)");
67
68    is >> x(0);
69    for (int i = 1; i < N_length; ++i)
70    {
71        is >> sep;
72        BZPRECHECK(sep == ',', "Format error while scanning input TinyVector"
73             << endl << " (expected ',' between TinyVector components)");
74        BZPRECHECK(!is.bad(), "Premature end of input while scanning TinyVector");
75        is >> x(i);
76    }
77    is >> sep;
78    BZPRECHECK(sep == ')', "Format error while scanning input TinyVector"
79       << endl << " (expected ')' closing TinyVector)");
80   
81    return is;
82}
83
84BZ_NAMESPACE_END
85
86#endif // BZ_TINYVECIO_CC
Note: See TracBrowser for help on using the repository browser.