CifFile.h (pymol-v1.8.6.0.tar.bz2) | : | CifFile.h (pymol-v2.1.0.tar.bz2) | ||
---|---|---|---|---|
skipping to change at line 12 | skipping to change at line 12 | |||
* CIF tokenizer | * CIF tokenizer | |||
* | * | |||
* (c) 2014 Schrodinger, Inc. | * (c) 2014 Schrodinger, Inc. | |||
*/ | */ | |||
#ifndef _H_CIFFILE | #ifndef _H_CIFFILE | |||
#define _H_CIFFILE | #define _H_CIFFILE | |||
#include <vector> | #include <vector> | |||
#include <map> | #include <map> | |||
#include <stdexcept> | ||||
#include <string.h> | #include <string.h> | |||
#ifdef WIN32 | ||||
#define strcasecmp(s1, s2) _stricmp(s1, s2) | ||||
#define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n) | ||||
#endif | ||||
/* | /* | |||
* C string comparison class | * C string comparison class | |||
*/ | */ | |||
struct strless2_t { | struct strless2_t { | |||
bool operator()(const char * a, const char * b) const { | bool operator()(const char * a, const char * b) const { | |||
return strcmp(a, b) < 0; | return strcmp(a, b) < 0; | |||
} | } | |||
}; | }; | |||
// cif data types | // cif data types | |||
skipping to change at line 63 | skipping to change at line 57 | |||
private: | private: | |||
char * contents; | char * contents; | |||
std::vector<char*> tokens; | std::vector<char*> tokens; | |||
// methods | // methods | |||
bool parse(); | bool parse(); | |||
}; | }; | |||
/* | /* | |||
* Class to store CIF loops. Only for parsing, do not use in any higher level | ||||
* reading functions. | ||||
*/ | ||||
class cif_loop { | ||||
public: | ||||
int ncols; | ||||
int nrows; | ||||
const char **values; | ||||
// methods | ||||
const char * get_value_raw(int row, int col) const; | ||||
}; | ||||
/* | ||||
* High-level access to CIF arrays | * High-level access to CIF arrays | |||
*/ | */ | |||
class cif_array { | class cif_array { | |||
friend class cif_file; | ||||
private: | private: | |||
// column index, -1 if not in loop | // column index, -1 if not in loop | |||
short col; | short col; | |||
// pointer to either loop or single value | // pointer to either loop or single value | |||
union { | union { | |||
const cif_loop * loop; | const cif_loop * loop; | |||
const char * value; | const char * value; | |||
} pointer; | } pointer; | |||
// methods | // methods | |||
const char * get_value_raw(int row = 0) const; | ||||
const char * get_value(int row = 0) const; | const char * get_value(int row = 0) const; | |||
public: | ||||
// point this array to a loop (only for parsing) | // point this array to a loop (only for parsing) | |||
void set_loop(const cif_loop * loop, short col_) { | void set_loop(const cif_loop * loop, short col_) { | |||
col = col_; | col = col_; | |||
pointer.loop = loop; | pointer.loop = loop; | |||
}; | }; | |||
// point this array to a single value (only for parsing) | // point this array to a single value (only for parsing) | |||
void set_value(const char * value) { | void set_value(const char * value) { | |||
col = -1; | col = -1; | |||
pointer.value = value; | pointer.value = value; | |||
}; | }; | |||
public: | ||||
// constructor | // constructor | |||
cif_array() { | cif_array() { | |||
}; | }; | |||
// constructor (only needed for EMPTY_ARRAY) | // constructor (only needed for EMPTY_ARRAY) | |||
cif_array(const char * value) { | cif_array(const char * value) { | |||
set_value(value); | set_value(value); | |||
}; | }; | |||
// get the number of elements in this array | // get the number of elements in this array | |||
int get_nrows() const { | int get_nrows() const; | |||
return (col < 0) ? 1 : pointer.loop->nrows; | ||||
}; | ||||
// get element as string, integer or double. If index is out of bounds, | // get element as string, integer or double. If index is out of bounds, | |||
// then return a default value. | // then return a default value. | |||
const char * as_s(int row = 0) const; | const char * as_s(int row = 0) const; | |||
int as_i(int row = 0, int d = 0) const; | int as_i(int row = 0, int d = 0) const; | |||
double as_d(int row = 0, double d = 0.0) const; | double as_d(int row = 0, double d = 0.0) const; | |||
// true if value in ['.', '?'] | // true if value in ['.', '?'] | |||
bool is_missing(int row = 0) const { | bool is_missing(int row = 0) const { | |||
return !get_value(row); | return !get_value(row); | |||
} | } | |||
// true if all values in ['.', '?'] | ||||
bool is_missing_all() const; | ||||
// templated getter | // templated getter | |||
template <typename T> T as(int row = 0) const; | template <typename T> T as(int row = 0) const; | |||
// get a copy of the entire array | // get a copy of the entire array | |||
template <typename T> std::vector<T> to_vector() const { | template <typename T> std::vector<T> to_vector() const { | |||
int n = get_nrows(); | int n = get_nrows(); | |||
std::vector<T> v; | std::vector<T> v; | |||
v.reserve(n); | v.reserve(n); | |||
for (int i = 0; i < n; ++i) | for (int i = 0; i < n; ++i) | |||
v.push_back(as<T>(i)); | v.push_back(as<T>(i)); | |||
End of changes. 9 change blocks. | ||||
25 lines changed or deleted | 7 lines changed or added |