00001 /* 00002 * Copyright 2007 Martin von Gagern 00003 * 00004 * 00005 * This file is part of mqn2mps. 00006 * 00007 * mqn2mps is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * mqn2mps is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 00022 #include <string> 00023 #include <vector> 00024 #include <utility> 00025 00026 #include "rational.hh" 00027 #include "field.hh" 00028 00029 /** 00030 * @file 00031 * Implementation of class field. 00032 */ 00033 00034 /** 00035 * Default constructor. 00036 * Members will be initialized to their default values. 00037 */ 00038 field::field() : name(), values() { 00039 } 00040 00041 /** 00042 * Constructor for use by the parser. 00043 * As the parser represents most objects through pointers, this 00044 * version of the constructor accepts pointers, and takes care of 00045 * freeing the memory of the objects pointed to. 00046 * 00047 * @param n the name of the field. 00048 * @param v the sequence of matrix elements. 00049 */ 00050 field::field(std::string* n, std::vector<rational>* v) : name(*n), values() { 00051 values.swap(*v); 00052 delete n; 00053 delete v; 00054 } 00055 00056 /** 00057 * Swap two fields. 00058 * This method implements the optimized swapping operation, which is 00059 * used by the std::swap(field&, field&) function in generic code. 00060 * 00061 * @param other the other field objects with which this one should be 00062 * swapped. 00063 */ 00064 void field::swap(field& other) { 00065 std::swap(name, other.name); 00066 std::swap(values, other.values); 00067 }