📄 rttable.cpp
字号:
switch (argstring[J])
{
case 'r':
case 'R':
if ( (Number = (LNINT)atoi( &argstring[(J+1)] ) ) )
*Rows = Number;
break;
case 'c':
case 'C':
if ( (Number = (LNINT)atoi( &argstring[(J+1)] ) ) )
*Cols = Number;
break;
}
} // END for (J=0; J<Count; J++)
} // END for(I=2; I<argc; I++)
} // END if (argc < 2) ELSE
if (0 == (*Rows))
throw ("*** Error: number of rows must be greater than 0 ***");
if (0 == (*Cols))
throw ("*** Error: number of columns must be greater than 0 ***");
} // END ProcessArguments()
//---------------------------------------------------------------------------
//
// Name:
// InitDefaultParams
//
// Description:
// Set up all the default parameter strings and numbers for user
// input. Called by ProcessArguments() if no user input params
// were provided.
//
// NOTE:
// You only need to edit this funciton and ProcessArguments()
// when creating a new sample. The rest of the user interface
// functions below are called by ProcessArguments() and are
// generic, which means that they can stay the same unless
// you modify the number of parameters to use.
// Then you only need to modify the case statements in the functions below.
//---------------------------------------------------------------------------
void InitDefaultParams()
{
// Initialize default parameter strings.
PromptString1 = "File path name for the database to search : [";
ParamString1 = "rtxtsamp.nsf";
// Initialize default parameter numbers.
PromptNumber1 = "Number of rows in the new table : [";
ParamNumber1 = 3;
PromptNumber2 = "Number of columns in the new table : [";
ParamNumber2 = 5;
} // END InitDefaultParams()
//---------------------------------------------------------------------------
//
// Name:
// GetArguments
//
// Description:
// Allows the user to change any or all of the input parameter
// IOParameter. The inputs can also be left as they are if desired.
//---------------------------------------------------------------------------
void GetArguments()
{
BOOL IsCorrectData = FALSE;
QueryArguments();
while(! IsCorrectData)
{
PrintArguments();
cout << "Are these current data settings correct? : [Y] ";
cin >> CommandBuf;
switch( CommandBuf[0] )
{
case 'Y':
case 'y':
IsCorrectData = TRUE; // All done, get out now!
break;
default:
// Prompt again for anything other than a "Y" or carriage return.
if( (CommandBuf) != (const char *)"" )
QueryArguments();
else
IsCorrectData = TRUE; // All done, get out now!
} // END switch
} // END while
} // END GetArguments()
//---------------------------------------------------------------------------
//
// Name:
// PrintArguments
//
// Description:
// Prints out all of the current input parameters to use.
//---------------------------------------------------------------------------
void PrintArguments()
{
cout << endl;
cout << "The Current Default Data Settings are: " << endl;
cout << endl;
// Print out current parameter strings.
cout << PromptString1 << ParamString1 << "]" << endl;
// Print out current parameter numbers.
cout << PromptNumber1 << ParamNumber1 << "]" << endl;
cout << PromptNumber2 << ParamNumber2 << "]" << endl;
cout << endl;
} // END PrintArguments()
//---------------------------------------------------------------------------
//
// Name:
// QueryArguments
//
// Description:
// Queries the user to change any of the input parameters.
// A carriage return on any of the prompts leaves it alone.
//---------------------------------------------------------------------------
void QueryArguments()
{
cout << endl;
cout << "Enter the following parameters (Enter by itself takes the default):" << endl;
cout << endl;
// Prompt for strings.
cout << PromptString1 << ParamString1 << "]> ";
cin >> CommandBuf;
if( (CommandBuf) != (const char *)"" )
ParamString1 = CommandBuf;
// Prompt for numbers.
cout << PromptNumber1 << ParamNumber1 << "]> ";
cin >> CommandBuf;
if( (CommandBuf) != (const char *)"" )
ParamNumber1 = (LNINT)CommandBuf.StringToInteger();
cout << PromptNumber2 << ParamNumber2 << "]> ";
cin >> CommandBuf;
if( (CommandBuf) != (const char *)"" )
ParamNumber2 = (LNINT)CommandBuf.StringToInteger();
} // END QueryArguments()
//===========================================================================
//
// IOPARAMETER Class Implementation
//
// Description:
// Implementation for a simple generic string buffer class
// to hold user input and output prompts.
//===========================================================================
//===========================================================================
// Constructors
//===========================================================================
IOParameter::IOParameter() // Default constructor.
{
Size =1; // Null terminator.
if(! (BufferPointer = new char[Size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
BufferPointer[0] = '\0';
}
//===========================================================================
IOParameter::IOParameter( const char *Str ) // Init with const string.
{
Size = strlen(Str) + 1; // Size of string + null term.
if(! (BufferPointer = new char[Size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(BufferPointer, Str);
}
//===========================================================================
// Constructs a decimal radix string representation of an integer.
IOParameter::IOParameter( const int Number )
{
char Buffer[16]; // Temporary buffer for characters.
sprintf(Buffer, "%d", Number);
Size = strlen(Buffer) + 1; // Size of string + null term.
if(! (BufferPointer = new char[Size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(BufferPointer, Buffer);
}
//===========================================================================
IOParameter::IOParameter( const IOParameter &Other ) // Copy constructor.
{
Size = Other.Size;
if(! (BufferPointer = new char[Size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(BufferPointer, Other.BufferPointer);
}
//===========================================================================
// Constructor using 2 IOParameter objects as input.
IOParameter::IOParameter( const IOParameter& Prefix, const IOParameter& Postfix)
{
Size = Prefix.Size + Postfix.Size - 1;
if(! (BufferPointer = new char[Size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(BufferPointer, Prefix.BufferPointer);
strcat(BufferPointer, Postfix.BufferPointer);
}
//===========================================================================
// Subscript, etc.
//===========================================================================
char IOParameter::operator [] (int Index)
{
char Ch;
if (Index > Size)
Ch = '\0';
else
Ch = BufferPointer[Index];
return Ch;
}
//===========================================================================
// Assignment.
//===========================================================================
IOParameter IOParameter::operator = ( const IOParameter &Other )
{
if(BufferPointer)
delete [] BufferPointer;
Size = Other.Size;
if(! (BufferPointer = new char[Size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(BufferPointer, Other.BufferPointer);
return *this;
}
//===========================================================================
IOParameter IOParameter::operator = ( const char *Str )
{
Size = strlen(Str) +1;
if (BufferPointer)
delete [] BufferPointer;
if(! (BufferPointer = new char[Size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(BufferPointer, Str);
return *this;
}
//===========================================================================
// I/O operators.
//===========================================================================
ostream &operator << ( ostream &Stream, const IOParameter &Other )
{
Stream << Other.BufferPointer;
return Stream;
}
//===========================================================================
istream &operator >> ( istream &Stream, IOParameter &Other )
{
const int BufferLength = 255; // Arbitrary size, change if needed.
char Temp[BufferLength]; // temp string...
int Length;
for (Length=0; Length<BufferLength; Length++)
{
Stream.get(Temp[Length]);
if (Temp[Length] == '\n') // New line character
break;
if (Temp[Length] == '\b') // Backspace character
{
if(Length)
{
Length--;
}
}
}
Temp[Length] = '\0';
Length++;
if(Other.BufferPointer)
delete [] Other.BufferPointer;
if (! (Other.BufferPointer = new char[Length]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
Other.Size = Length;
strcpy(Other.BufferPointer, Temp);
return Stream;
} // END istream &operator >>
//===========================================================================
// Concatenate.
//===========================================================================
IOParameter IOParameter::operator + ( const IOParameter &Other ) // Cat 2 IOParameter objects.
{
return IOParameter( *this, Other );
}
//===========================================================================
IOParameter IOParameter::operator + ( const char *Str ) // Cat IOParameter and string.
{
return IOParameter( *this, IOParameter(Str) );
}
//===========================================================================
IOParameter operator + ( char *Str, const IOParameter &Other ) // Cat string with IOParameter.
{
return IOParameter( IOParameter(Str), Other );
}
//===========================================================================
IOParameter& IOParameter::operator << ( const IOParameter &Other ) // Cat 2 IOParameter objects.
{
IOParameter TempString(*this);
Size = TempString.Size + Other.Size - 1;
if (BufferPointer)
delete [] BufferPointer;
if(! (BufferPointer = new char[Size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(BufferPointer, TempString.BufferPointer);
strcat(BufferPointer, Other.BufferPointer);
return *this;
}
//===========================================================================
IOParameter& IOParameter::operator << ( const char *Str )
// Cat IOParameter and string.
{
IOParameter TempString(*this);
IOParameter Other(Str);
Size = TempString.Size + Other.Size - 1;
if (BufferPointer)
delete [] BufferPointer;
if(! (BufferPointer = new char[Size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(BufferPointer, TempString.BufferPointer);
strcat(BufferPointer, Other.BufferPointer);
return *this;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -