Now you can download a copy of these docs so you can use them offline! Download now
IntCameraParameter.cpp
00001 /*----------------------------------------------------------------------------*/ 00002 /* Copyright (c) FIRST 2008. All Rights Reserved. */ 00003 /* Open Source Software - may be modified and shared by FRC teams. The code */ 00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ 00005 /*----------------------------------------------------------------------------*/ 00006 00007 #include "IntCameraParameter.h" 00008 #include "pcre.h" 00009 #include <stdio.h> 00010 #include <string.h> 00011 00017 IntCameraParameter::IntCameraParameter(const char *setString, const char *getString, bool requiresRestart) 00018 { 00019 m_changed = false; 00020 m_value = 0; 00021 m_setString = setString; 00022 m_getString = getString; 00023 m_requiresRestart = requiresRestart; 00024 } 00025 00030 int IntCameraParameter::GetValue() 00031 { 00032 return m_value; 00033 } 00034 00040 void IntCameraParameter::SetValue(int value) 00041 { 00042 m_value = value; 00043 m_changed = true; 00044 } 00045 00052 bool IntCameraParameter::CheckChanged(bool &changed, char *param) 00053 { 00054 changed = m_changed; 00055 if (m_changed) 00056 { 00057 sprintf(param, m_setString, m_value); 00058 m_changed = false; 00059 return m_requiresRestart; 00060 } 00061 return false; 00062 } 00063 00070 void IntCameraParameter::GetParamFromString(const char *string, int stringLength) 00071 { 00072 char resultString[150]; 00073 if (SearchForParam(m_getString, string, stringLength, resultString) >= 0) 00074 { 00075 if (!m_changed) m_value = atoi(resultString); 00076 } 00077 } 00078 00085 int IntCameraParameter::SearchForParam(const char *pattern, const char *searchString, int searchStringLen, char *result) 00086 { 00087 int vectorLen = 10; 00088 int resultVector[vectorLen]; 00089 const char *error; 00090 int erroffset; 00091 pcre *compiledPattern = pcre_compile( 00092 pattern, //"root.Image.I0.Appearance.Resolution=(.*)", 00093 PCRE_CASELESS, 00094 &error, // for error message 00095 &erroffset, // for error offset 00096 NULL); // use default character tables 00097 int rc; 00098 rc = pcre_exec(compiledPattern, 00099 NULL, 00100 searchString, 00101 searchStringLen, 00102 0, 00103 0, 00104 resultVector, //locations of submatches 00105 vectorLen); //size of ovector 00106 int length = resultVector[3] - resultVector[2]; 00107 memcpy(result, &searchString[resultVector[2]], length); 00108 result[length] = '\0'; 00109 return rc; 00110 } 00111
Generated on Thu Jan 12 2012 22:35:20 for WPILibC++ by
1.7.1