Commit 81c0d019 by Maarten L. Hekkelman

Cleaning up all warnings in MSVC

parent 1d2f997e
...@@ -8,3 +8,4 @@ test/pdb2cif-test ...@@ -8,3 +8,4 @@ test/pdb2cif-test
test/rename-compound-test test/rename-compound-test
tools/update-dictionary-script tools/update-dictionary-script
data/ data/
CMakeSettings.json
...@@ -15,10 +15,6 @@ include(CMakePackageConfigHelpers) ...@@ -15,10 +15,6 @@ include(CMakePackageConfigHelpers)
include(Dart) include(Dart)
include(GenerateExportHeader) include(GenerateExportHeader)
set(PACKAGE ${PROJECT_NAME})
set(PACKAGE_VERSION ${PROJECT_VERSION})
add_definitions(-DVERSION=${PACKAGE_VERSION})
set(CXX_EXTENSIONS OFF) set(CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
...@@ -31,6 +27,9 @@ if(MSVC) ...@@ -31,6 +27,9 @@ if(MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
endif() endif()
# Build shared libraries by default (not my cup of tea, but hey)
option(BUILD_SHARED_LIBS "Build a shared library instead of a static one" ON)
set(CMAKE_DEBUG_POSTFIX d) set(CMAKE_DEBUG_POSTFIX d)
if(MSVC) if(MSVC)
...@@ -163,18 +162,15 @@ include_directories( ...@@ -163,18 +162,15 @@ include_directories(
${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src
) )
add_library(cifpp SHARED ${project_sources} ${project_headers}) add_library(cifpp ${project_sources} ${project_headers})
set_target_properties(cifpp PROPERTIES set_target_properties(cifpp PROPERTIES
SOVERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION}
INTERFACE_cifpp_MAJOR_VERSION cifpp_MAJOR_VERSION INTERFACE_cifpp_MAJOR_VERSION cifpp_MAJOR_VERSION
COMPATIBLE_INTERFACE_STRING cifpp_MAJOR_VERSION COMPATIBLE_INTERFACE_STRING cifpp_MAJOR_VERSION
) )
add_library(cifpp_static STATIC ${project_sources} ${project_headers})
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
target_link_options(cifpp PRIVATE -undefined dynamic_lookup) target_link_options(cifpp PRIVATE -undefined dynamic_lookup)
target_link_options(cifpp_static PRIVATE -undefined dynamic_lookup)
endif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") endif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
# download the components.cif file from CCD # download the components.cif file from CCD
...@@ -212,13 +208,23 @@ add_custom_target(COMPONENTS ALL DEPENDS ${COMPONENTS_CIF}) ...@@ -212,13 +208,23 @@ add_custom_target(COMPONENTS ALL DEPENDS ${COMPONENTS_CIF})
include_directories(${Boost_INCLUDE_DIRS}) include_directories(${Boost_INCLUDE_DIRS})
link_libraries(${Boost_LIBRARIES}) link_libraries(${Boost_LIBRARIES})
add_compile_definitions(CACHE_DIR="${SHARE_INSTALL_DIR}/libcifpp" DATA_DIR="${SHARE_INSTALL_DIR}/libcifpp" )
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR} )
set(LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} )
set(SHARE_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/libcifpp)
set(ConfigPackageLocation lib/cmake/cifpp)
# Fix cache dir
add_compile_definitions(
# CACHE_DIR="${CMAKE_INSTALL_PREFIX}/${SHARE_INSTALL_DIR}"
DATA_DIR="${CMAKE_INSTALL_PREFIX}/${SHARE_INSTALL_DIR}" )
generate_export_header(cifpp) generate_export_header(cifpp)
# Install rules # Install rules
install(TARGETS cifpp cifpp_static install(TARGETS cifpp
EXPORT cifppTargets EXPORT cifppTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
...@@ -241,15 +247,9 @@ install(FILES ...@@ -241,15 +247,9 @@ install(FILES
${PROJECT_SOURCE_DIR}/rsrc/mmcif_ddl.dic ${PROJECT_SOURCE_DIR}/rsrc/mmcif_ddl.dic
${PROJECT_SOURCE_DIR}/rsrc/mmcif_pdbx_v50.dic ${PROJECT_SOURCE_DIR}/rsrc/mmcif_pdbx_v50.dic
${PROJECT_SOURCE_DIR}/data/components.cif ${PROJECT_SOURCE_DIR}/data/components.cif
DESTINATION ${CMAKE_INSTALL_DATADIR} DESTINATION ${SHARE_INSTALL_DIR}
) )
set(INCLUDE_INSTALL_DIR include )
set(LIBRARY_INSTALL_DIR lib )
set(SHARE_INSTALL_DIR share/libcifpp)
set(ConfigPackageLocation lib/cmake/cifpp)
configure_package_config_file(cmake/cifppConfig.cmake.in configure_package_config_file(cmake/cifppConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cifpp/cifppConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/cifpp/cifppConfig.cmake
INSTALL_DESTINATION ${ConfigPackageLocation} INSTALL_DESTINATION ${ConfigPackageLocation}
...@@ -310,7 +310,7 @@ if(CIFPP_BUILD_TESTS) ...@@ -310,7 +310,7 @@ if(CIFPP_BUILD_TESTS)
${CMAKE_CURRENT_BINARY_DIR} # for config.h ${CMAKE_CURRENT_BINARY_DIR} # for config.h
) )
target_link_libraries(${CIFPP_TEST} cifpp_static Threads::Threads ${Boost_LIBRARIES}) target_link_libraries(${CIFPP_TEST} $<TARGET_OBJECTS:cifpp> Threads::Threads ${Boost_LIBRARIES})
if(${ZLIB_FOUND}) if(${ZLIB_FOUND})
target_link_libraries(${CIFPP_TEST} ZLIB::ZLIB) target_link_libraries(${CIFPP_TEST} ZLIB::ZLIB)
...@@ -329,8 +329,8 @@ if(CIFPP_BUILD_TESTS) ...@@ -329,8 +329,8 @@ if(CIFPP_BUILD_TESTS)
add_custom_command( add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Run${CIFPP_TEST}.touch OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Run${CIFPP_TEST}.touch
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${CIFPP_TEST} COMMAND $<TARGET_FILE:${CIFPP_TEST}>
) WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test)
add_test(NAME ${CIFPP_TEST} add_test(NAME ${CIFPP_TEST}
COMMAND $<TARGET_FILE:${CIFPP_TEST}> COMMAND $<TARGET_FILE:${CIFPP_TEST}>
...@@ -338,5 +338,3 @@ if(CIFPP_BUILD_TESTS) ...@@ -338,5 +338,3 @@ if(CIFPP_BUILD_TESTS)
endforeach() endforeach()
endif() endif()
...@@ -1961,7 +1961,7 @@ class Category ...@@ -1961,7 +1961,7 @@ class Category
void write(std::ostream& os); void write(std::ostream& os);
void write(std::ostream& os, const std::vector<std::string>& order); void write(std::ostream& os, const std::vector<std::string>& order);
void write(std::ostream& os, const std::vector<int>& order, bool includeEmptyColumns); void write(std::ostream& os, const std::vector<size_t>& order, bool includeEmptyColumns);
size_t addColumn(const std::string& name); size_t addColumn(const std::string& name);
......
...@@ -47,6 +47,16 @@ ...@@ -47,6 +47,16 @@
#include "cifpp_export.h" #include "cifpp_export.h"
#if _MSC_VER
# pragma warning (disable : 4355) // this is used in Base Initializer list
# pragma warning (disable : 4996) // unsafe function or variable
# pragma warning (disable : 4068) // unknown pragma
# pragma warning (disable : 4996) // stl copy()
# pragma warning (disable : 4800) // BOOL conversion
# pragma warning (disable : 4100) // unreferenced formal parameter
# pragma warning (disable : 4101) // unreferenced local variable
#endif
namespace cif namespace cif
{ {
...@@ -85,7 +95,7 @@ typedef std::set<std::string, iless> iset; ...@@ -85,7 +95,7 @@ typedef std::set<std::string, iless> iset;
extern const uint8_t kCharToLowerMap[256]; extern const uint8_t kCharToLowerMap[256];
inline char tolower(char ch) inline char tolower(int ch)
{ {
return static_cast<char>(kCharToLowerMap[static_cast<uint8_t>(ch)]); return static_cast<char>(kCharToLowerMap[static_cast<uint8_t>(ch)]);
} }
...@@ -102,7 +112,7 @@ std::string cifIdForNumber(int number); ...@@ -102,7 +112,7 @@ std::string cifIdForNumber(int number);
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// custom wordwrapping routine // custom wordwrapping routine
std::vector<std::string> wordWrap(const std::string& text, unsigned int width); std::vector<std::string> wordWrap(const std::string& text, size_t width);
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Code helping with terminal i/o // Code helping with terminal i/o
......
...@@ -32,22 +32,23 @@ ...@@ -32,22 +32,23 @@
struct PDBRecord struct PDBRecord
{ {
PDBRecord* mNext; PDBRecord *mNext;
uint32_t mLineNr; uint32_t mLineNr;
char mName[11]; char mName[11];
size_t mVlen; size_t mVlen;
char mValue[0]; char mValue[1];
PDBRecord(uint32_t lineNr, const std::string& name, const std::string& value); PDBRecord(uint32_t lineNr, const std::string &name, const std::string &value);
~PDBRecord(); ~PDBRecord();
void* operator new(size_t); void *operator new(size_t);
void* operator new(size_t size, size_t vLen); void *operator new(size_t size, size_t vLen);
void operator delete(void* p); void operator delete(void *p);
void operator delete(void *p, size_t vLen);
bool is(const char* name) const;
bool is(const char *name) const;
char vC(size_t column); char vC(size_t column);
std::string vS(size_t columnFirst, size_t columnLast = std::numeric_limits<size_t>::max()); std::string vS(size_t columnFirst, size_t columnLast = std::numeric_limits<size_t>::max());
int vI(int columnFirst, int columnLast); int vI(int columnFirst, int columnLast);
...@@ -56,4 +57,4 @@ struct PDBRecord ...@@ -56,4 +57,4 @@ struct PDBRecord
// -------------------------------------------------------------------- // --------------------------------------------------------------------
void ReadPDBFile(std::istream& pdbFile, cif::File& cifFile); void ReadPDBFile(std::istream &pdbFile, cif::File &cifFile);
...@@ -39,8 +39,8 @@ namespace mmcif ...@@ -39,8 +39,8 @@ namespace mmcif
typedef boost::math::quaternion<float> quaternion; typedef boost::math::quaternion<float> quaternion;
const long double const double
kPI = 3.141592653589793238462643383279502884L; kPI = 3.141592653589793238462643383279502884;
// -------------------------------------------------------------------- // --------------------------------------------------------------------
......
...@@ -289,7 +289,7 @@ class CompoundBondMap ...@@ -289,7 +289,7 @@ class CompoundBondMap
auto i = mAtomIDIndex.find(id); auto i = mAtomIDIndex.find(id);
if (i == mAtomIDIndex.end()) if (i == mAtomIDIndex.end())
{ {
result = mAtomIDIndex.size(); result = uint32_t(mAtomIDIndex.size());
mAtomIDIndex[id] = result; mAtomIDIndex[id] = result;
} }
else else
...@@ -354,15 +354,12 @@ BondMap::BondMap(const Structure& p) ...@@ -354,15 +354,12 @@ BondMap::BondMap(const Structure& p)
auto& compoundBondInfo = CompoundBondMap::instance(); auto& compoundBondInfo = CompoundBondMap::instance();
auto atoms = p.atoms(); auto atoms = p.atoms();
dim = atoms.size(); dim = uint32_t(atoms.size());
// bond = std::vector<bool>(dim * (dim - 1), false); // bond = std::vector<bool>(dim * (dim - 1), false);
for (auto& atom: atoms) for (auto& atom: atoms)
{ index[atom.id()] = uint32_t(index.size());
size_t ix = index.size();
index[atom.id()] = ix;
};
auto bindAtoms = [this](const std::string& a, const std::string& b) auto bindAtoms = [this](const std::string& a, const std::string& b)
{ {
......
...@@ -68,7 +68,7 @@ struct ItemValue ...@@ -68,7 +68,7 @@ struct ItemValue
uint32_t mColumnIndex; uint32_t mColumnIndex;
char mText[4]; char mText[4];
ItemValue(const char* v, uint32_t columnIndex); ItemValue(const char* v, size_t columnIndex);
~ItemValue(); ~ItemValue();
bool empty() const { return mText[0] == 0 or ((mText[0] == '.' or mText[0] == '?') and mText[1] == 0); } bool empty() const { return mText[0] == 0 or ((mText[0] == '.' or mText[0] == '?') and mText[1] == 0); }
...@@ -77,13 +77,15 @@ struct ItemValue ...@@ -77,13 +77,15 @@ struct ItemValue
void* operator new(size_t size, size_t dataSize); void* operator new(size_t size, size_t dataSize);
void operator delete(void* p); void operator delete(void* p);
void operator delete(void* p, size_t dataSize);
}; };
// -------------------------------------------------------------------- // --------------------------------------------------------------------
ItemValue::ItemValue(const char* value, uint32_t columnIndex) ItemValue::ItemValue(const char* value, size_t columnIndex)
: mNext(nullptr), mColumnIndex(columnIndex) : mNext(nullptr), mColumnIndex(uint32_t(columnIndex))
{ {
assert(columnIndex < std::numeric_limits<uint32_t>::max());
strcpy(mText, value); strcpy(mText, value);
} }
...@@ -109,6 +111,11 @@ void ItemValue::operator delete(void* p) ...@@ -109,6 +111,11 @@ void ItemValue::operator delete(void* p)
free(p); free(p);
} }
void ItemValue::operator delete(void* p, size_t dataSize)
{
free(p);
}
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// itemColumn contains info about a column or field in a Category // itemColumn contains info about a column or field in a Category
...@@ -124,8 +131,8 @@ struct ItemRow ...@@ -124,8 +131,8 @@ struct ItemRow
{ {
~ItemRow(); ~ItemRow();
void drop(uint32_t columnIx); void drop(size_t columnIx);
const char* c_str(uint32_t columnIx) const; const char* c_str(size_t columnIx) const;
std::string str() const std::string str() const
{ {
...@@ -181,7 +188,7 @@ ItemRow::~ItemRow() ...@@ -181,7 +188,7 @@ ItemRow::~ItemRow()
delete mValues; delete mValues;
} }
void ItemRow::drop(uint32_t columnIx) void ItemRow::drop(size_t columnIx)
{ {
if (mValues != nullptr and mValues->mColumnIndex == columnIx) if (mValues != nullptr and mValues->mColumnIndex == columnIx)
{ {
...@@ -212,7 +219,7 @@ void ItemRow::drop(uint32_t columnIx) ...@@ -212,7 +219,7 @@ void ItemRow::drop(uint32_t columnIx)
#endif #endif
} }
const char* ItemRow::c_str(uint32_t columnIx) const const char* ItemRow::c_str(size_t columnIx) const
{ {
const char* result = kEmptyResult; const char* result = kEmptyResult;
...@@ -1393,11 +1400,11 @@ std::string Category::getUniqueID(std::function<std::string(int)> generator) ...@@ -1393,11 +1400,11 @@ std::string Category::getUniqueID(std::function<std::string(int)> generator)
if (mCatValidator != nullptr and mCatValidator->mKeys.size() == 1) if (mCatValidator != nullptr and mCatValidator->mKeys.size() == 1)
key = mCatValidator->mKeys.front(); key = mCatValidator->mKeys.front();
int nr = size() + 1; size_t nr = size() + 1;
for (;;) for (;;)
{ {
std::string result = generator(nr++); std::string result = generator(int(nr++));
if (exists(Key(key) == result)) if (exists(Key(key) == result))
continue; continue;
...@@ -1429,7 +1436,7 @@ void Category::drop(const std::string& field) ...@@ -1429,7 +1436,7 @@ void Category::drop(const std::string& field)
if (ci != mColumns.end()) if (ci != mColumns.end())
{ {
uint32_t columnIx = ci - mColumns.begin(); size_t columnIx = ci - mColumns.begin();
for (auto pi = mHead; pi != nullptr; pi = pi->mNext) for (auto pi = mHead; pi != nullptr; pi = pi->mNext)
pi->drop(columnIx); pi->drop(columnIx);
...@@ -2299,7 +2306,7 @@ size_t writeValue(std::ostream& os, std::string value, size_t offset, size_t wid ...@@ -2299,7 +2306,7 @@ size_t writeValue(std::ostream& os, std::string value, size_t offset, size_t wid
} }
void Category::write(std::ostream& os, const std::vector<int>& order, bool includeEmptyColumns) void Category::write(std::ostream& os, const std::vector<size_t>& order, bool includeEmptyColumns)
{ {
if (empty()) if (empty())
return; return;
...@@ -2437,7 +2444,7 @@ void Category::write(std::ostream& os, const std::vector<int>& order, bool inclu ...@@ -2437,7 +2444,7 @@ void Category::write(std::ostream& os, const std::vector<int>& order, bool inclu
void Category::write(std::ostream& os) void Category::write(std::ostream& os)
{ {
std::vector<int> order(mColumns.size()); std::vector<size_t> order(mColumns.size());
iota(order.begin(), order.end(), 0); iota(order.begin(), order.end(), 0);
write(os, order, false); write(os, order, false);
} }
...@@ -2448,7 +2455,7 @@ void Category::write(std::ostream& os, const std::vector<std::string>& columns) ...@@ -2448,7 +2455,7 @@ void Category::write(std::ostream& os, const std::vector<std::string>& columns)
for (auto& c: columns) for (auto& c: columns)
addColumn(c); addColumn(c);
std::vector<int> order; std::vector<size_t> order;
order.reserve(mColumns.size()); order.reserve(mColumns.size());
for (auto& c: columns) for (auto& c: columns)
...@@ -2541,7 +2548,7 @@ void Category::update_value(RowSet &&rows, const std::string &tag, const std::st ...@@ -2541,7 +2548,7 @@ void Category::update_value(RowSet &&rows, const std::string &tag, const std::st
for (auto child: children) for (auto child: children)
{ {
Condition cond; Condition cond_c;
for (size_t ix = 0; ix < linked->mParentKeys.size(); ++ix) for (size_t ix = 0; ix < linked->mParentKeys.size(); ++ix)
{ {
...@@ -2550,10 +2557,10 @@ void Category::update_value(RowSet &&rows, const std::string &tag, const std::st ...@@ -2550,10 +2557,10 @@ void Category::update_value(RowSet &&rows, const std::string &tag, const std::st
// TODO add code to *NOT* test mandatory fields for Empty // TODO add code to *NOT* test mandatory fields for Empty
cond = std::move(cond) && Key(pk) == child[ck].c_str(); cond_c = std::move(cond_c) && Key(pk) == child[ck].c_str();
} }
auto parents = find(std::move(cond)); auto parents = find(std::move(cond_c));
if (parents.empty()) if (parents.empty())
{ {
process.push_back(child); process.push_back(child);
...@@ -2646,7 +2653,7 @@ void Row::assign(const std::vector<Item>& values) ...@@ -2646,7 +2653,7 @@ void Row::assign(const std::vector<Item>& values)
{ {
auto cat = mData->mCategory; auto cat = mData->mCategory;
std::map<std::string,std::tuple<int,std::string,std::string>> changed; std::map<std::string,std::tuple<size_t,std::string,std::string>> changed;
for (auto& value: values) for (auto& value: values)
{ {
...@@ -2844,11 +2851,11 @@ void Row::assign(size_t column, const std::string& value, bool skipUpdateLinked) ...@@ -2844,11 +2851,11 @@ void Row::assign(size_t column, const std::string& value, bool skipUpdateLinked)
} }
else else
{ {
const char* value = (*this)[pk].c_str(); const char* pk_value = (*this)[pk].c_str();
if (*value == 0) if (*pk_value == 0)
cond = std::move(cond) && Key(ck) == Empty(); cond = std::move(cond) && Key(ck) == Empty();
else else
cond = std::move(cond) && ((Key(ck) == value) or Key(ck) == Empty()); cond = std::move(cond) && ((Key(ck) == pk_value) or Key(ck) == Empty());
} }
} }
...@@ -2878,11 +2885,11 @@ void Row::assign(size_t column, const std::string& value, bool skipUpdateLinked) ...@@ -2878,11 +2885,11 @@ void Row::assign(size_t column, const std::string& value, bool skipUpdateLinked)
cond_n = std::move(cond_n) && Key(ck) == value; cond_n = std::move(cond_n) && Key(ck) == value;
else else
{ {
const char* value = (*this)[pk].c_str(); const char* pk_value = (*this)[pk].c_str();
if (*value == 0) if (*pk_value == 0)
cond_n = std::move(cond_n) && Key(ck) == Empty(); cond_n = std::move(cond_n) && Key(ck) == Empty();
else else
cond_n = std::move(cond_n) && ((Key(ck) == value) or Key(ck) == Empty()); cond_n = std::move(cond_n) && ((Key(ck) == pk_value) or Key(ck) == Empty());
} }
} }
......
...@@ -232,7 +232,7 @@ std::vector<std::string> MapAsymIDs2ChainIDs(const std::vector<std::string>& asy ...@@ -232,7 +232,7 @@ std::vector<std::string> MapAsymIDs2ChainIDs(const std::vector<std::string>& asy
} }
// support for wrapping text using a 'continuation marker' // support for wrapping text using a 'continuation marker'
int WriteContinuedLine(std::ostream& pdbFile, std::string header, int& count, int cLen, std::string text, int lStart = 0) size_t WriteContinuedLine(std::ostream& pdbFile, std::string header, int& count, int cLen, std::string text, std::string::size_type lStart = 0)
{ {
if (lStart == 0) if (lStart == 0)
{ {
...@@ -242,7 +242,7 @@ int WriteContinuedLine(std::ostream& pdbFile, std::string header, int& count, in ...@@ -242,7 +242,7 @@ int WriteContinuedLine(std::ostream& pdbFile, std::string header, int& count, in
lStart = header.length() + cLen; lStart = header.length() + cLen;
} }
int maxLength = 80 - lStart - 1; std::string::size_type maxLength = 80 - lStart - 1;
std::vector<std::string> lines = cif::wordWrap(text, maxLength); std::vector<std::string> lines = cif::wordWrap(text, maxLength);
...@@ -268,15 +268,15 @@ int WriteContinuedLine(std::ostream& pdbFile, std::string header, int& count, in ...@@ -268,15 +268,15 @@ int WriteContinuedLine(std::ostream& pdbFile, std::string header, int& count, in
} }
int WriteOneContinuedLine(std::ostream& pdbFile, std::string header, int cLen, std::string line, int lStart = 0) size_t WriteOneContinuedLine(std::ostream& pdbFile, std::string header, int cLen, std::string line, int lStart = 0)
{ {
int count = 0; int count = 0;
return WriteContinuedLine(pdbFile, header, count, cLen, line, lStart); return WriteContinuedLine(pdbFile, header, count, cLen, line, lStart);
} }
int WriteCitation(std::ostream& pdbFile, Datablock& db, Row r, int reference) size_t WriteCitation(std::ostream& pdbFile, Datablock& db, Row r, int reference)
{ {
int result = 0; size_t result = 0;
std::string s1; std::string s1;
...@@ -2441,18 +2441,18 @@ void WriteRemark350(std::ostream& pdbFile, Datablock& db) ...@@ -2441,18 +2441,18 @@ void WriteRemark350(std::ostream& pdbFile, Datablock& db)
for (auto bm: c1) for (auto bm: c1)
{ {
std::string id, details, method, oligomer; std::string id, detail, method, oligomer;
cif::tie(id, details, method, oligomer) = bm.get("id", "details", "method_details", "oligomeric_details"); cif::tie(id, detail, method, oligomer) = bm.get("id", "details", "method_details", "oligomeric_details");
pdbFile << RM("") << std::endl pdbFile << RM("") << std::endl
<< RM("BIOMOLECULE: ") << id << std::endl; << RM("BIOMOLECULE: ") << id << std::endl;
ba::to_upper(oligomer); ba::to_upper(oligomer);
if (details == "author_defined_assembly" or details == "author_and_software_defined_assembly") if (detail == "author_defined_assembly" or detail == "author_and_software_defined_assembly")
pdbFile << RM("AUTHOR DETERMINED BIOLOGICAL UNIT: ") << oligomer << std::endl; pdbFile << RM("AUTHOR DETERMINED BIOLOGICAL UNIT: ") << oligomer << std::endl;
if (details == "software_defined_assembly" or details == "author_and_software_defined_assembly") if (detail == "software_defined_assembly" or detail == "author_and_software_defined_assembly")
pdbFile << RM("SOFTWARE DETERMINED QUATERNARY STRUCTURE: ") << oligomer << std::endl; pdbFile << RM("SOFTWARE DETERMINED QUATERNARY STRUCTURE: ") << oligomer << std::endl;
if (not method.empty()) if (not method.empty())
...@@ -3070,7 +3070,7 @@ int WriteHeterogen(std::ostream& pdbFile, Datablock& db) ...@@ -3070,7 +3070,7 @@ int WriteHeterogen(std::ostream& pdbFile, Datablock& db)
} }
} }
int nr = count_if(hets.begin(), hets.end(), [hetID](auto& h) -> bool { return h.hetID == hetID; }); auto nr = count_if(hets.begin(), hets.end(), [hetID](auto& h) -> bool { return h.hetID == hetID; });
for (auto r: db["chem_comp"].find(cif::Key("id") == hetID)) for (auto r: db["chem_comp"].find(cif::Key("id") == hetID))
{ {
...@@ -3428,7 +3428,7 @@ int WriteMiscellaneousFeatures(std::ostream& pdbFile, Datablock& db) ...@@ -3428,7 +3428,7 @@ int WriteMiscellaneousFeatures(std::ostream& pdbFile, Datablock& db)
std::string siteID = std::get<0>(s); std::string siteID = std::get<0>(s);
std::deque<std::string>& res = std::get<1>(s); std::deque<std::string>& res = std::get<1>(s);
int numRes = res.size(); size_t numRes = res.size();
int nr = 1; int nr = 1;
while (res.empty() == false) while (res.empty() == false)
...@@ -3533,7 +3533,7 @@ std::tuple<int,int> WriteCoordinatesForModel(std::ostream& pdbFile, Datablock& d ...@@ -3533,7 +3533,7 @@ std::tuple<int,int> WriteCoordinatesForModel(std::ostream& pdbFile, Datablock& d
auto ri = atom_site.begin(); auto ri = atom_site.begin();
std::string id, group, name, altLoc, resName, chainID, iCode, element; std::string id, group, name, altLoc, resName, chainID, iCode, element;
int resSeq, charge; int resSeq = 0, charge;
for (;;) for (;;)
{ {
......
...@@ -599,7 +599,7 @@ DatablockIndex SacParser::indexDatablocks() ...@@ -599,7 +599,7 @@ DatablockIndex SacParser::indexDatablocks()
case data_name: case data_name:
if (isNonBlank(ch)) if (isNonBlank(ch))
datablock.insert(datablock.end(), ch); datablock.insert(datablock.end(), char(ch));
else if (isspace(ch)) else if (isspace(ch))
{ {
if (not datablock.empty()) if (not datablock.empty())
......
...@@ -401,7 +401,7 @@ std::string::const_iterator nextLineBreak(std::string::const_iterator text, std: ...@@ -401,7 +401,7 @@ std::string::const_iterator nextLineBreak(std::string::const_iterator text, std:
return text; return text;
} }
std::vector<std::string> wrapLine(const std::string &text, unsigned int width) std::vector<std::string> wrapLine(const std::string &text, size_t width)
{ {
std::vector<std::string> result; std::vector<std::string> result;
std::vector<size_t> offsets = {0}; std::vector<size_t> offsets = {0};
...@@ -462,7 +462,7 @@ std::vector<std::string> wrapLine(const std::string &text, unsigned int width) ...@@ -462,7 +462,7 @@ std::vector<std::string> wrapLine(const std::string &text, unsigned int width)
return result; return result;
} }
std::vector<std::string> wordWrap(const std::string &text, unsigned int width) std::vector<std::string> wordWrap(const std::string &text, size_t width)
{ {
std::vector<std::string> paragraphs; std::vector<std::string> paragraphs;
ba::split(paragraphs, text, ba::is_any_of("\n")); ba::split(paragraphs, text, ba::is_any_of("\n"));
...@@ -490,6 +490,9 @@ std::vector<std::string> wordWrap(const std::string &text, unsigned int width) ...@@ -490,6 +490,9 @@ std::vector<std::string> wordWrap(const std::string &text, unsigned int width)
#include <Windows.h> #include <Windows.h>
#include <libloaderapi.h> #include <libloaderapi.h>
#include <wincon.h> #include <wincon.h>
#include <codecvt>
namespace cif namespace cif
{ {
...@@ -498,7 +501,6 @@ uint32_t get_terminal_width() ...@@ -498,7 +501,6 @@ uint32_t get_terminal_width()
return TERM_WIDTH; return TERM_WIDTH;
} }
// I don't have a windows machine to test the following code, please accept my apologies in case it fails...
std::string GetExecutablePath() std::string GetExecutablePath()
{ {
WCHAR buffer[4096]; WCHAR buffer[4096];
...@@ -509,7 +511,11 @@ std::string GetExecutablePath() ...@@ -509,7 +511,11 @@ std::string GetExecutablePath()
std::wstring ws(buffer); std::wstring ws(buffer);
return std::string(ws.begin(), ws.end()); // convert from utf16 to utf8
std::wstring_convert<std::codecvt_utf8<wchar_t>> conv1;
std::string u8str = conv1.to_bytes(ws);
return u8str;
} }
#else #else
......
...@@ -121,8 +121,8 @@ int ValidateType::compare(const char* a, const char* b) const ...@@ -121,8 +121,8 @@ int ValidateType::compare(const char* a, const char* b) const
if (mPrimitiveType == DDL_PrimitiveType::UChar) if (mPrimitiveType == DDL_PrimitiveType::UChar)
{ {
ca = toupper(ca); ca = tolower(ca);
cb = toupper(cb); cb = tolower(cb);
} }
result = ca - cb; result = ca - cb;
......
...@@ -172,23 +172,23 @@ Compound::Compound(cif::Datablock &db, const std::string &id, const std::string ...@@ -172,23 +172,23 @@ Compound::Compound(cif::Datablock &db, const std::string &id, const std::string
for (auto row : chemCompBond) for (auto row : chemCompBond)
{ {
CompoundBond bond; CompoundBond bond;
std::string type; std::string btype;
cif::tie(bond.atomID[0], bond.atomID[1], type, bond.aromatic) = row.get("atom_id_1", "atom_id_2", "type", "aromatic"); cif::tie(bond.atomID[0], bond.atomID[1], btype, bond.aromatic) = row.get("atom_id_1", "atom_id_2", "type", "aromatic");
using cif::iequals; using cif::iequals;
if (iequals(type, "single")) if (iequals(btype, "single"))
bond.type = BondType::sing; bond.type = BondType::sing;
else if (iequals(type, "double")) else if (iequals(btype, "double"))
bond.type = BondType::doub; bond.type = BondType::doub;
else if (iequals(type, "triple")) else if (iequals(btype, "triple"))
bond.type = BondType::trip; bond.type = BondType::trip;
else if (iequals(type, "deloc") or iequals(type, "aromat") or iequals(type, "aromatic")) else if (iequals(btype, "deloc") or iequals(btype, "aromat") or iequals(btype, "aromatic"))
bond.type = BondType::delo; bond.type = BondType::delo;
else else
{ {
if (cif::VERBOSE) if (cif::VERBOSE)
std::cerr << "Unimplemented chem_comp_bond.type " << type << " in " << id << std::endl; std::cerr << "Unimplemented chem_comp_bond.type " << btype << " in " << id << std::endl;
bond.type = BondType::sing; bond.type = BondType::sing;
} }
mBonds.push_back(std::move(bond)); mBonds.push_back(std::move(bond));
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -1479,8 +1479,8 @@ bool Remark3Parser::parse(const std::string& expMethod, PDBRecord* r, cif::Datab ...@@ -1479,8 +1479,8 @@ bool Remark3Parser::parse(const std::string& expMethod, PDBRecord* r, cif::Datab
} }
else else
{ {
for (auto r: cat1) for (auto rs: cat1)
cat2.emplace(r); cat2.emplace(rs);
} }
} }
} }
......
...@@ -45,10 +45,10 @@ quaternion Normalize(quaternion q) ...@@ -45,10 +45,10 @@ quaternion Normalize(quaternion q)
t *= t; t *= t;
double length = sqrt(t.sum()); double length = std::sqrt(t.sum());
if (length > 0.001) if (length > 0.001)
q /= length; q /= static_cast<quaternion::value_type>(length);
else else
q = quaternion(1, 0, 0, 0); q = quaternion(1, 0, 0, 0);
...@@ -67,7 +67,7 @@ std::tuple<double,Point> QuaternionToAngleAxis(quaternion q) ...@@ -67,7 +67,7 @@ std::tuple<double,Point> QuaternionToAngleAxis(quaternion q)
angle = angle * 180 / kPI; angle = angle * 180 / kPI;
// axis: // axis:
double s = sqrt(1 - q.R_component_1() * q.R_component_1()); float s = std::sqrt(1 - q.R_component_1() * q.R_component_1());
if (s < 0.001) if (s < 0.001)
s = 1; s = 1;
...@@ -108,7 +108,7 @@ Point Centroid(std::vector<Point>& Points) ...@@ -108,7 +108,7 @@ Point Centroid(std::vector<Point>& Points)
for (Point& pt : Points) for (Point& pt : Points)
result += pt; result += pt;
result /= Points.size(); result /= static_cast<float>(Points.size());
return result; return result;
} }
...@@ -158,7 +158,7 @@ double LargestDepressedQuarticSolution(double a, double b, double c) ...@@ -158,7 +158,7 @@ double LargestDepressedQuarticSolution(double a, double b, double c)
std::complex<double> W = std::sqrt(a + 2.0 * y); std::complex<double> W = std::sqrt(a + 2.0 * y);
// And to get the final result: // And to get the final result:
// result = (±W + sqrt(-(3 * alpha + 2 * y ± 2 * beta / W))) / 2; // result = (±W + std::sqrt(-(3 * alpha + 2 * y ± 2 * beta / W))) / 2;
// We want the largest result, so: // We want the largest result, so:
std::valarray<double> t(4); std::valarray<double> t(4);
...@@ -289,15 +289,15 @@ Point Nudge(Point p, float offset) ...@@ -289,15 +289,15 @@ Point Nudge(Point p, float offset)
std::uniform_real_distribution<> randomAngle(0, 2 * kPI); std::uniform_real_distribution<> randomAngle(0, 2 * kPI);
std::normal_distribution<> randomOffset(0, offset); std::normal_distribution<> randomOffset(0, offset);
float theta = randomAngle(rng); float theta = static_cast<float>(randomAngle(rng));
float phi1 = randomAngle(rng) - kPI; float phi1 = static_cast<float>(randomAngle(rng) - kPI);
float phi2 = randomAngle(rng) - kPI; float phi2 = static_cast<float>(randomAngle(rng) - kPI);
quaternion q = boost::math::spherical(1.0f, theta, phi1, phi2); quaternion q = boost::math::spherical(1.0f, theta, phi1, phi2);
Point r{ 0, 0, 1 }; Point r{ 0, 0, 1 };
r.rotate(q); r.rotate(q);
r *= randomOffset(rng); r *= static_cast<float>(randomOffset(rng));
return p + r; return p + r;
} }
......
...@@ -154,21 +154,21 @@ struct BridgeParner ...@@ -154,21 +154,21 @@ struct BridgeParner
// -------------------------------------------------------------------- // --------------------------------------------------------------------
const float const float
// kSSBridgeDistance = 3.0, // kSSBridgeDistance = 3.0f,
kMinimalDistance = 0.5, kMinimalDistance = 0.5f,
kMinimalCADistance = 9.0, kMinimalCADistance = 9.0f,
kMinHBondEnergy = -9.9, kMinHBondEnergy = -9.9f,
kMaxHBondEnergy = -0.5, kMaxHBondEnergy = -0.5f,
kCouplingConstant = -27.888, // = -332 * 0.42 * 0.2 kCouplingConstant = -27.888f, // = -332 * 0.42 * 0.2
kMaxPeptideBondLength = 2.5; kMaxPeptideBondLength = 2.5f;
const float const float
kRadiusN = 1.65, kRadiusN = 1.65f,
kRadiusCA = 1.87, kRadiusCA = 1.87f,
kRadiusC = 1.76, kRadiusC = 1.76f,
kRadiusO = 1.4, kRadiusO = 1.4f,
kRadiusSideAtom = 1.8, kRadiusSideAtom = 1.8f,
kRadiusWater = 1.4; kRadiusWater = 1.4f;
struct Res struct Res
{ {
...@@ -233,7 +233,7 @@ struct Res ...@@ -233,7 +233,7 @@ struct Res
auto pc = mPrev->mC; auto pc = mPrev->mC;
auto po = mPrev->mO; auto po = mPrev->mO;
double CODistance = Distance(pc, po); float CODistance = static_cast<float>(Distance(pc, po));
mH.mX += (pc.mX - po.mX) / CODistance; mH.mX += (pc.mX - po.mX) / CODistance;
mH.mY += (pc.mY - po.mY) / CODistance; mH.mY += (pc.mY - po.mY) / CODistance;
...@@ -429,16 +429,16 @@ MSurfaceDots::MSurfaceDots(int32_t N) ...@@ -429,16 +429,16 @@ MSurfaceDots::MSurfaceDots(int32_t N)
{ {
auto P = 2 * N + 1; auto P = 2 * N + 1;
const double kGoldenRatio = (1 + sqrt(5.0)) / 2; const float kGoldenRatio = (1 + std::sqrt(5.0f)) / 2;
mWeight = (4 * kPI) / P; mWeight = (4 * kPI) / P;
for (auto i = -N; i <= N; ++i) for (auto i = -N; i <= N; ++i)
{ {
double lat = asin((2.0 * i) / P); float lat = std::asin((2.0f * i) / P);
double lon = fmod(i, kGoldenRatio) * 2 * kPI / kGoldenRatio; float lon = static_cast<float>(std::fmod(i, kGoldenRatio) * 2 * kPI / kGoldenRatio);
mPoints.emplace_back(sin(lon) * cos(lat), cos(lon) * cos(lat), sin(lat)); mPoints.emplace_back(std::sin(lon) * std::cos(lat), std::cos(lon) * std::cos(lat), std::sin(lat));
} }
} }
...@@ -768,7 +768,7 @@ void CalculateBetaSheets(std::vector<Res>& inResidues, DSSP_Statistics& stats) ...@@ -768,7 +768,7 @@ void CalculateBetaSheets(std::vector<Res>& inResidues, DSSP_Statistics& stats)
{ {
ladderset.insert(&bridge); ladderset.insert(&bridge);
uint32_t n = bridge.i.size(); size_t n = bridge.i.size();
if (n > kHistogramSize) if (n > kHistogramSize)
n = kHistogramSize; n = kHistogramSize;
...@@ -815,7 +815,7 @@ void CalculateBetaSheets(std::vector<Res>& inResidues, DSSP_Statistics& stats) ...@@ -815,7 +815,7 @@ void CalculateBetaSheets(std::vector<Res>& inResidues, DSSP_Statistics& stats)
++ladder; ++ladder;
} }
uint32_t nrOfLaddersPerSheet = sheetset.size(); size_t nrOfLaddersPerSheet = sheetset.size();
if (nrOfLaddersPerSheet > kHistogramSize) if (nrOfLaddersPerSheet > kHistogramSize)
nrOfLaddersPerSheet = kHistogramSize; nrOfLaddersPerSheet = kHistogramSize;
if (nrOfLaddersPerSheet == 1 and (*sheetset.begin())->i.size() > 1) if (nrOfLaddersPerSheet == 1 and (*sheetset.begin())->i.size() > 1)
...@@ -1179,9 +1179,9 @@ DSSPImpl::DSSPImpl(const Structure& s, int min_poly_proline_stretch_length) ...@@ -1179,9 +1179,9 @@ DSSPImpl::DSSPImpl(const Structure& s, int min_poly_proline_stretch_length)
, m_min_poly_proline_stretch_length(min_poly_proline_stretch_length) , m_min_poly_proline_stretch_length(min_poly_proline_stretch_length)
{ {
size_t nRes = accumulate(mPolymers.begin(), mPolymers.end(), size_t nRes = accumulate(mPolymers.begin(), mPolymers.end(),
0.0, [](double s, auto& p) { return s + p.size(); }); 0ULL, [](size_t s, auto& p) { return s + p.size(); });
mStats.nrOfChains = mPolymers.size(); mStats.nrOfChains = static_cast<uint32_t>(mPolymers.size());
mResidues.reserve(nRes); mResidues.reserve(nRes);
int resNumber = 0; int resNumber = 0;
...@@ -1214,7 +1214,7 @@ DSSPImpl::DSSPImpl(const Structure& s, int min_poly_proline_stretch_length) ...@@ -1214,7 +1214,7 @@ DSSPImpl::DSSPImpl(const Structure& s, int min_poly_proline_stretch_length)
} }
} }
mStats.nrOfResidues = mResidues.size(); mStats.nrOfResidues = static_cast<uint32_t>(mResidues.size());
for (size_t i = 0; i + 1 < mResidues.size(); ++i) for (size_t i = 0; i + 1 < mResidues.size(); ++i)
{ {
...@@ -1272,7 +1272,7 @@ void DSSPImpl::calculateSecondaryStructure() ...@@ -1272,7 +1272,7 @@ void DSSPImpl::calculateSecondaryStructure()
switch (r.GetHelixFlag(helixType)) switch (r.GetHelixFlag(helixType))
{ {
case Helix::Start: helix[static_cast<int>(helixType)] = '>'; break; case Helix::Start: helix[static_cast<int>(helixType)] = '>'; break;
case Helix::Middle: helix[static_cast<int>(helixType)] = helixType == HelixType::rh_pp ? 'P' : '3' + static_cast<int>(helixType); break; case Helix::Middle: helix[static_cast<int>(helixType)] = helixType == HelixType::rh_pp ? 'P' : '3' + static_cast<char>(helixType); break;
case Helix::StartAndEnd: helix[static_cast<int>(helixType)] = 'X'; break; case Helix::StartAndEnd: helix[static_cast<int>(helixType)] = 'X'; break;
case Helix::End: helix[static_cast<int>(helixType)] = '<'; break; case Helix::End: helix[static_cast<int>(helixType)] = '<'; break;
case Helix::None: helix[static_cast<int>(helixType)] = ' '; break; case Helix::None: helix[static_cast<int>(helixType)] = ' '; break;
...@@ -1289,10 +1289,10 @@ void DSSPImpl::calculateSecondaryStructure() ...@@ -1289,10 +1289,10 @@ void DSSPImpl::calculateSecondaryStructure()
} }
// finish statistics // finish statistics
mStats.nrOfSSBridges = mSSBonds.size(); mStats.nrOfSSBridges = static_cast<uint32_t>(mSSBonds.size());
mStats.nrOfIntraChainSSBridges = 0; mStats.nrOfIntraChainSSBridges = 0;
int ssBondNr = 0; uint8_t ssBondNr = 0;
for (const auto& [a, b]: mSSBonds) for (const auto& [a, b]: mSSBonds)
{ {
if (a == b) if (a == b)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment