00001 /* 00002 * $Id: ClearSilverNodeComparatorValue.cc,v 1.4 2006/03/29 05:35:58 brook Exp $ 00003 */ 00004 00005 /* 00006 * ClearSilver++ Software License. 00007 * 00008 * Copyright (c) 2005,2006 Brook Milligan <brook@nmsu.edu> 00009 * All rights reserved. 00010 * 00011 * Redistribution and use in source and binary forms, with or without 00012 * modification, are permitted provided that the following conditions 00013 * are met: 00014 * 00015 * 1. Redistributions of source code must retain the above copyright 00016 * notice, this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above 00018 * copyright notice, this list of conditions and the following 00019 * disclaimer in the documentation and/or other materials provided 00020 * with the distribution. 00021 * 3. The name of the author may not be used to endorse or promote 00022 * products derived from this software without specific prior 00023 * written permission. 00024 * 00025 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 00026 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00027 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00028 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 00029 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00030 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00031 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00032 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00033 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 */ 00037 00038 #include "ClearSilverNodeComparatorValue.h" 00039 #include "ConstHDF.h" 00040 00041 using namespace std; 00042 00043 namespace ClearSilver 00044 { 00045 // constructors 00046 ClearSilverNodeComparatorValue::ClearSilverNodeComparatorValue () 00047 : ClearSilverNodeComparator(), key_() {} 00048 00049 ClearSilverNodeComparatorValue::ClearSilverNodeComparatorValue 00050 (const char* key) 00051 : ClearSilverNodeComparator(), key_(key) {} 00052 00053 ClearSilverNodeComparatorValue::ClearSilverNodeComparatorValue 00054 (const string& key) 00055 : ClearSilverNodeComparator(), key_(key) {} 00056 00057 ClearSilverNodeComparatorValue::ClearSilverNodeComparatorValue 00058 (const ClearSilverNodeComparatorValue& c) 00059 : ClearSilverNodeComparator(c), key_(c.key_) {} 00060 00061 ClearSilverNodeComparatorValue::~ClearSilverNodeComparatorValue () throw() {} 00062 00063 // assignment 00064 ClearSilverNodeComparatorValue& 00065 ClearSilverNodeComparatorValue::operator = 00066 (const ClearSilverNodeComparatorValue& c) 00067 { 00068 ClearSilverNodeComparatorValue c_(c); 00069 swap(c_); 00070 return *this; 00071 } 00072 00073 void 00074 ClearSilverNodeComparatorValue::swap 00075 (ClearSilverNodeComparatorValue& c) throw() 00076 { 00077 ClearSilverNodeComparator::swap (c); 00078 key_.swap (c.key_); 00079 } 00080 00081 // compare two nodes 00082 int 00083 ClearSilverNodeComparatorValue::operator () (const ConstHDF& n1, 00084 const ConstHDF& n2) const 00085 { 00086 if (n1[key_].value() < n2[key_].value()) 00087 return -1; 00088 if (n1[key_].value() > n2[key_].value()) 00089 return +1; 00090 return 0; 00091 } 00092 00093 }; // namespace ClearSilver 00094
1.4.5