ARTS  2.0.49
m_append.h
Go to the documentation of this file.
1 /* Copyright (C) 2002-2008 Stefan Buehler <sbuehler@ltu.se>
2 
3  This program is free software; you can redistribute it and/or modify it
4  under the terms of the GNU General Public License as published by the
5  Free Software Foundation; either version 2, or (at your option) any
6  later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16  USA. */
17 
29 #ifndef m_append_h
30 #define m_append_h
31 
32 #include "array.h"
33 #include "exceptions.h"
34 #include "matpackI.h"
35 
36 
37 /* Implementations for supported types follow. */
38 
39 /* Implementation for array types */
40 template< class T >
41 void Append(// WS Generic Output:
42  Array<T>& out,
43  // WS Generic Input:
44  const Array<T>& in,
45  const Verbosity&)
46 {
47  // Reserve memory in advance to avoid reallocations:
48  out.reserve(out.nelem()+in.nelem());
49  // Append in to end of out:
50  for (Index i=0; i<in.nelem(); ++i)
51  out.push_back(in[i]);
52 }
53 
54 /* Implementation for array types to append single element */
55 template< class T >
56 void Append(// WS Generic Output:
57  Array<T>& out,
58  // WS Generic Input:
59  const T& in,
60  const Verbosity&)
61 {
62  // Append in to end of out:
63  out.push_back(in);
64 }
65 
66 /* Implementation for Vector */
67 void Append(// WS Generic Output:
68  Vector& out,
69  // WS Generic Input:
70  const Vector& in,
71  const Verbosity&)
72 {
73  // Get backup of out:
74  Vector dummy = out;
75 
76  // Make out the right size:
77  out.resize(dummy.nelem()+in.nelem());
78 
79  // Copy dummy to first part of out:
80  out[Range(0,dummy.nelem())] = dummy;
81 
82  // Copy in to last part of out:
83  out[Range(dummy.nelem(),in.nelem())] = in;
84 }
85 
86 /* Implementation for String */
87 void Append(// WS Generic Output:
88  String& out,
89  // WS Generic Input:
90  const String& in,
91  const Verbosity&)
92 {
93  // String stream for easy string operations:
94  ostringstream os;
95 
96  os << out << in;
97 
98  out = os.str();
99 }
100 
101 #endif // m_append_h
exceptions.h
The declarations of all the exception classes.
Append
void Append(Array< T > &out, const Array< T > &in, const Verbosity &)
Definition: m_append.h:41
Vector::resize
void resize(Index n)
Resize function.
Definition: matpackI.cc:771
array.h
This file contains the definition of Array.
matpackI.h
Array
This can be used to make arrays out of anything.
Definition: array.h:103
my_basic_string
The implementation for String, the ARTS string class.
Definition: mystring.h:62
ConstVectorView::nelem
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:175
Verbosity
Definition: messages.h:50
Range
The range class.
Definition: matpackI.h:148
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Vector
The Vector class.
Definition: matpackI.h:555
Array::nelem
Index nelem() const
Number of elements.
Definition: array.h:172