configurationmanager.cc

来自「VC视频对象的跟踪提取原代码(vc视频监控源码)」· CC 代码 · 共 282 行

CC
282
字号
/********************************************************************* * C++ source * * File : 	ConfigurationManager.cc (formerly GlobalsManager.cc) * * Module :	ConfigurationManager (formerly GlobalsManager) * * Author : 	A M Baumberg (CoMIR) * * Creation Date : Mon Oct 21 13:33:42 1996  * * Changes : nts: Some changes in 2000--2001. *           nts: Jul 27, 2001: Fix for problem under Xt 6.0 when using *                libstdc++-libc6.2-2.so.3 . Do text search for "////" to find it. *           nts: Aug 2001: changed file and class name to more appropriate name. *           nts: Aug 2001: added support for setting icon for our window (XPM), *                changed colours (fallback) for all windows. * *********************************************************************/#include "ConfigurationManager.h"#include <iostream>#include <fstream>#include <cmath>#include <sstream>#include <cassert>#include <cstdio> // for sscanf(...), sprintf(...)#ifdef LINUX#include <sys/prctl.h>#include <sched.h>#include <unistd.h> // for getpid()#endif#include <pthread.h>#ifndef NO_DISPLAY#include <cstdlib>  // for atof(...) etc#include <csignal>  // for SIGHUP#include <X11/X.h>#include <X11/Xlib.h>#include <X11/Intrinsic.h>#include <X11/cursorfont.h>#include <Xm/RowColumn.h>#include <Xm/ToggleB.h>#include <Xm/PushB.h>#include <Xm/MessageB.h>#include <Xm/TextF.h>#include <Xm/Label.h>#include <Xm/Text.h>#include <Xm/Scale.h>#include <Xm/Form.h>#include <Xm/Separator.h>#include <Xm/CascadeB.h>#include <Xm/FileSB.h>#include <Xm/SelectioB.h>#include <Xm/DialogS.h>#include <X11/xpm.h>   // for colour icons in XPM format#include "os_specific_things.h"  // for usleep()namespace ReadingPeopleTracker{static int back_argc;static char **back_argv;static char **back_owners;static char **back_tags;ConfigurationManager *back_this;static pid_t back_pid = getpid();} // namespace ReadingPeopleTracker#else//#include "strcasecmp.h"#include "os_specific_things.h"  // for usleep()#endif   // #ifndef NO_DISPLAY#include "text_output.h" // for cerror etc#include "tracker_defines_types_and_helpers.h"namespace ReadingPeopleTracker{void ConfigurationVariable::full_printout(ostream &strm_out ){    strm_out << "Tag: " << tag << endl;        if (fixed)	strm_out << "constant " << endl;    else	strm_out << "variable " << endl;        if (owner_class != NULL)	strm_out << "object class: " << owner_class << endl;        if (help_string != NULL)	strm_out << "help info: " << help_string << endl;}bool RealConfigurationVariable::read_value(istream &strm_in){    realno new_value;    strm_in >> new_value;    if (constrained)    {	if ((new_value > max) || (new_value < min))	    return false;    }    value = new_value;    return true;}void RealConfigurationVariable::output_value(ostream &strm_out){    if (real_isnan(value)) strm_out << "Undefined" << endl;    else strm_out << value << endl;}void RealConfigurationVariable::full_printout(ostream &strm_out ){    ConfigurationVariable::full_printout(strm_out);    strm_out << "current value "; output_value(strm_out);    if (constrained)    {	strm_out << "( min: " << min << " max: "		 << max << ")";    }    strm_out << endl;}bool IntConfigurationVariable::read_value(istream &strm_in){    int new_value;    strm_in >> new_value;    if (constrained)    {	if ((new_value > max) || (new_value < min))	    return false;    }    value = new_value;    return true;}void IntConfigurationVariable::output_value(ostream &strm_out){    strm_out << value << endl;}void IntConfigurationVariable::full_printout(ostream &strm_out ){    ConfigurationVariable::full_printout(strm_out);    strm_out << "current value " << value;    if (constrained)    {	strm_out << "( min: " << min << " max: "		 << max << ")";    }    strm_out << endl;}bool BoolConfigurationVariable::read_value(istream &strm_in){//    strm_in >> (int&) value;// size of a bool is undefined.. better to do it like this    int temp_value;    strm_in >> temp_value;    value = temp_value == 0 ? false : true;    return true;}void BoolConfigurationVariable::output_value(ostream &strm_out){    strm_out << value << endl; }void BoolConfigurationVariable::full_printout(ostream &strm_out){    ConfigurationVariable::full_printout(strm_out);    strm_out << "current value ";    if (value == false)	strm_out << "false" << endl;    else	strm_out << "true" << endl;}bool StringConfigurationVariable::read_value(istream &strm_in){    static char buffer[255];    strm_in >> buffer;    char *new_str = new char[strlen(buffer)+1];    strcpy(new_str, buffer);    value = new_str;    return true;}void StringConfigurationVariable::output_value(ostream &strm_out){    if (value != NULL)	strm_out << value << endl;}void StringConfigurationVariable::full_printout(ostream &strm_out ){    ConfigurationVariable::full_printout(strm_out);        if (value != NULL)	strm_out << "current value: " << value << endl;    else	strm_out << "not set to any value" << endl;}ConfigurationManager::ConfigurationManager(){    table = NULL;    no_variables = 0;    max_variables = 0;        our_icon = NULL;  // means use default icon from icons.h    //   max_variables = 128;//   no_variables = 0;//   // set up array of pointers//   table = new ConfigurationVariable*[max_variables];}ConfigurationManager::~ConfigurationManager(){    for (unsigned int i = 0; i < no_variables; i++)	delete table[i];        delete [] table;}void ConfigurationManager::register_variable(ConfigurationVariable *var){    if (table == NULL)    { 	max_variables = 128;	no_variables = 0;	// set up array of pointers	table = new ConfigurationVariable*[max_variables];	flags = NULL;    }          bool already_registered = false;        for (unsigned int i = 0; i < no_variables; i++)	if ((strlen(var->tag) == strlen(table[i]->tag)) &&	    (strcasecmp(table[i]->tag, var->tag) == 0))	    already_registered = true;        //if not already registered    if (!already_registered)    {	if ((no_variables+1) < max_variables)	    table[no_variables++] = var;	else	{	    unsigned int max_variables2 = 2 * max_variables;	    ConfigurationVariable **table2 = 		new ConfigurationVariable*[max_variables2];	    memcpy(table2, table, sizeof(table));	    delete [] table;	    table = table2;	    max_variables = max_variables2;	    register_variable(var);	}    }    else    {	cerror << "ConfigurationManager::register_variable: "	       << " Illegal multiple registration of variable 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?