Xmipp  v3.23.11-Nereus
Public Types | Public Member Functions | Friends | List of all members

#include <docfile.h>

Public Types

enum  Line_Type { NOT_CONSIDERED = -1, NOT_ASSIGNED = 0, DATALINE = 1, COMMENT = 2 }
 

Public Member Functions

void read (std::istream &i)
 
Constructors for Document Lines
 DocLine ()
 
Component access
double & operator[] (size_t i)
 
double operator[] (size_t i) const
 
void set (size_t i, double val)
 
void set (const Matrix1D< double > &v)
 
Structure information
std::string get_text ()
 
int get_key () const
 
int get_no_components () const
 
void clear ()
 
int Is_comment ()
 
int Is_data ()
 
void set_type (Line_Type _line_type)
 

Friends

class DocFile
 Document file can access anything in this class. More...
 
std::ostream & operator<< (std::ostream &o, const DocLine &DL)
 

Detailed Description

DocFile Line.

The Document file is a collection (STL list) of Document lines. This class needn't be accessed in common programs since the DocFile class offers most of the used functions. However, the class is shown in case you may need to access specifically to any of the Document Line functions alone. The DocLines can be either comments or data line, they might be of other internal used types (not assigned or to be discarded), but you may assume that if a line is not a comment nor a data line then it can be skipped.

Definition at line 54 of file docfile.h.

Member Enumeration Documentation

◆ Line_Type

Enumerator
NOT_CONSIDERED 
NOT_ASSIGNED 
DATALINE 
COMMENT 

Definition at line 57 of file docfile.h.

Constructor & Destructor Documentation

◆ DocLine()

DocLine::DocLine ( )
inline

Empty Constructor.

The document line is created with no type (neither comment or data). You must use the function set_type to assign a type

Definition at line 82 of file docfile.h.

82  : line_type(NOT_ASSIGNED)
83  {}

Member Function Documentation

◆ clear()

void DocLine::clear ( )

Empty the document line.

Definition at line 87 of file docfile.cpp.

88 {
89  line_type = NOT_ASSIGNED;
90  text = "";
91  key = 0;
92  data.clear();
93 }

◆ get_key()

int DocLine::get_key ( ) const
inline

Get the key of this line.

Definition at line 142 of file docfile.h.

143  {
144  return key;
145  }

◆ get_no_components()

int DocLine::get_no_components ( ) const
inline

Get the number of components.

If it is a comment or it hasn't been assigned it returns -1

Definition at line 151 of file docfile.h.

152  {
153  if (line_type == DATALINE)
154  return data.size();
155  else
156  return -1;
157  }

◆ get_text()

std::string DocLine::get_text ( )
inline

Get text of this line.

The text is only valid for comment lines

Definition at line 135 of file docfile.h.

136  {
137  return text;
138  }

◆ Is_comment()

int DocLine::Is_comment ( )
inline

True if current line is a comment.

Definition at line 165 of file docfile.h.

166  {
167  return line_type == COMMENT;
168  }

◆ Is_data()

int DocLine::Is_data ( )
inline

True if current line is a comment.

Definition at line 172 of file docfile.h.

173  {
174  return line_type == DATALINE;
175  }

◆ operator[]() [1/2]

double & DocLine::operator[] ( size_t  i)

Set existing components.

Inside the document line the values are considered as an array (with starting index at 0). With this function you can set any EXISTING position inside the document line. If the position has not been created yet (ie, the vector is smaller) then an exception is thrown.

line[3] = 3; // line[3] must exist!!

This function is ignored in the python wrapper. Use "set" instead.

Definition at line 34 of file docfile.cpp.

35 {
36  if (i+1 > data.size())
37  {
38  std::cout << "Docline=" << *this << std::endl;
39  REPORT_ERROR(ERR_DOCFILE, "Trying to access to non-existing element " +
40  integerToString(i) + " of a document line");
41  }
42 
43  return data[i];
44 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
String integerToString(int I, int _width, char fill_with)
#define i
Error in docfile format.
Definition: xmipp_error.h:122

◆ operator[]() [2/2]

double DocLine::operator[] ( size_t  i) const

Constant component access.

The same as the previous function

This function is renamed as "get" in the python wrapper.

Definition at line 46 of file docfile.cpp.

47 {
48  if (i+1 > data.size())
49  {
50  std::cout << "Docline=" << *this << std::endl;
51  REPORT_ERROR(ERR_DOCFILE, "Trying to access to non-existing element " +
52  integerToString(i) + " of a document line");
53  }
54 
55  return data[i];
56 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
String integerToString(int I, int _width, char fill_with)
#define i
Error in docfile format.
Definition: xmipp_error.h:122

◆ read()

void DocLine::read ( std::istream &  i)

Read a Document Line. An exception is thrown if the line doesn't meet the Document File specifications. First the line is read in a C way, if it fails then the exact Fortran output is tried.

Definition at line 129 of file docfile.cpp.

130 {
131  std::string line;
132  int param_no;
133 
134  // Get line
135  getline(in, line);
136 
137  // Initialize target
138  line_type = DocLine::NOT_ASSIGNED;
139  text = "";
140  key = 0;
141  data.clear();
142 
143  // Check if comment or empty line
144  int charpos1 = line.find_first_not_of(" \t");
145  if (line[0] == '\0' || line[charpos1] == '#' || line[charpos1] == ';')
146  {
147  line_type = DocLine::COMMENT;
148  text = line;
149  data.clear();
150  key = 0;
151  }
152  // Read a true document file line
153  else
154  {
155  line_type = DocLine::DATALINE;
156  text = "";
157  size_t i = 0;
158 
159  key = textToInteger(nextToken(line, i));
160  param_no = textToInteger(nextToken(line, i));
161  std::string auxline = line;
162 
163  try
164  {
165  // Try unfixed mode first
166  readFloatList(line, i, param_no, data);
167  }
168  catch (XmippError &e)
169  {
170  // Try fixed mode then
171  data.clear();
172  data.reserve(param_no);
173  for (int i = 0; i < param_no; i++)
174  {
175  data.push_back(textToFloat(line.substr(8 + i*12, 12)));
176  }
177  }
178  }
179 }
void readFloatList(const char *str, int N, std::vector< T > &v)
Definition: args.h:104
#define i
int in
float textToFloat(const char *str)
int textToInteger(const char *str)
String nextToken(const String &str, size_t &i)

◆ set() [1/2]

void DocLine::set ( size_t  i,
double  val 
)

Set an existing or not component.

If the Document Line is not large enough to hold the required component, then it is resized

Definition at line 58 of file docfile.cpp.

59 {
60  // Make sure there is enough memory
61  if (i + 1 > data.size())
62  data.reserve(i + 1);
63 
64  // Pad with zeros for the non-existing indexes in between
65  int space_needed = i + 1 - data.size();
66  for (int k = 0; k < space_needed; k++)
67  data.push_back(0);
68 
69  // Set required data
70  data[i] = val;
71 }
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac

◆ set() [2/2]

void DocLine::set ( const Matrix1D< double > &  v)

Set a vector (Matrix1D) as Document line.

It doesn't matter if it is a row or a column vector. The previous data is overwritten and the key is kept. If it was not a data line, then the new key=0.

Definition at line 73 of file docfile.cpp.

74 {
75  data.clear();
76  if (line_type != DATALINE)
77  {
78  line_type = DATALINE;
79  key = 0;
80  }
81 
82  data.reserve(VEC_XSIZE(v));
84  data.push_back(VEC_ELEM(v, i));
85 }
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
#define i
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
Definition: matrix1d.h:72

◆ set_type()

void DocLine::set_type ( Line_Type  _line_type)
inline

Set type.

Only the comment flag is set, the key and possible data are not lost. The comment text is not touched. The valid types are DATALINE, COMMENT, NOT_ASSIGNED, and NOT_CONSIDERED.

Definition at line 183 of file docfile.h.

184  {
185  line_type = _line_type;
186  }

Friends And Related Function Documentation

◆ DocFile

friend class DocFile
friend

Document file can access anything in this class.

Definition at line 71 of file docfile.h.

◆ operator<<

std::ostream& operator<< ( std::ostream &  o,
const DocLine DL 
)
friend

Show a Document Line.

Definition at line 95 of file docfile.cpp.

96 {
97  char aux[30];
98  switch (line.line_type)
99  {
100  case DocLine::DATALINE:
101  // Print a data line
102  sprintf(aux, "%5d ", line.key);
103  o << aux;
104  sprintf(aux, "%-2lu", (unsigned long int)(line.data.size()));
105  o << aux;
106 
107  int imax;
108  imax = line.data.size();
109  for (int i = 0; i < imax; i++)
110 {
111  sprintf(aux, " % 10.5f", line.data[i]);
112  o << aux;
113  }
114 
115  o << std::endl;
116  break;
117 
118  case DocLine::COMMENT:
119  // Print a comment
120  o << line.text << std::endl;
121  break;
122  default:
123  break;
124  }
125 
126  return o;
127 }
#define i

The documentation for this class was generated from the following files: