Exemple #1
0
	String String::strip(Strings tokens) const
	{
		if(tokens.empty())
			tokens.push_back(L" ");

		IndexVar left = 0, right = mContent.size();
		while(left<mContent.size())
		{
			bool flag = false;
			for(Strings::iterator ptr = tokens.begin(); ptr != tokens.end(); ptr++)
				if(find(*ptr,left)==left)
				{
					flag = true;
					break;
				}
			if(!flag)
				break;
			left++;
		}
		while(right>=0)
		{
			bool flag = false;
			for(Strings::iterator ptr = tokens.begin(); ptr != tokens.end(); ptr++)
				if(rfind(*ptr,right-1)==right-1)
				{
					flag = true;
					break;
				}
			if(!flag)
				break;
			right--;
		}
		return substr(left,right-left);
	}
Exemple #2
0
	Strings String::split(Strings tokens) const
	{
		if(tokens.empty())
			tokens.push_back(L" ");

		Strings ans;
		base_wstring nowS;
		IndexVar index = 0;
		while(index<mContent.size())
		{
			bool flag = false;
			for(Strings::iterator ptr = tokens.begin(); ptr != tokens.end(); ptr++)
				if(find(*ptr,index)==index)
				{
					flag = true;
					ans.push_back(nowS);
					nowS = L"";
					break;
				}
			if(!flag)
				nowS += mContent[index];
			index++;
		}
		ans.push_back(nowS);

		return ans;
	}
Exemple #3
0
bool User_Program::Compile (string &text, bool list_flag)
{
	Strings lines;
	Str_Itr line_itr;

	//---- split the text into lines ----

	String_Ptr (text)->Parse (lines, "\n\r\f");

	for (line_itr = lines.begin (); line_itr != lines.end (); line_itr++) {
		line_num++;

		if (list_flag) {
			exe->Print (1, "\t") << *line_itr;
		}
		line_itr->Clean ();
		if (line_itr->empty ()) continue;

		if (declare_flag) {
			if (!Initial_Declare (*line_itr)) break;
		} else if (table_flag) {
			if (!Initial_Table (*line_itr)) break;
		} else {
			while (Get_Token (*line_itr)) {
				if (!Process_Token ()) break;
			}
		}
	}
	return (true);
}
Exemple #4
0
std::string 
StringTools::wrap( const std::string &text,
                   int wrapColumn )
{
  const char lineBreak = '\n';
  Strings lines = split( text, lineBreak );

  std::string wrapped;
  for ( Strings::const_iterator it = lines.begin(); it != lines.end(); ++it )
  {
    if ( it != lines.begin() )
      wrapped += lineBreak;

    const std::string &line = *it;
    unsigned int index =0;
    while ( index < line.length() )
    {
      std::string lineSlice( line.substr( index, wrapColumn ) );
      wrapped += lineSlice;
      index += wrapColumn;
      if ( index < line.length() )
        wrapped += lineBreak;
    }
  }

  return wrapped;
}
bool FfmpegOutput::initialize(const Attributes &attributes)
{
	FfmpegResources::instance().registerAll();

	queryFormats();

	Strings avFormats;
	for(int i=0; i<m_avFormats.size(); ++i)
	{
		avFormats.push_back(m_avFormats[i].name);
	}

	//default mp4
//	std::string avFormatName="mp4";
//	std::string avFormatName="h264";
	std::string avFormatName="f4v";
//	std::string avFormatName="flv";
	Strings::iterator iter=std::find(avFormats.begin(), avFormats.end(), avFormatName);

	if(iter == avFormats.end())
		avFormatName=avFormats[0];
	
	m_enabled=false;
	m_recording=false;
	m_audioRecording=false;

	addAttribute("enable", false);
	addAttribute("outputFormat", avFormatName, avFormats);
	addAttribute("outputLocation", "untitled.mp4");
//	addAttribute("outputLocation", "test.mp4");
//	addAttribute("outputLocation", "test.h264");
//	addAttribute("outputLocation", "rtmp://localhost/live/test");
//	addAttribute("outputLocation", "rtmp://localhost:1935/live/stream");

	m_bufferSampleId=MediaSampleFactory::getTypeId("BufferSample");
	m_ffmpegPacketSampleId=MediaSampleFactory::getTypeId("FfmpegPacketSample");
    m_eventSampleId=Limitless::MediaSampleFactory::getTypeId("EventSample");

	m_videoSinkPad=addSinkPad("Sink", "[{\"mime\":\"video/*\"}, {\"mime\":\"image/*\"}]");
	m_audioSinkPad=addSinkPad("AudioSink", "[{\"mime\":\"audio/raw\"}]");
//	addSinkPad("[{\"mime\":\"audio/*\"}]");

	return true;
}
Exemple #6
0
void FileUtils::close(Mapper * mapper) {
	Strings * columnNames = mapper->getColumnNames();
	for (Strings::iterator it = columnNames->begin(); it != columnNames->end();
			++it) {
		std::string columnName = *it;
		BulkFileWriter * bulkFileWriter =
				(*(mapper->getColumnsToWriters()))[columnName];
		delete bulkFileWriter;
	}
}
void PluginRegistry::init()
{
    // for each directory
    for( Strings::const_iterator i = _directories.begin();
         i != _directories.end(); ++i )
    {
        const std::string& dir = *i;
        LBLOG( LOG_PLUGIN ) << "Searching plugins in " << dir << std::endl;

#ifdef _WIN32
        Strings files = lunchbox::searchDirectory( dir, "EqualizerCompressor*.dll");
        const char DIRSEP = '\\';
#elif defined (Darwin)
        Strings files = lunchbox::searchDirectory( dir,
                                               "libEqualizerCompressor*.dylib");
        Strings oldFiles = lunchbox::searchDirectory( dir,
                                                  "libeqCompressor*.dylib" );
        files.insert( files.end(), oldFiles.begin(), oldFiles.end( ));
        const char DIRSEP = '/';
#else
        Strings files = lunchbox::searchDirectory( dir,
                                               "libEqualizerCompressor*.so" );
        Strings oldFiles = lunchbox::searchDirectory( dir, "libeqCompressor*.so" );
        files.insert( files.end(), oldFiles.begin(), oldFiles.end( ));
        const char DIRSEP = '/';
#endif
        
        // for each file found in the directory
        for( Strings::const_iterator j = files.begin(); j != files.end(); ++j )
        {
            // build path + name of library
            const std::string libraryName =
                dir.empty() ? *j : dir + DIRSEP + *j;
            addPlugin( libraryName );
        }
    }

    for( Plugins::const_iterator i = _plugins.begin(); i != _plugins.end(); ++i)
    {
        Plugin* plugin = *i;
        plugin->initChildren();
    }
}
Exemple #8
0
void Display::discoverLocal( Config* config )
{
    Node* node = config->findAppNode();
    EQASSERT( node );
    if( !node )
        return;

    const Pipes& pipes = node->getPipes();
    EQASSERT( !pipes.empty( ));
    if( pipes.empty( ))
        return;

    Pipe* pipe = pipes.front();
    Window* window = new Window( pipe );
    window->setViewport( Viewport( .25f, .2f, .5f, .5f ));
    window->setName( pipe->getName() + " window" );
    window->setIAttribute( Window::IATTR_PLANES_STENCIL, 1 );

    Channel* channel = new Channel( window );
    channel->setName( pipe->getName() + " channel" );
    Observer* observer = new Observer( config );

    const PixelViewport& pvp = pipe->getPixelViewport();
    Wall wall;
    if( pvp.isValid( ))
        wall.resizeHorizontalToAR( float( pvp.w ) / float( pvp.h ));

    Canvas* canvas = new Canvas( config );
    canvas->setWall( wall );

    Segment* segment = new Segment( canvas );
    segment->setChannel( channel );

    Strings names;
    names.push_back( EQ_SERVER_CONFIG_LAYOUT_2D_DYNAMIC  );
    names.push_back( EQ_SERVER_CONFIG_LAYOUT_SIMPLE );
    names.push_back( EQ_SERVER_CONFIG_LAYOUT_DB_DS );
    names.push_back( EQ_SERVER_CONFIG_LAYOUT_DB_STATIC );
    names.push_back( EQ_SERVER_CONFIG_LAYOUT_DB_DYNAMIC );
    names.push_back( EQ_SERVER_CONFIG_LAYOUT_2D_STATIC );

    for( StringsCIter i = names.begin(); i != names.end(); ++i )
    {
        Layout* layout = new Layout( config );
        layout->setName( *i );

        View* view = new View( layout );
        view->setObserver( observer );
        view->setWall( wall );

        canvas->addLayout( layout );
    }

    config->activateCanvas( canvas );
}
Exemple #9
0
std::string StringManager::mt_Get_String(Strings& strings, const std::string& string_id, const GameStringArguments& args)
{
	std::string l_ret;
	auto l_str(strings.find(string_id));

	if (l_str != strings.end())
	{
		l_ret = l_str->second.mt_Get_String(args);
	}

	return l_ret;
}
ProteinsAnchorsSamplingSpace get_part_of_sampling_space(
    const ProteinsAnchorsSamplingSpace &prots_ss, const Strings &prot_names) {
  ProteinsAnchorsSamplingSpace ret(multifit::get_partial_proteomics_data(
      prots_ss.get_proteomics_data(), prot_names));
  ret.set_anchors(prots_ss.get_anchors());
  // add the paths
  for (Strings::const_iterator it = prot_names.begin(); it != prot_names.end();
       it++) {
    ret.set_paths_for_protein(*it, prots_ss.get_paths_for_protein(*it));
  }
  return ret;
}
Exemple #11
0
void FileUtils::deleteFile(std::string bulkDirectory, Mapper * mapper) {
	Strings * columnNames = mapper->getColumnNames();
	for (Strings::iterator it = columnNames->begin(); it != columnNames->end();
			++it) {
		std::string columnName = *it;
		std::string fileName = mapper->getFilename(bulkDirectory, columnName);
		std::ifstream columnFile(fileName.c_str());
		if (columnFile.good()) {
			columnFile.close();
			remove(fileName.c_str());
		}
	}
}
Exemple #12
0
bool
OracleDialect::table_exists(SqlConnection &conn, const String &table)
{
    Strings s = get_tables(conn);
    for (Strings::iterator i = s.begin(); i != s.end(); ++i)
    {
        if (*i == table)
        {
            return true;
        }
    }
    return false;
}
Exemple #13
0
int Execution_Service::Start_Execution (Strings keys) 
{
	Str_Itr key_itr;
	char *config_file;

	Program_Status (RUNNING);
	
	Show_Banner ();

	//---- check for a config file ----

	config_file = get_env ("TRANSIMS_CONFIG_FILE");

	if (config_file != 0) {
		if (!Read_Control_File (config_file)) {
			return (Return_Code ());
		}
	}

	//---- process the control keys ----
	
	for (key_itr = keys.begin (); key_itr != keys.end (); key_itr++) {
		Process_Control_String (key_itr->c_str ());
	}

	//---- open the output report ----

	if (Check_Control_Key (TITLE)) {
		Title (Get_Control_String (TITLE));
	}
	Open_Report (Get_Control_String (REPORT_DIRECTORY), Get_Control_String (REPORT_FILE), Set_Control_Flag (REPORT_FLAG));
	
	if (report_flag) Read_Reports ();
		
	set_new_handler (Insufficient_Memory);

	//---- start processing ----

	Program_Control ();

	if (report_flag) {
		List_Reports ();
	} else if (!Highest_Control_Group (PROGRAM_REPORTS, 0)) {
		Print (1);
		Flush ();
	}
	Execute ();

	return (Return_Code ());
}
Exemple #14
0
bool Data_Range::Add_Breaks (string text)
{
	int low, high;
	double d1, d2;
	Strings breaks;
	Str_Itr itr;

	//---- check for special conditions ----

	if (text.empty () || text [0] == '\n') return (true);

	if (String_Ptr (text)->Equals ("None")) {
		return (Add_Range (minimum, maximum));
	}

	//---- unpack the break string ----	

	low = minimum;

	String_Ptr (text)->Parse (breaks);

	for (itr = breaks.begin (); itr != breaks.end (); itr++) {
		if (!String_Ptr (*itr)->Range (d1, d2)) continue;

		if (d1 == 0.0 && d2 == 0.0) continue;
		if (d2 > d1) goto break_error;

		high = DTOI (d2 * factor);

		if (low > high || low < minimum || high > maximum) goto break_error;

		if (low < high) {
			if (!Add_Range (low, high)) return (false);
		}
		low = high;
	}
	high = maximum;

	if (low < high) {
		return (Add_Range (low, high));
	}
	return (Num_Ranges () > 0);

break_error:
	if (exe->Send_Messages ()) {
		exe->Error (String ("Range Breaks %s are Illogical") % text);
	}
	return (false);
}
Exemple #15
0
static void normalizeLines(Strings& in, StringsSet& out, bool sortWords, bool ignoreBlankLines,
                           char wordsep = ' ') {
    Strings::iterator begin = in.begin(), end = in.end(), i = begin, o = begin;
    for (; i != end; ++i) {
        std::string& line = *i;
        normalizeLine(line, sortWords, wordsep);
        bool empty = ignoreBlankLines && line.empty();
        if (!empty) {
            out.insert(line);
            if (i != o) *o = std::move(*i);
            ++o;
        }
    }
    in.erase(o, end);
}
Exemple #16
0
void FileUtils::open(std::string bulkDirectory, Mapper * mapper) {
	// create directory with read/write/search permissions for owner and group,
	// and with read/search permissions for others.
	mkdir(bulkDirectory.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);

	std::map<std::string, BulkFileWriter *> * columnsToWriters = new std::map<
			std::string, BulkFileWriter *>();

	Strings * columnNames = mapper->getColumnNames();
	for (Strings::iterator it = columnNames->begin(); it != columnNames->end();
			++it) {
		std::string columnName = *it;
		std::string fileName = mapper->getFilename(bulkDirectory, columnName);
		(*columnsToWriters)[columnName] = new BulkFileWriter(fileName);
	}
	mapper->setColumnsToWriters(columnsToWriters);
}
Exemple #17
0
bool Data_Range::Add_Ranges (string text)
{
	int low, high;
	double d1, d2;
	Strings ranges;
	Str_Itr itr;

	//---- check for special conditions ----

	if (text.empty () || text [0] == '\n') return (true);
	
	if (String_Ptr (text)->Equals ("All")) {
		return (Add_Range (minimum, maximum, increment));
	}

	//---- unpack the range string ----	

	String_Ptr (text)->Parse (ranges);

	for (itr = ranges.begin (); itr != ranges.end (); itr++) {
		if (!String_Ptr (*itr)->Range (d1, d2)) continue;

		if (d1 == 0.0 && d2 == 0.0 && !itr->Equals ("0")) continue;

		low = DTOI (d1 * factor);
		high = DTOI (d2 * factor);

		if (low > high || low < minimum || high > maximum) {
			if (exe->Send_Messages ()) {
				exe->Error (String ("Range %g-%g is Out of Range") % d1 % d2);
			}
		}
		if (!Add_Range (low, high, increment)) return (false);
	}
	return (Num_Ranges () > 0);
}
Exemple #18
0
int main(int argc, char *argv[])
{
	// Set the current locale.
	setlocale(LC_ALL, "");
	// Set the text message domain.
	bindtextdomain("tilesetter", LOCALE_DIR);
	textdomain("tilesetter");

	static const char* version = "0.1";
	std::cout << boost::format(_("Tilesetter version %1%")) % version << std::endl;
	std::cout << _(
	"Copyright (C) 2009 by Tamino Dauth\n"
	"[email protected]\n"
	"\n"
	"This program is free software; you can redistribute it and/or modify\n"
	"it under the terms of the GNU General Public License as published by\n"
	"the Free Software Foundation; either version 2 of the License, or\n"
	"(at your option) any later version.\n"
	"\n"
	"This program is distributed in the hope that it will be useful,\n"
	"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
	"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
	"GNU General Public License for more details.\n"
	"\n"
	"You should have received a copy of the GNU General Public License\n"
	"along with this program; if not, write to the\n"
	"Free Software Foundation, Inc.,\n"
	"59 Temple Place - Suite 330, Boston, MA  02111-1307, USA."
	) << std::endl;

	typedef std::vector<boost::filesystem::path> Paths;
	typedef std::vector<std::string> Strings;
	// TODO throws exception when using escaped white spaces! - string work around
	Strings environmentStrings;
	Paths environments;

	const boost::program_options::command_line_style::style_t pstyle = boost::program_options::command_line_style::style_t(
	boost::program_options::command_line_style::unix_style
	);

	boost::program_options::options_description desc("Allowed options");
	desc.add_options()
	("version,V", _("Shows current version of tilesetter."))
	("help,h",_("Shows this text."))
	// options

	// operations
	("reassign,r", _("Reads ground and cliff types from the first environment file and assigns them to all following."))

	// input
	("files,f", boost::program_options::value<Strings>(&environmentStrings), _("Expected environment files."))
	;

	boost::program_options::positional_options_description p;
	p.add("files", -1);

	boost::program_options::variables_map vm;

	try
	{
		boost::program_options::store(boost::program_options::command_line_parser(argc, argv).style(pstyle).options(desc).positional(p).run(), vm);
	}
	catch (std::exception &exception)
	{
		std::cerr << boost::format(_("Error while parsing program options: \"%1%\"")) % exception.what() << std::endl;

		return EXIT_FAILURE;
	}

	boost::program_options::notify(vm);

	// WORKAROUND
	environments.resize(environmentStrings.size());
	environments.assign(environmentStrings.begin(), environmentStrings.end());

	if (vm.count("version"))
	{
		std::cout << boost::format(_(
		"tilesetter %1%.\n"
		"Copyright © 2009 Tamino Dauth\n"
		"License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>\n"
		"This is free software: you are free to change and redistribute it.\n"
		"There is NO WARRANTY, to the extent permitted by law."
		)) % version << std::endl;

		return EXIT_SUCCESS;
	}

	if (vm.count("help"))
	{
		std::cout << desc << std::endl;
		std::cout << _("\nReport bugs to [email protected] or on https://wc3lib.org") << std::endl;

		return EXIT_SUCCESS;
	}

	if (environments.empty())
	{
		std::cerr << _("Missing environments arguments.") << std::endl;

		return EXIT_FAILURE;
	}

	if (vm.count("reassign"))
	{
		boost::ptr_vector<map::Environment> envs;
		envs.reserve(environments.size());

		BOOST_FOREACH(Paths::const_reference path, environments)
		{
			if (!boost::filesystem::is_regular_file(path))
			{
				std::cerr << boost::format(_("File %1% does not seem to be a regular file.")) % path << std::endl;

				return EXIT_FAILURE;
			}

			boost::filesystem::ifstream ifstream;
			ifstream.exceptions(boost::filesystem::ifstream::badbit | boost::filesystem::ifstream::failbit | boost::filesystem::ifstream::eofbit);

			try
			{
				ifstream.open(path, std::ios::in | std::ios::binary);
				std::auto_ptr<map::Environment> env(new map::Environment());
				env->read(ifstream);
				envs.push_back(env);
			}
			catch (std::exception &exception)
			{
				std::cerr << boost::format(_("Error occured while opening file %1%:\n\"%2%\"")) % path % exception.what() << std::endl;

				return EXIT_FAILURE;
			}
		}

		if (envs.size() < 2)
		{
			std::cerr << _("We need at least 2 environments.") << std::endl;

			return EXIT_FAILURE;
		}

		for (std::size_t i = 1; i < envs.size(); ++i)
		{
			envs[i].cliffTilesetsIds().assign(envs[0].cliffTilesetsIds().begin(), envs[0].cliffTilesetsIds().end());
			envs[i].groundTilesetsIds().assign(envs[0].groundTilesetsIds().begin(), envs[0].groundTilesetsIds().end());

			boost::filesystem::ofstream ofstream;
			ofstream.exceptions(boost::filesystem::ofstream::badbit | boost::filesystem::ofstream::failbit | boost::filesystem::ofstream::eofbit);

			try
			{
				ofstream.open(environments[i], std::ios::out | std::ios::binary);
				envs[i].write(ofstream);
			}
			catch (std::exception &exception)
			{
				std::cerr << boost::format(_("Error occured while saving file %1%:\n\"%2%\"")) % environments[i] % exception.what() << std::endl;

				return EXIT_FAILURE;
			}
		}
	}
Exemple #19
0
void PerfPrep::Program_Control (void)
{
	String key;
	Strings list;
	Str_Itr str_itr;

	//---- open network files ----

	Data_Service::Program_Control ();
	
	Read_Select_Keys ();
	Read_Flow_Time_Keys ();

	Print (2, String ("%s Control Keys:") % Program ());

	new_file_flag = System_File_Flag (NEW_PERFORMANCE);

	//---- open the merge performance ----
	
	key = Get_Control_String (MERGE_PERFORMANCE_FILE);

	if (!key.empty ()) {
		merge_file.File_Type ("Merge Performance File");
		Print (1);

		if (Check_Control_Key (MERGE_PERFORMANCE_FORMAT)) {
			merge_file.Dbase_Format (Get_Control_String (MERGE_PERFORMANCE_FORMAT));
		}
		merge_file.Open (Project_Filename (key));
		merge_flag = true;

		if (!new_file_flag) {
			Error ("A New Performance File is required for Merge Processing");
		}
	}

	//---- open the base performance ----
	
	key = Get_Control_String (BASE_PERFORMANCE_FILE);

	if (!key.empty ()) {
		base_file.File_Type ("Base Performance File");
		Print (1);

		if (Check_Control_Key (BASE_PERFORMANCE_FORMAT)) {
			base_file.Dbase_Format (Get_Control_String (BASE_PERFORMANCE_FORMAT));
		}
		base_file.Open (Project_Filename (key));
		base_flag = true;

		if (!new_file_flag) {
			Error ("A New Performance File is required for Base Processing");
		}
	}

	//---- open the merge turn delay ----

	turn_flag = System_File_Flag (TURN_DELAY);

	if (turn_flag) {
		key = Get_Control_String (MERGE_TURN_DELAY_FILE);

		if (!key.empty ()) {
			turn_file.File_Type ("Merge Turn Delay File");
			Print (1);

			if (Check_Control_Key (MERGE_TURN_DELAY_FORMAT)) {
				turn_file.Dbase_Format (Get_Control_String (MERGE_TURN_DELAY_FORMAT));
			}
			turn_file.Open (Project_Filename (key));
			turn_merge_flag = true;

			if (!System_File_Flag (NEW_TURN_DELAY)) {
				Error ("A New Turn Delay File is required for Merge Processing");
			}
		}
	}

	//---- processing method ----

	Print (1);
	key = Get_Control_Text (PROCESSING_METHOD);

	if (!key.empty ()) {
		method = Combine_Code (key);

		if (method != UPDATE_TIMES) {
			if (merge_flag || turn_merge_flag) {
				if (method == WEIGHTED_LINK_AVG || method == REPLACE_AVERAGE) {

					//---- merge weighting factor ----

					factor = Get_Control_Double (MERGE_WEIGHTING_FACTOR);
				}
			} else {
				//Error (String ("Processing Method %s requires Merge Files") % key);
			}
		}
	}

	//---- read the smoothing parameters ----

	smooth_flag = smooth_data.Read_Control ();

	if (smooth_flag) {
		if (!smooth_data.Num_Input (time_periods.Num_Periods ())) {
			Error ("Smooth Parameters are Illogical");
		}
		if (!new_file_flag) {
			Error ("A New Performance File is required for Data Smoothing");
		}
	}

	//---- set min travel time ----

	min_time_flag = Get_Control_Flag (SET_MIN_TRAVEL_TIME);

	if (min_time_flag && !new_file_flag) {
		Error ("A New Performance File is required for Minimum Travel Times");
	}

	//---- set merge transit data ----

	key = Get_Control_Text (MERGE_TRANSIT_DATA);

	if (!key.empty ()) {
		transit_flag = true;

		if (!System_File_Flag (TRANSIT_STOP) || !System_File_Flag (TRANSIT_ROUTE) ||
			!System_File_Flag (TRANSIT_SCHEDULE) || !System_File_Flag (TRANSIT_DRIVER)) {

			Error ("Transit Network Files are Required for Transit Loading");
		}
		if (!new_file_flag) {
			Error ("A New Performance File is required to Merge Transit Data");
		}
		key.Parse (list);
		for (str_itr = list.begin (); str_itr != list.end (); str_itr++) {
			if (str_itr->Starts_With ("VEH")) {
				transit_veh_flag = true;
			} else if (str_itr->Starts_With ("PER")) {
				transit_person_flag = true;
			} else if (str_itr->Starts_With ("PCE") || str_itr->Starts_With ("CAR_EQ")) {
				transit_pce_flag = true;
			}
		}
		if (!System_File_Flag (VEHICLE_TYPE) && transit_pce_flag) {
			Warning ("Vehicle Type File is Required for Transit PCE Loading");
		}
		if (!System_File_Flag (RIDERSHIP) && transit_person_flag) {
			Warning ("Ridership File is Required for Transit Person Loading");
		}
		if (!merge_flag) {
			method = Combine_Code (Get_Control_Text (PROCESSING_METHOD));
		}
	}

	//---- open the time constraint file ----
	
	key = Get_Control_String (TIME_CONSTRAINT_FILE);

	if (!key.empty ()) {
		constraint_file.File_Type ("Time Constraint File");
		Print (1);

		if (Check_Control_Key (TIME_CONSTRAINT_FORMAT)) {
			constraint_file.Dbase_Format (Get_Control_String (TIME_CONSTRAINT_FORMAT));
		}
		constraint_file.Open (Project_Filename (key));
		constraint_flag = true;
	}

	//---- open the time ratio file ----
	
	key = Get_Control_String (NEW_TIME_RATIO_FILE);

	if (!key.empty ()) {
		time_ratio_file.File_Type ("New Time Ratio File");

		time_ratio_file.Create (Project_Filename (key));
		time_ratio_flag = true;
	}

	//---- open the deleted record file ----
	
	key = Get_Control_String (NEW_DELETED_RECORD_FILE);

	if (!key.empty ()) {
		deleted_file.File_Type ("New Deleted Record File");
		Print (1);

		if (Check_Control_Key (NEW_DELETED_RECORD_FORMAT)) {
			deleted_file.Dbase_Format (Get_Control_String (NEW_DELETED_RECORD_FORMAT));
		}
		deleted_file.Create (Project_Filename (key));
		del_file_flag = true;
	}

	List_Reports ();

	first_delete = deleted_flag = (Report_Flag (DELETED_RECORDS) || del_file_flag);
}
Exemple #20
0
bool Zone_Location_Map::Read (void)
{
	int num, zone, n1, n2, count;
	double low, high;
	bool zone_flag, loc_flag;

	String text;
	Strings ranges;
	Str_Itr range_itr;
	Int_Map_Itr map_itr;

	Ints_Map_Stat zone_loc_stat;
	Integers empty, *loc_ptr;

	Data_Service *data = (Data_Service *) exe;
	zone_flag = data->System_Data_Flag (ZONE);
	loc_flag = data->System_Data_Flag (LOCATION);

	loc_ptr = 0;
	count = 0;

	while (Db_File::Read ()) {

		text = Record_String ();
		if (text.empty ()) continue;

		text.Parse (ranges);

		for (range_itr = ranges.begin (); range_itr != ranges.end (); range_itr++) {

			//---- create the zone index ----

			if (range_itr == ranges.begin ()) {
				zone = range_itr->Integer ();
				if (zone == 0) break;

				if (zone_flag) {
					map_itr = data->zone_map.find (zone);
					if (map_itr == data->zone_map.end ()) break;
					zone = map_itr->second;
				}
				zone_loc_stat = insert (Ints_Map_Data (zone, empty));

				loc_ptr = &zone_loc_stat.first->second;
				continue;
			}

			//---- parse location records ----

			if (!range_itr->Range (low, high)) continue;
			n1 = (int) low;
			n2 = (int) high;

			if (n1 == 0 && n2 == 0) continue;

			if (n1 > n2) {
				if (exe->Send_Messages ()) {
					exe->Write (1, String ("Location Range %d..%d is Illogical") % n1 % n2); 
				}
				return (false);
			}
			for (num = n1; num <= n2; num++) {
				if (loc_flag) {
					map_itr = data->location_map.find (num);
					if (map_itr == data->location_map.end ()) continue;
					loc_ptr->push_back (map_itr->second);
					count++;
				} else {
					loc_ptr->push_back (num);
					count++;
				}
			}
		}
	}
	exe->Print (2, String ("%s contains %d Zones and %d Locations") % File_Type () % Num_Zones () % count);
	return (true);
}
Exemple #21
0
void Display::discoverLocal( Config* config, const uint32_t flags )
{
    Node* node = config->findAppNode();
    LBASSERT( node );
    if( !node )
        return;

    const Pipes& pipes = node->getPipes();
    LBASSERT( !pipes.empty( ));
    if( pipes.empty( ))
        return;

    Pipe* pipe = pipes.front();
    Window* window = new Window( pipe );
    window->setViewport( Viewport( .25f, .2f, .5f, .5f ));
    window->setName( pipe->getName() + " window" );
    window->setIAttribute( Window::IATTR_PLANES_STENCIL, 1 );

    Channel* channel = new Channel( window );
    channel->setName( pipe->getName() + " channel" );
    Observer* observer = new Observer( config );

    const PixelViewport& pvp = pipe->getPixelViewport();
    Wall wall;
    if( pvp.isValid( ))
        wall.resizeHorizontalToAR( float( pvp.w ) / float( pvp.h ));

    Canvas* canvas = new Canvas( config );
    canvas->setWall( wall );

    Segment* segment = new Segment( canvas );
    segment->setChannel( channel );

    Strings names;
    const Nodes& nodes = config->getNodes();
    const bool scalability = nodes.size() > 1 || pipes.size() > 1;

    if( scalability )
        names.push_back( EQ_SERVER_CONFIG_LAYOUT_2D_DYNAMIC );

    names.push_back( EQ_SERVER_CONFIG_LAYOUT_SIMPLE );

    if( scalability )
    {
        names.push_back( EQ_SERVER_CONFIG_LAYOUT_DB_DS );
        names.push_back( EQ_SERVER_CONFIG_LAYOUT_DB_STATIC );
        names.push_back( EQ_SERVER_CONFIG_LAYOUT_DB_DYNAMIC );
        if( flags & fabric::ConfigParams::FLAG_MULTIPROCESS_DB &&
            nodes.size() > 1 )
        {
            for( NodesCIter i = nodes.begin(); i != nodes.end(); ++i )
            {
                if( (*i)->getPipes().size() > 1 )
                {
                    names.push_back( EQ_SERVER_CONFIG_LAYOUT_DB_2D );
                    break;
                }
            }
        }
    }

    for( StringsCIter i = names.begin(); i != names.end(); ++i )
    {
        Layout* layout = new Layout( config );
        layout->setName( *i );

        View* view = new View( layout );
        view->setObserver( observer );
        view->setWall( wall );

        canvas->addLayout( layout );
    }

    config->activateCanvas( canvas );
}
Exemple #22
0
void  Dtime::Time_String (string text, bool duration, Units_Type time_format)
{
	//---- NOON ----
	//---- MIDNIGHT ----
	//---- d@hh:mm:ss.x -----
	//---- d@hh:mm -----
	//---- [email protected] ----
	//---- d@ssssss ----
	//---- hh:mm:ss -----
	//---- hh:mm -----
	//---- hh:mmpm -----
	//---- hh.xxx ----
	//---- ssssss ----
	//---- dddhh:mm ----
	
	static const char *day_text [] = {
		"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT", "WKE", "WKD", "ALL", 0
	};
	int hour, min_time, hour_time, day_time;
	size_t index;
	char ch;
	bool sign;
	String result, time;
	Strings clock;
	Str_Itr itr;

	if (time_format == NO_UNITS) time_format = Time_Format ();

	dtime = 0;
	time = text;
	time.Trim (" \t");

	if (time.empty ()) return;

	//---- negative ----

	if (time [0] == '-') {
		if (!duration && time_format != SECONDS && time_format != MINUTES) {
			if (!warning_flag) goto time_error;
			return;
		}
		time.erase (0, 1);
		sign = true;
	} else {
		sign = false;
	}
	min_time = Round (60);
	hour_time = min_time * 60;
	day_time = hour_time * 24;

	//---- day ----

	if (time.find ("@") != time.npos) {
		if (time.Split (result, "@")) {
			if (result.empty () || result [0] < '0' || result [0] > '9') goto time_error;

			dtime = result.Integer () * day_time;
			if (time.empty ()) goto finish;
		}
	}

	//---- check for special codes ----

	if (time [0] < '0' || time [0] > '9') {
		if (time.Equals ("NOON")) {
			dtime += day_time / 2;
			goto finish;
		} 
		if (time.Equals ("MIDNIGHT")) {
			goto finish;
		}

		//---- VERSION3 Time Codes ----

		for (int i=0; day_text [i] != 0; i++) {
			if (time.Starts_With (day_text [i])) {
				time.erase (0, strlen (day_text [i]));

				if (time.empty ()) goto finish;
				if (time.find (":") != time.npos) {
					if (time.Split (result, ":")) {
						dtime = Round (result.Integer () * 3600 + time.Integer () * 60);
					}
				} else if (time [0] < '0' || time [0] > '9') {
					goto time_error;
				} else {
					dtime = Round (time.Integer () * 3600);
				}
				goto finish;
			}
		}
	}

	//---- check time units ----

	if (time.Parse (clock, ":") < 1) goto finish;

	itr = clock.begin ();
	ch = (*itr) [0];

	if (clock.size () == 1) {
		if ((ch < '0' || ch > '9') && ch != '.') goto time_error;

		if (time_format == SECONDS) {
			dtime += Round (itr->Double ()); 
		} else if (time_format == MINUTES) {
			dtime += DTOI (itr->Double () * min_time);
		} else if (time_format == HOURS) {
			dtime += DTOI (itr->Double () * hour_time); 
		} else if (itr->find ('.') != itr->npos) {
			dtime += DTOI (itr->Double () * hour_time); 
		} else {
			dtime += Round (itr->Double ());
		}
		goto finish;
	}

	//---- hour of the day ----

	if (ch < '0' || ch > '9') goto time_error;

	hour = itr->Integer ();

	dtime += hour * hour_time;

	if (++itr == clock.end ()) goto finish;

	//---- minute of the hour ----
	
	ch = (*itr) [0];
	if (ch < '0' || ch > '5' || itr->length () != 2) goto time_error;

	dtime += itr->Integer () * min_time;

	if (++itr == clock.end ()) goto finish;

	//---- seconds of the minute ----

	ch = (*itr) [0];
	if (ch < '0' || ch > '5') goto time_error;

	index = itr->find ('.');

	if (index != itr->npos) {
		if (index != 2) goto time_error;
		dtime += Round (itr->Double ()); 
	} else {
		if (itr->length () != 2) goto time_error;
		dtime += Round (itr->Double ());
	}
finish:
	if (sign) dtime = -dtime;
	return;

time_error:
	exe->Warning ("Time Conversion ") << text;
	warning_flag = true;
}
Exemple #23
0
bool TransimsNet::Get_Phasing_Data (Phasing_File &file, Phasing_Record &phasing_rec)
{
	int link, dir, node, dir_index, to_index, num, detector, signal;
	String svalue;
	
	Int_Map_Itr map_itr;
	Int2_Map_Itr map2_itr;
	Link_Data *link_ptr;
	Dir_Data *dir_ptr;

	Phasing_Data *phasing_ptr = &(phasing_rec.phasing_data);

	//---- process the header record ----
	
	if (!file.Nested ()) {
		signal = file.Signal ();
		if (signal == 0) return (false);

		map_itr = signal_map.find (signal);
		if (map_itr == signal_map.end ()) {
			Warning (String ("Phasing Signal %d was Not Found") % signal);
			return (false);
		}
		phasing_rec.Signal (map_itr->second);

		phasing_ptr->Phasing (file.Phasing ());
		phasing_ptr->Phase (file.Phase ());

		//---- process the detectors ----

		svalue = file.Detectors ();

		if (!svalue.empty ()) {
			Strings detect;
			Str_Itr itr;

			num = svalue.Parse (detect, "|+/");

			for (itr = detect.begin (); itr != detect.end (); itr++) {
				detector = itr->Integer ();
				if (detector <= 0) break;

				map_itr = detector_map.find (detector);
				if (map_itr == detector_map.end ()) {
					Warning (String ("Signal %d Detector %d was Not Found") % file.Signal () % detector);
					break;
				}
				phasing_ptr->detectors.push_back (map_itr->second);
			}
		}
		if (file.Version () > 40) return (phasing_rec.Signal () >= 0);
	}
	Movement_Data move_rec;

	move_rec.Movement (file.Movement ());

	//---- convert the link direction ----
	
	link = file.Link ();
	dir = file.Dir ();

	link_ptr = Set_Link_Direction (file, link, dir);

	if (link_ptr == 0) return (false);

	if (dir) {
		dir_index = link_ptr->BA_Dir ();
		node = link_ptr->Anode ();
	} else {
		dir_index = link_ptr->AB_Dir ();
		node = link_ptr->Bnode ();
	}
	if (dir_index < 0) {
		Warning (String ("Phasing Plan %d Link %d Direction %s was Not Found") % Progress_Count () % 
			link_ptr->Link () % ((dir) ? "BA" : "AB"));
		return (false);
	}

	//---- convert the to-link number ----

	link = file.To_Link ();

	map_itr = link_map.find (link);
	if (map_itr == link_map.end ()) {
		Warning (String ("Phasing Plan %d Link %d was Not Found") % Progress_Count () % link);
		return (false);
	}
	link = map_itr->second;

	link_ptr = &link_array [link];

	if (link_ptr->Anode () == node) {
		to_index = link_ptr->AB_Dir ();
	} else if (link_ptr->Bnode () == node) {
		to_index = link_ptr->BA_Dir ();
	} else {
		Node_Data *ptr = &node_array [node];
		Warning (String ("Phasing Plan %d Node %d is Not on Link %d") % Progress_Count () % ptr->Node () % link_ptr->Link ());
		return (false);
	}

	//---- check the link connection ----

	map2_itr = connect_map.find (Int2_Key (dir_index, to_index));

	if (map2_itr == connect_map.end ()) {
		to_index = link_ptr->Link ();

		dir_ptr = &dir_array [dir_index];
		link_ptr = &link_array [dir_ptr->Link ()];
		dir_index = link_ptr->Link ();

		if (file.Version () > 40) {
			Warning (String ("No Link Connection between %d and %d") % dir_index % to_index);
		}
		return (false);
	}

	//---- save the data ----

	move_rec.Connection (map2_itr->second);

	move_rec.Protection (file.Protection ());

	if (file.Version () <= 40 && move_rec.Movement () == 0) {
		Connect_Data *connect_ptr;
		const char *direction;

		dir_ptr = &dir_array [dir_index];
		direction = compass.Point_Text (dir_ptr->In_Bearing (), 4);

		if (*direction == 'N') {
			dir = NB_TH;
		} else if (*direction == 'S') {
			dir = SB_TH;
		} else if (*direction == 'E') {
			dir = EB_TH;
		} else {
			dir = WB_TH;
		}
		connect_ptr = &connect_array [map2_itr->second];
		num = connect_ptr->Type ();
		
		if (num == RIGHT || num == R_SPLIT) {
			dir += NB_RT - NB_TH;
		} else if (num == LEFT || num == L_SPLIT) {
			dir += NB_LT - NB_TH;
		} else if (num == UTURN) {
			dir += NB_UT - NB_TH;
		}
		move_rec.Movement (dir);
	}
	phasing_ptr->push_back (move_rec);

	return (phasing_rec.Signal () >= 0);
}
Exemple #24
0
    Strings discover( const lunchbox::Servus::Interface interface_,
                      const unsigned browseTime )
    {
#ifdef LUNCHBOX_USE_DNSSD
        instanceMap_.clear();

#   ifdef SERVUS_BONJOUR
        const lunchbox::Servus::Interface addr = interface_;
#   endif
#   ifdef SERVUS_AVAHI // no kDNSServiceInterfaceIndexLocalOnly support in avahi
        const lunchbox::Servus::Interface addr = lunchbox::Servus::IF_ALL;
#   endif
        DNSServiceRef service;
        const DNSServiceErrorType error = DNSServiceBrowse( &service, 0,
                                                            addr,
                                                            name_.c_str(),
                                                            "",
                                     (DNSServiceBrowseReply)browseCBS_,
                                                            this );
        if( error != kDNSServiceErr_NoError )
        {
            LBWARN << "DNSServiceDiscovery error: " << error << std::endl;
            return getInstances();
        }

        handleEvents_( service, browseTime );
        DNSServiceRefDeallocate( service );

#   ifdef SERVUS_AVAHI // let's implement InterfaceIndexLocalOnly for avahi
        if( interface_ == lunchbox::Servus::IF_LOCAL )
        {
            Strings hosts;
            char hostname[256] = {0};

            gethostname( hostname, 256 );

            std::string name = hostname;
            const size_t dotPos = name.find( '.' );
            if( dotPos != std::string::npos )
                name = name.substr( 0, dotPos );

            const std::string dot = ".";
            hosts.push_back( name );
            hosts.push_back( name + ".local." );

            InstanceMap localData;
            for( InstanceMapCIter i = instanceMap_.begin();
                 i != instanceMap_.end(); ++i )
            {
                const ValueMap& values = i->second;
                const ValueMapCIter j = values.find( "servus_host" );
                const std::string& current = j->second;
                if( std::find( hosts.begin(), hosts.end(), current ) !=
                    hosts.end( ))
                {
                    localData[ i->first ] = i->second;
                }
            }
            instanceMap_.swap( localData );
        }
#   endif
#endif
        return getInstances();
    }
Exemple #25
0
int
main(int argc, char *argv[]) {
    using namespace Sawyer::CommandLine;
    typedef std::vector<std::string> Strings;

    // Usage:
    //    translator --command=CMD NAMES [-- SWITCHES...]         -- runs: CMD SWITCHES NAMES
    //    translator NAMES -- SWITCHES                        -- runs ROSE on SWITCHES NAMES
    // NAMES are always de-escaped and created
    Parser p;
    std::string cmd;
    p.with(Switch("command").argument("cmd", anyParser(cmd)));
    Strings args = p.parse(argc, argv).apply().unreachedArgs();

    // Expand the "+SOMETHING+" escapes in all arguments.
    typedef Sawyer::Container::Map<std::string, std::string> Translations;
    Translations map;
    map.insert("+PLUS+",        "+");
    map.insert("+SPACE+",       " ");
    map.insert("+DOLLAR+",      "$");
    map.insert("+STAR+",        "*");
    map.insert("+HASH+",        "#");
    map.insert("+SQUOTE+",      "'");
    map.insert("+DQUOTE+",      "\"");
    map.insert("+DOT+",         ".");
    map.insert("+SLASH+",       "/");
    map.insert("+BSLASH+",      "\\");
    for (Strings::iterator arg = args.begin(); arg != args.end(); ++arg) {
        std::string translated;
        for (size_t i=0; i<arg->size(); ++i) {
            size_t endPlus;
            if ((*arg)[i] == '+' && (endPlus=arg->find('+', i+1)) != std::string::npos) {
                std::string token = arg->substr(i, endPlus+1-i);
                translated += map.getOrElse(token, token);
                i = endPlus;
            } else {
                translated += (*arg)[i];
            }
        }
        *arg = translated;
    }

    // If there's a '--' argument, then create a stub C source file for each argument before the '--', move them all to the
    // end, and remove the '--'. I.e., if the arguments are "a b -- c d" then create files "a" and "b" and then rearrange the
    // arguments to read "c d a b".  If there's no "--", then create source files for all the arguments but don't rearrange
    // anything.
    Strings::iterator doubleHyphen = std::find(args.begin(), args.end(), "--");
    for (Strings::iterator arg = args.begin(); arg != doubleHyphen; ++arg) {
        std::ofstream of(arg->c_str());
        ASSERT_require(!of.bad());
        of <<"int main() {}\n";
    }
    if (doubleHyphen != args.end()) {
        Strings tmp(args.begin(), doubleHyphen);
        tmp.insert(tmp.begin(), ++doubleHyphen, args.end());
        args = tmp;
    }

    // Either the ROSE translator or some other command
    if (cmd.empty()) {
        std::cout <<"translator args are:";
        BOOST_FOREACH (const std::string &arg, args)
            std::cout <<" \"" <<StringUtility::cEscape(arg) <<"\"";
        std::cout <<"\n";
        
        args.insert(args.begin(), argv[0]);
        SgProject *project = frontend(args);
        ASSERT_not_null(project);
        exit(backend(project));
    }
Exemple #26
0
bool Execution_Service::Command_Line (Strings &commands)
{
	bool banner_flag, syntax_flag, help_flag, command_flag, key_flag, param_flag, control_flag, exit_flag, doc_flag, user_flag;
	String message;
	Str_Itr str_itr;
	char ch, *config_file;

	banner_flag = syntax_flag = help_flag = command_flag = key_flag = param_flag = control_flag = exit_flag = doc_flag = user_flag = false;

	if ((int) commands.size () < 1) {
		Show_Banner ();
		Show_Syntax ();
		banner_flag = syntax_flag = true;

		Control_File (Get_Control_File ());
		if (Control_File ().empty ()) return (false);

	} else {

		//---- process the command line -----

		for (str_itr = commands.begin (); str_itr != commands.end (); str_itr++) {

			if (str_itr->at (0) == '-') {
				ch = str_itr->at (1);
				if (ch == 'Q' || ch == 'q') {
					if (Master ()) Quiet (true);
				} else if (ch == 'H' || ch == 'h') {
					if (Master ()) Syntax_Help ();
					help_flag = syntax_flag = banner_flag = true;
				} else if (ch == 'P' || ch == 'p') {
					if (Master ()) Pause_Flag (true);
				} else if (ch == 'N' || ch == 'n') {
					if (Master ()) No_Pause (true);
				} else if (ch == 'D' || ch == 'd' ||
					ch == 'B' || ch == 'b') {	//---- version 4.0 compatibility ----
					if (Master ()) Detail (true);
				} else if (ch == 'K' || ch == 'k') {
					if (Master ()) key_flag = true;
				} else if (ch == 'X' || ch == 'x') {
					if (Master ()) {
						XML_Flag (true);
						if (str_itr->size () > 2 && (str_itr->at (2) == 'H' || str_itr->at (2) == 'h')) {
							XML_Help_Flag (true);
						}
					}
				} else if (ch == 'C' || ch == 'c') {
					if (Master ()) {
						control_flag = true;
						if (str_itr->size () > 2 && (str_itr->at (2) == 'X' || str_itr->at (2) == 'x')) {
							exit_flag = true;
						}
					}
				} else if (ch == 'R' || ch == 'r') {
					if (Master ()) {
						doc_flag = true;
						if (str_itr->size () > 2 && (str_itr->at (2) == 'U' || str_itr->at (2) == 'u')) {
							user_flag = true;
						}
					}
				} else {
					message ("Unrecognized Command Line Option = ");
					message += *str_itr ;
					goto error_message;
				}
			} else if (Control_File ().empty ()) {
				Control_File (*str_itr);
			} else if (Enable_Partitions ()) {
				if (First_Partition () >= 0) {
					message ("Too Many Partition Parameters");
					goto error_message;
				}
				int low, high;
				str_itr->Range (low, high);
				if (low < 0 || low > high || high > 999) {
					if (low == high) {
						message ("Partition Number %d is Out of Range (0..999)") % low;
					} else {
						message ("Partition Range %d..%d is Out of Range (0..999)") % low % high;
					}
				}
				First_Partition (low); 
				Last_Partition (high);
			} else if (Enable_Parameter ()) {
				if (!Parameter ().empty ()) {
					message ("Too Many Parameters");
					goto error_message;
				} else {
					Parameter (*str_itr);
					param_flag = true;
				}
			} else {
				command_flag = true;
			}
		}
		if (Control_File ().empty ()) {
			if (XML_Flag ()) XML_Open ();
			if (control_flag) Write_Control_File ();
			if (doc_flag) Document (user_flag);
			if (help_flag) {
				if (command_flag) {
					message = Program ();
					message += " has Too Many Parameters";
					Show_Warning (message);
				}
				Pause_Flag (true);
				Exit_Stat (DONE);
				return (false);
			} else if (XML_Flag () || control_flag || doc_flag) {
				Exit_Stat (DONE);
				return (false);
			}
			message ("No Control File");
			goto error_message;
		}
		if (!banner_flag) {
			Show_Banner ();
			banner_flag = true;
		}
	}

	//---- check for a config file ----

	config_file = get_env ("TRANSIMS_CONFIG_FILE");

	if (config_file != 0) {
		if (!Read_Control_File (config_file)) {
			message ("Reading Configuration File: \"%s\"") % config_file;
			goto error_message;
		}
	}

	//---- read the control file ----

	if (!Read_Control_File (Control_File ())) {
		if (control_flag) {
			Write_Control_File ();
			Exit_Stat (DONE);
			return (false);
		} else {
			message ("Reading Control File: \"%s\"") % Control_File ();
			goto error_message;
		}
	}
	if (control_flag) Write_Control_File ();
	if (XML_Flag ()) XML_Open ();
	if (doc_flag) Document (user_flag);

	if (exit_flag) {
		Exit_Stat (DONE);
		return (false);
	}

	//---- open the output report ----

	if (Check_Control_Key (TITLE)) {
		Title (Get_Control_String (TITLE));
	}
#ifdef DEBUG_KEYS
	{
#else
	if (Master ()) {
#endif
		Open_Report (Get_Control_String (REPORT_DIRECTORY), Get_Control_String (REPORT_FILE), Set_Control_Flag (REPORT_FLAG));
	}
	
	//---- show parameter warning ----

	if (command_flag) {
		message (Program ()) += " has Too Many Parameters";
		Warning (message);
		Write (1);
	}

	//---- show unrecognized control key warnings ----

	if (key_flag) {
		Show_Extra_Keys ();
	}
	if (!Check_Keys ()) {
		Error ("Required Control Keys were Not Found");
	}
	return (true);

error_message: 
	if (Master ()) {
		Quiet (false);
		if (!banner_flag) Show_Banner ();
		if (!syntax_flag) Show_Syntax ();
		Show_Error (message);
	}
	return (false);
}

//---------------------------------------------------------
//	Program_Control
//---------------------------------------------------------

void Execution_Service::Program_Control (void) 
{
	String key;
	Dtime increment;

	//---- override default page length ----

	if (Check_Control_Key (PAGE_LENGTH)) {
		int len = Get_Control_Integer (PAGE_LENGTH);
		if (len == 0) len = MAX_INTEGER;
		Page_Size (Page_Width (), len);
	}

	//---- project directory ----

	key = Get_Control_String (PROJECT_DIRECTORY);

	if (!key.empty ()) {
		Print_Filename (1, "Project Directory", key);
		Project_Directory (key);
	}

	//---- default file format ----

	Default_Format (Format_Code (Get_Control_Text (DEFAULT_FILE_FORMAT)));

	//---- time of day format ----

	Time_Format (Time_Code (Get_Control_Text (TIME_OF_DAY_FORMAT)));

	//---- model start time ----

	Model_Start_Time (Get_Control_Text (MODEL_START_TIME));

	//---- model end time ----

	Model_End_Time (Get_Control_Text (MODEL_END_TIME));

	//---- model time increment ----

	increment = Get_Control_Time (MODEL_TIME_INCREMENT);

	time_periods.Set_Periods (increment, Model_Start_Time (), Model_End_Time ());

	//---- units of measure ----

	Metric_Flag (Measure_Code (Get_Control_Text (UNITS_OF_MEASURE)) == METRIC);

	//---- drive side of road ----

	Left_Side_Flag (Drive_Side_Code (Get_Control_Text (DRIVE_SIDE_OF_ROAD)) == LEFT_SIDE);

	//---- random number seed ----

	if (Control_Key_Status (RANDOM_NUMBER_SEED)) {
		key = Get_Control_String (RANDOM_NUMBER_SEED);

		if (!key.empty ()) {
			if (key.length () > 9) key.erase (9);
			random.Seed (key.Integer ());
		}
		random_seed = random.Seed ();
		Output_Control_Label (RANDOM_NUMBER_SEED) << random_seed;
	}

	//---- warning messages ----

	if (Control_Key_Status (MAX_WARNING_MESSAGES)) {
		Max_Warnings (Get_Control_Integer (MAX_WARNING_MESSAGES));
	}
	Warning_Flag (Get_Control_Flag (MAX_WARNING_EXIT_FLAG));

	//---- problem count ----

	Max_Problems (Get_Control_Integer (MAX_PROBLEM_COUNT));

	//---- number of threads ----

	num_threads = Get_Control_Integer (NUMBER_OF_THREADS);

	if (num_threads > 1) {
		if (!Enable_Threads ()) {
			key (Program ()) += " is Not Thread Enabled";
			Warning (key);
			Write (1);
			num_threads = 1;
		}
	}

	int num = Highest_Control_Group (USER_FUNCTIONS, 0);

	if (num > 0) {
		for (int i=1; i <= num; i++) {
			key = Get_Control_String (USER_FUNCTIONS, i);

			if (!key.empty ()) {
				functions.Add_Function (i, key);
			}
		}
	}
}
Exemple #27
0
void IntControl::Read_Signal (void)
{
	int signal, node, num;
	String buffer;
	Strings nodes;

	Signal_Data signal_rec;
	Int_Map_Itr map_itr;
	Int_Map_Stat map_stat;
	Int_Set_Stat set_stat;
	Str_Itr str_itr;
	Int_Itr node_itr;
	Node_Data *node_ptr;

	//---- store the signal data ----

	Show_Message (String ("Reading %s -- Record") % signal_file.File_Type ());
	Set_Progress ();

	num_new = num_update = 0;

	while (signal_file.Read (false)) {
		Show_Progress ();

		//---- check the signal number ----

		signal = signal_file.Signal ();
		if (signal == 0) continue;
		
		map_itr = signal_map.find (signal);
		if (map_itr != signal_map.end ()) {
			if (update_flag) {
				set_stat = update_signal.insert (signal);
				if (!set_stat.second) {
					Warning ("Duplicate Signal Number = ") << signal;
				}
				num_update++;
				nsignal++;
			} else {
				Warning (String ("Signal %d Already Exists") % signal);
			}
			goto read_nest;
		}

		//---- gather the warrant signal data ----

		signal_rec.Clear ();

		signal_rec.Signal (signal);
		signal_rec.Group (signal_file.Group ());

		buffer = signal_file.Nodes ();
		if (buffer.empty ()) goto read_nest;

		num = buffer.Parse (nodes, "|+/");
		if (num == 0) goto read_nest;

		signal_rec.nodes.reserve (num);

		for (str_itr = nodes.begin (); str_itr != nodes.end (); str_itr++) {
			node = str_itr->Integer ();
			if (node <= 0) break;

			map_itr = node_map.find (node);
			if (map_itr == node_map.end ()) {
				Warning (String ("Signal %d Node %d was Not Found") % signal_rec.Signal () % node);
				continue;
			}
			node_ptr = &node_array [map_itr->second];

			if (node_ptr->Control () >= 0 && signal_file.Version () > 40) {
				Warning (String ("Node %d is assigned to multiple signals") % node);
				continue;
			} else if (node_ptr->Control () < -1) {
				Warning (String ("Node %d has a Sign/Signal control conflict") % node);
				continue;
			}
			signal_rec.nodes.push_back (map_itr->second);
		}
		if (signal_rec.nodes.size () == 0) goto read_nest;

		//---- insert the signal warrant ----

		num = (int) signal_array.size ();

		map_stat = signal_map.insert (Int_Map_Data (signal, num));

		if (!map_stat.second) {
			Warning ("Duplicate Signal Number = ") << signal_rec.Signal ();
			goto read_nest;
		}

		//---- set the node controls ----

		for (node_itr = signal_rec.nodes.begin (); node_itr != signal_rec.nodes.end (); node_itr++) {
			node_ptr = &node_array [*node_itr];
			node_ptr->Control (num);
		}
		signal_array.push_back (signal_rec);
		num_new++;
		nsignal++;

read_nest:
		for (num = signal_file.Times (); num > 0; num--) {
			if (!signal_file.Read (true)) {
				Error (String ("Number of Time Records for Signal %d") % signal);
			}
			Show_Progress ();
		}
	}
	End_Progress ();

	signal_file.Close ();

	Print (2, String ("Number of %s Records = %d") % signal_file.File_Type () % Progress_Count ());
	if (num_new > 0) {
		Print (1, "Number of New Signal Records = ") << num_new;
	}
	if (num_update > 0) {
		Print (1, "Number of Signal Updates = ") << num_update;
	}
}
Exemple #28
0
void Progression::Read_Weights (void)
{
	int group, num_periods;
	double weight;
	String record;
	Strings parts;
	Str_Itr str_itr;

	Doubles weights;
	Dbls_Map_Itr grp_itr;
	Dbls_Map_Stat map_stat;
	Dbl_Itr wt_itr;

	Show_Message (String ("Reading %s -- Record") % weight_file.File_Type ());
	Set_Progress ();

	num_periods = progress_time.Num_Periods ();

	while (weight_file.Read ()) {
		Show_Progress ();

		record = weight_file.Record_String ();
		record.Parse (parts);

		if ((int) parts.size () < 2) continue;

		str_itr = parts.begin ();
		group = str_itr->Integer ();

		weights.clear ();
		weight = 1.0;

		for (++str_itr; str_itr != parts.end (); str_itr++) {
			weight = str_itr->Double ();

			if (weight < 0.01 || weight > 1000.0) {
				Error (String ("Group %d Period Weight %.2lf is Out of Range (0.01..1000.0)") % group % weight);
			}
			weights.push_back (weight);
		}

		//---- check the data ----

		while ((int) weights.size () < num_periods) {
			weights.push_back (weight);
		}

		map_stat = weight_data.insert (Dbls_Map_Data (group, weights));

		if (!map_stat.second) {
			Warning ("Duplicate Weight Group = ") << group;
		}
	}
	End_Progress ();
	weight_file.Close ();

	Print (2, "Number of Group Period Weight Records = ") << Progress_Count ();

	if (Report_Flag (WEIGHT_REPORT)) {

		//---- print the report ----

		Header_Number (WEIGHT_REPORT);

		if (!Break_Check (weight_data.size () + 6)) {
			Print (1);
			Weight_Header ();
		}

		for (grp_itr = weight_data.begin (); grp_itr != weight_data.end (); grp_itr++) {
			Print (1, String ("%5d") % grp_itr->first);

			for (wt_itr = grp_itr->second.begin (); wt_itr != grp_itr->second.end (); wt_itr++) {
				Print (0, String ("  %8.2lf") % *wt_itr);
			}
		}
		Header_Number (0);
	}
}