00001 /* Copyright (C) 2002-2008 Stefan Buehler <sbuehler@ltu.se> 00002 00003 This program is free software; you can redistribute it and/or modify it 00004 under the terms of the GNU General Public License as published by the 00005 Free Software Foundation; either version 2, or (at your option) any 00006 later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00016 USA. */ 00017 00029 #ifndef m_append_h 00030 #define m_append_h 00031 00032 #include "array.h" 00033 #include "exceptions.h" 00034 #include "matpackI.h" 00035 00036 00037 /* Implementations for supported types follow. */ 00038 00039 /* Implementation for array types */ 00040 template< class T > 00041 void Append(// WS Generic Output: 00042 Array<T>& out, 00043 // WS Generic Input: 00044 const Array<T>& in) 00045 { 00046 // Reserve memory in advance to avoid reallocations: 00047 out.reserve(out.nelem()+in.nelem()); 00048 // Append in to end of out: 00049 for (Index i=0; i<in.nelem(); ++i) 00050 out.push_back(in[i]); 00051 } 00052 00053 /* Implementation for Vector */ 00054 void Append(// WS Generic Output: 00055 Vector& out, 00056 // WS Generic Input: 00057 const Vector& in) 00058 { 00059 // Get backup of out: 00060 Vector dummy = out; 00061 00062 // Make out the right size: 00063 out.resize(dummy.nelem()+in.nelem()); 00064 00065 // Copy dummy to first part of out: 00066 out[Range(0,dummy.nelem())] = dummy; 00067 00068 // Copy in to last part of out: 00069 out[Range(dummy.nelem(),in.nelem())] = in; 00070 } 00071 00072 /* Implementation for String */ 00073 void Append(// WS Generic Output: 00074 String& out, 00075 // WS Generic Input: 00076 const String& in) 00077 { 00078 // String stream for easy string operations: 00079 ostringstream os; 00080 00081 os << out << in; 00082 00083 out = os.str(); 00084 } 00085 00086 #endif // m_append_h