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 <utility> 00024 00025 #include "rational.hh" 00026 #include "constraint.hh" 00027 00028 /** 00029 * @file 00030 * Implementation of class constraint. 00031 */ 00032 00033 /** 00034 * Default constructor. 00035 * Uses default values for all members, like a goal of 0 and no modulo 00036 * arithmetic to be used. 00037 */ 00038 constraint::constraint() : name(), goal(0), mod(0) { 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 associated quantum number. 00048 * @param g the goal, i.e. the right hand side of the equation. 00049 * @param m the modulo divisor, or 0 for no modulo arithmetic. 00050 */ 00051 constraint::constraint(std::string* n, rational* g, int m = 0) 00052 : name(*n), goal(*g), mod(m) { 00053 delete n; 00054 delete g; 00055 } 00056 00057 /** 00058 * Full constructor. 00059 * This constructor takes its arguments by value. They map to the 00060 * members of the constraint object in an obvious way. 00061 * 00062 * @param n the name of the associated quantum number. 00063 * @param g the goal, i.e. the right hand side of the equation. 00064 * @param m the modulo divisor, or 0 for no modulo arithmetic. 00065 */ 00066 constraint::constraint(std::string n, rational g, int m = 0) 00067 : name(n), goal(g), mod(m) { 00068 } 00069 00070 /** 00071 * Swap two constraints. 00072 * This method implements the optimized swapping operation, which is 00073 * used by the std::swap(constraint&, constraint&) function in generic 00074 * code. 00075 * 00076 * @param other the other constraint objects with which this one 00077 * should be swapped. 00078 */ 00079 void constraint::swap(constraint& other) { 00080 std::swap(name, other.name); 00081 std::swap(goal, other.goal); 00082 std::swap(mod , other.mod ); 00083 }
1.6.0