コード例 #1
0
ファイル: ParameterUtils.cpp プロジェクト: samanseifi/Tahoe
/* construct extracting dimensions from the name */
MatrixParameterT::MatrixParameterT(const StringT& name_NxM, char variable):
	ParameterInterfaceT(name_NxM),
	fVariable(variable),
	fCopySymmetric(false)
{
	const char caller[] = "MatrixParameterT::MatrixParameterT";
	const char msg[] = "could not extract %s dimensions from \"%s\" in \"%s\"";

	/* resolve suffix */
	StringT suffix;
	suffix.Suffix(name_NxM, '_');
	if (suffix.StringLength() < 4)
		ExceptionT::GeneralFail(caller, msg, "matrix", suffix.Pointer(), name_NxM.Pointer());
	
	/* resolve column dimensions */
	StringT num;
	num.Suffix(suffix, 'x');
	if (num.StringLength() < 2 || !isdigit(num[1]))
		ExceptionT::GeneralFail(caller, msg, "col", num.Pointer(), name_NxM.Pointer());
	int col = -1;
	col = atoi(num.Pointer(1));
	if (col < 0)
		ExceptionT::GeneralFail(caller, msg, "col", num.Pointer(), name_NxM.Pointer());
	
	/* resolve row dimensions */
	suffix.Root('x');
	if (suffix.StringLength() < 2 || !isdigit(suffix[1]))
		ExceptionT::GeneralFail(caller, msg, "row", suffix.Pointer(), name_NxM.Pointer());
	int row = -1;
	row = atoi(suffix.Pointer(1));
	if (row < 0)
		ExceptionT::GeneralFail(caller, msg, "row", suffix.Pointer(), name_NxM.Pointer());
	
	/* initialize */
	fMatrix.Dimension(row, col);
	fMatrix = 0.0;
}
コード例 #2
0
ファイル: ExtractIOManager.cpp プロジェクト: samanseifi/Tahoe
void ExtractIOManager::OpenFile (ofstreamT& o, const StringT& name, bool append) const
{
  StringT filename (fOutputName);
  filename.Append ("_");
  for (int i=name.StringLength(); i < fNumDigits; i++)
    filename.Append ("0");
  filename.Append (name);
  filename.Append (".", fOutfileExtension);
  if (!append)
    {
      remove (filename); // remove any pre-existing file
      o.open (filename);
    }
  else
    o.open_append (filename);
  if (!o.is_open())
    ExceptionT::GeneralFail ("ExtractIOManager::OpenFile","Unable to open %s", filename.Pointer());
}
コード例 #3
0
ファイル: ParameterUtils.cpp プロジェクト: samanseifi/Tahoe
/* construct extracting length from the name */
VectorParameterT::VectorParameterT(const StringT& name_N, char variable):
	ParameterInterfaceT(name_N),
	fVariable(variable)
{
	const char caller[] = "VectorParameterT::VectorParameterT";
	const char msg[] = "could not extract length from \"%s\" in \"%s\"";

	/* resolve length */
	StringT suffix;
	suffix.Suffix(name_N, '_');
	if (suffix.StringLength() < 2 || !isdigit(suffix[1]))
		ExceptionT::GeneralFail(caller, msg, suffix.Pointer(), name_N.Pointer());
	int length = -1;
	length = atoi(suffix.Pointer(1));
	if (length < 0) 
		ExceptionT::GeneralFail(caller, msg, suffix.Pointer(), name_N.Pointer());

	/* initialize */
	fVector.Dimension(length);
	fVector = 0.0;
}
コード例 #4
0
ファイル: ArgSpecT.cpp プロジェクト: samanseifi/Tahoe
/* read value from stream */
bool ArgSpecT::ReadValue(istream& in)
{
	switch (fType)
	{
		case int_:
		{
			int a = -991991;
			in >> a;
			if (a != -991991) {
				SetValue(a);
				return true;
			}
		}
		case double_:
		{
			double a = -991.991;
			in >> a;
			if (a != -991.991) {
				SetValue(a);
				return true;
			}
		}
		case string_:
		{
			StringT a;
			a.GetLineFromStream(in);
			if (a.StringLength() > 0) {
				SetValue(a);
				return true;
			}
		}
		case bool_:
		{
			/* get next non-white space character */
			char a;	
			in.get(a);
			while (in.good() && isspace(a)) 
				in.get(a);	

			/* resolve */
			switch (a)
			{
				case '1':
				case 't':
				case 'T':
					SetValue(true);
					return true;
				case '0':
				case 'f':
				case 'F':
					SetValue(false);
					return true;
				default:
					return false;
			}
		}
		case float_:
		{
			float a = -91.91;
			in >> a;
			if (a != -91.91) {
				SetValue(a);
				return true;
			}
		}
		default:
			cout << "\n ArgSpecT::operator=: unknown value type" << endl;
			throw ExceptionT::kGeneralFail;
	}

	/* dummy */
	return false;
}