本文整理汇总了C++中Column::Alignment方法的典型用法代码示例。如果您正苦于以下问题:C++ Column::Alignment方法的具体用法?C++ Column::Alignment怎么用?C++ Column::Alignment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Column
的用法示例。
在下文中一共展示了Column::Alignment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetColumns
/**
* Sets the vector of Columns and writes out the first row of the file.
*
* @param cols A vector of Columns, setting the format of the table
*/
void WriteTabular::SetColumns(std::vector <Column> cols ){
for (unsigned int index=0; index < cols.size(); index++) {
Column thisCol = cols[index];
std::string thisTitle = thisCol.Name();
if (thisTitle.length() > thisCol.Width()) {
std::string message = "Column header [" + thisTitle + "] is wider " +
"than the set width for column [" + iString((int)index) + "]";
throw Isis::iException::Message(Isis::iException::User,message,_FILEINFO_);
}
int iteration = 0;
while (thisTitle.length() < thisCol.Width()) {
if (thisCol.Alignment() == Column::Left) {
thisTitle += " ";
}
else if (thisCol.Alignment() == Column::Right ||
thisCol.Alignment() == Column::Decimal) {
thisTitle = " " + thisTitle;
}
else {
std::string message = "Alignment is improperly set";
throw Isis::iException::Message(Isis::iException::User,message,_FILEINFO_);
}
iteration++;
}//end while
p_cols.push_back(thisCol);
p_outfile << thisTitle;
if (index < (cols.size()-1)) {
p_outfile << p_delimiter;
}
}//end for
p_outfile << "\n";
}//end function
示例2: Write
/**
* Add an integer value to the next column in this row
*
* @param item The integer value to put in this column.
*/
void WriteTabular::Write(int item){
Column thisCol = p_cols[p_curCol];
if (thisCol.DataType() != Column::Integer &&
thisCol.DataType() != Column::Pixel) {
if (thisCol.DataType() == Column::Real ||
thisCol.DataType() == Column::Pixel) {
Write((double)item);
return;
}
std::string message = "Wrong data type for this Column";
throw Isis::iException::Message(Isis::iException::User,message,_FILEINFO_);
}
iString thisItem(item);
if (thisItem.length() > thisCol.Width()) {
thisItem = "*";
while (thisItem.length() < thisCol.Width()) {
thisItem += "*";
}
}
std::stringstream tempStream;
tempStream.width(thisCol.Width());
tempStream.fill(' ');
if (thisCol.Alignment() == Column::Left) {
tempStream.setf(std::ios::left);
}
else tempStream.setf(std::ios::right);
tempStream << thisItem;
thisItem = tempStream.str();
if (p_curCol == 0) {
p_rows++;
}
if (p_curCol < (p_cols.size()-1)) {
thisItem += p_delimiter;
p_curCol++;
}
else {
thisItem += "\n";
p_curCol = 0;
}
p_outfile << thisItem.c_str();
}
示例3: Write
/**
* Writes a string to the next column in the current row
*
* @param item The string to write out
*/
void WriteTabular::Write(const char *itemCStr) {
Column thisCol = p_cols[p_curCol];
if(thisCol.DataType() != Column::String &&
thisCol.DataType() != Column::Pixel) {
QString message = "Wrong data type for this Column";
throw IException(IException::User, message, _FILEINFO_);
}
QString item(itemCStr);
if(item.length() > (int)thisCol.Width()) {
item = "*";
while(item.length() < (int)thisCol.Width()) {
item += "*";
}
}
stringstream tempStream;
tempStream.width(thisCol.Width());
tempStream.fill(' ');
if(thisCol.Alignment() == Column::Left) {
tempStream.setf(std::ios::left);
}
else tempStream.setf(std::ios::right);
tempStream << item;
item = tempStream.str().c_str();
if(p_curCol == 0) {
p_rows++;
}
if(p_curCol < (p_cols.size() - 1)) {
item += p_delimiter;
p_curCol++;
}
else {
item += "\n";
p_curCol = 0;
}
p_outfile << item;
}