nux-1.16.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #include "Nux.h" 00024 #include "HexRegExpValidator.h" 00025 00026 namespace nux 00027 { 00028 00029 HexRegExpValidator::HexRegExpValidator (int Minimum, int Maximum) 00030 : m_Minimum (Minimum) 00031 , m_Maximum (Maximum) 00032 { 00033 _regexp_str = "^(0[xX])*[0-9a-fA-F]+$"; 00034 00035 InitRegExp (); 00036 00037 if (m_Minimum > m_Maximum) 00038 { 00039 int temp = m_Minimum; 00040 m_Minimum = m_Maximum; 00041 m_Maximum = temp; 00042 } 00043 } 00044 00045 HexRegExpValidator::HexRegExpValidator (const HexRegExpValidator ©) 00046 { 00047 m_Minimum = copy.m_Minimum; 00048 m_Minimum = copy.m_Maximum; 00049 _regexp_str = copy._regexp_str; 00050 InitRegExp (); 00051 } 00052 00053 HexRegExpValidator &HexRegExpValidator::operator= (const HexRegExpValidator &rhs) 00054 { 00055 if (&rhs != this) 00056 { 00057 m_Minimum = rhs.m_Minimum; 00058 m_Minimum = rhs.m_Maximum; 00059 _regexp_str = rhs._regexp_str; 00060 InitRegExp (); 00061 } 00062 00063 return *this; 00064 } 00065 00066 HexRegExpValidator::~HexRegExpValidator() 00067 { 00068 } 00069 00070 Validator *HexRegExpValidator::Clone() const 00071 { 00072 return new HexRegExpValidator (*this); 00073 } 00074 00075 void HexRegExpValidator::SetMinimum (int value) 00076 { 00077 m_Minimum = value; 00078 00079 if (m_Minimum > m_Maximum) 00080 { 00081 int temp = m_Minimum; 00082 m_Minimum = m_Maximum; 00083 m_Maximum = temp; 00084 } 00085 } 00086 00087 int HexRegExpValidator::GetMinimum() const 00088 { 00089 return m_Minimum; 00090 } 00091 00092 void HexRegExpValidator::SetMaximum (int value) 00093 { 00094 m_Maximum = value; 00095 00096 if (m_Minimum > m_Maximum) 00097 { 00098 int temp = m_Minimum; 00099 m_Minimum = m_Maximum; 00100 m_Maximum = temp; 00101 } 00102 } 00103 00104 int HexRegExpValidator::GetMaximum() const 00105 { 00106 return m_Maximum; 00107 } 00108 00109 int HexRegExpValidator::GetClampedValue (int i) const 00110 { 00111 if (i < m_Minimum) 00112 return m_Minimum; 00113 00114 if (i > m_Maximum) 00115 return m_Maximum; 00116 00117 return i; 00118 } 00119 00120 void HexRegExpValidator::Alternative (const TCHAR *str) 00121 { 00122 str = TEXT ("0x0"); 00123 } 00124 00125 NString HexRegExpValidator::ToString (int i) 00126 { 00127 NString Prec (TEXT ("%d")); 00128 return NString::Printf (Prec.GetTCharPtr (), i); 00129 } 00130 00131 int HexRegExpValidator::ToInteger (const TCHAR *str) 00132 { 00133 if (Validate (str) == Acceptable) 00134 return HexCharToInteger (str); 00135 else 00136 return 0; 00137 } 00138 00139 }