Now you can download a copy of these docs so you can use them offline! Download now
IntCameraParameter.cpp
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
5 /*----------------------------------------------------------------------------*/
6 
7 #include "IntCameraParameter.h"
8 #include "pcre.h"
9 #include <stdio.h>
10 #include <string.h>
11 
17 IntCameraParameter::IntCameraParameter(const char *setString, const char *getString, bool requiresRestart)
18 {
19  m_changed = false;
20  m_value = 0;
21  m_setString = setString;
22  m_getString = getString;
23  m_requiresRestart = requiresRestart;
24 }
25 
31 {
32  return m_value;
33 }
34 
41 {
42  m_value = value;
43  m_changed = true;
44 }
45 
52 bool IntCameraParameter::CheckChanged(bool &changed, char *param)
53 {
54  changed = m_changed;
55  if (m_changed)
56  {
57  sprintf(param, m_setString, m_value);
58  m_changed = false;
59  return m_requiresRestart;
60  }
61  return false;
62 }
63 
70 void IntCameraParameter::GetParamFromString(const char *string, int stringLength)
71 {
72  char resultString[150];
73  if (SearchForParam(m_getString, string, stringLength, resultString) >= 0)
74  {
75  if (!m_changed) m_value = atoi(resultString);
76  }
77 }
78 
85 int IntCameraParameter::SearchForParam(const char *pattern, const char *searchString, int searchStringLen, char *result)
86 {
87  int vectorLen = 10;
88  int resultVector[vectorLen];
89  const char *error;
90  int erroffset;
91  pcre *compiledPattern = pcre_compile(
92  pattern, //"root.Image.I0.Appearance.Resolution=(.*)",
93  PCRE_CASELESS,
94  &error, // for error message
95  &erroffset, // for error offset
96  NULL); // use default character tables
97  int rc;
98  rc = pcre_exec(compiledPattern,
99  NULL,
100  searchString,
101  searchStringLen,
102  0,
103  0,
104  resultVector, //locations of submatches
105  vectorLen); //size of ovector
106  int length = resultVector[3] - resultVector[2];
107  memcpy(result, &searchString[resultVector[2]], length);
108  result[length] = '\0';
109  return rc;
110 }
111 
int SearchForParam(const char *pattern, const char *searchString, int searchStringLen, char *result)
void SetValue(int value)
IntCameraParameter(const char *setString, const char *getString, bool requiresRestart)
virtual void GetParamFromString(const char *string, int stringLength)
virtual bool CheckChanged(bool &changed, char *param)

Generated on Sat Apr 26 2014 12:26:45 for WPILibC++ by doxygen 1.8.6