m_PatchLevel(patch_level),
75 intmajor, minor, patch = 0;
130 if( !
m_Name.empty() ) {
131os <<
" ("<<
m_Name<<
")";
140os <<
"<version_info";
142os <<
" major=\""<<
m_Major<<
148 if( !
m_Name.empty() ) {
160 boolneed_separator =
false;
162os <<
"\"major\": "<<
m_Major<<
167need_separator =
true;
169 if( !
m_Name.empty() ) {
170 if( need_separator ) os <<
", ";
219 int& best_patch_level)
225 if(
info.GetMajor() == -1) {
226 if(major > best_major) {
229best_patch_level = patch_level;
235 if(
info.GetMajor() != major) {
240 if(
info.GetMinor() == -1) {
241 if(minor > best_minor) {
244best_patch_level = patch_level;
248 if(
info.GetMinor() > minor) {
251 if(
info.GetMinor() < minor) {
254best_patch_level = patch_level;
261 if(patch_level > best_patch_level) {
264best_patch_level = patch_level;
272 string* program_name,
282program_name->erase();
286string::size_type pos;
288 const char* vstr_str = vstr.c_str();
292pos = lo_vstr.find(
"(");
293 if(pos != string::npos) {
294string::size_type pos2 = lo_vstr.find(
")", pos);
295 if(pos2 == string::npos) {
297eFormat,
"Version string format error", 0);
299 for(++pos; pos < pos2; ++pos) {
300program_name->push_back(vstr.at(pos));
312 static const char* version_patterns[] = {
320 for(
const char** ppattern = version_patterns; *ppattern !=
nullptr;
322pos = lo_vstr.rfind(*ppattern);
326= lo_vstr.find_first_not_of(
" .", pos + strlen(*ppattern));
327 if( !
isdigit(lo_vstr[pos2]) ) {
331version_pattern = *ppattern;
336 if(pos == string::npos) {
338 const char* ch = vstr_str;
340 if(
isdigit((
unsigned char)(*ch))) {
341 if(ch == vstr_str) {
343 const char*
ch2= ch + 1;
356 if(
isspace((
unsigned char) ch[-1])) {
367 if(pos != string::npos) {
368 intpname_end = (
int)(pos - 1);
369 for(; pname_end >= 0; --pname_end) {
370 charch = vstr[pname_end];
371 if(!
isspace((
unsigned char) ch))
374 if(pname_end <= 0) {
376program_name->append(vstr.c_str(), pname_end + 1);
379pos += strlen(version_pattern);
380 for(; pos < vstr.length(); ++pos) {
384 if(!
isspace((
unsigned char) ch))
388 const char* ver_str = vstr_str + pos;
393*program_name = vstr;
395 if(program_name->empty()) {
410 const string& name,
const SBuildInfo& build_info)
411:
CVersionInfo(ver_major, ver_minor, patch_level, name),
412m_ComponentName( component_name ), m_BuildInfo(build_info)
418 const string& name,
const SBuildInfo& build_info)
420m_ComponentName( component_name ), m_BuildInfo(build_info)
438 "</component>"<< endl;
455: date(__DATE__
" "__TIME__) {
460 if(!
value.empty()) {
481 for(
const auto& e :
m_extra) {
482 if(e.first ==
key) {
487 returndefault_value;
515 case eBuildDate:
return "ncbi_app_build_date";
516 case eBuildTag:
return "ncbi_app_build_tag";
520 case eBuildID:
return "ncbi_app_build_id";
525 case eBuiltAs:
return "ncbi_app_built_as";
526 case eRevision:
return "ncbi_app_revision";
527 case eGitBranch:
return "ncbi_app_gitbranch";
529 return "ncbi_app_unk";
550 stringprefix(
offset+1,
' ');
552 if(!
date.empty()) {
556 if(!
tag.empty()) {
559 for(
const auto& e :
m_extra) {
560os << prefix <<
ExtraName(e.first) <<
": "<< e.second << endl;
568os <<
"<build_info";
569 if( !
date.empty() ) {
572 if( !
tag.empty() ) {
576 for(
const auto& e :
m_extra) {
579os <<
"</build_info>"<< endl;
586 boolneed_separator =
false;
588 if( !
date.empty() ) {
590need_separator =
true;
592 if( !
tag.empty() ) {
593 if( need_separator ) os <<
", ";
595need_separator =
true;
597 for(
const auto& e :
m_extra) {
598 if( need_separator ) os <<
", ";
600need_separator =
true;
623m_BuildInfo(build_info)
631m_BuildInfo(build_info)
659 intpatch_level,
const string& ver_name)
662ver_major, ver_minor, patch_level, ver_name) );
666 intpatch_level,
const string& ver_name,
670ver_major, ver_minor, patch_level, ver_name) );
692 const string& component_name,
intver_major,
intver_minor,
693 intpatch_level,
const string& ver_name,
const SBuildInfo& build_info)
697patch_level, ver_name, build_info));
748 #ifdef NCBI_SIGNATURE 750os <<
" Build-Signature: "<<
' '<< NCBI_SIGNATURE << endl;
755os <<
" GI-64bit: TRUE"<< endl;
757os <<
" GI-64bit: FALSE"<< endl;
767os << endl <<
' '<< c->Print() << endl;
778os <<
"<?xml version=\"1.0\"?>\n" 779 "<ncbi_version xmlns=\"ncbi:version\"\n" 780 " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" 781 " xs:schemaLocation=\"ncbi:version ncbi_version.xsd\">\n";
784 if( !appname.empty() ) {
804os <<
"</package>\n";
808 #ifdef NCBI_SIGNATURE 810os <<
"<build_signature>"<<
NStr::XmlEncode(NCBI_SIGNATURE) <<
"</build_signature>\n";
818os <<
"</ncbi_version>\n";
827 boolneed_separator =
false;
829os <<
"{\n \"ncbi_version\": {\n";
832 if( !appname.empty() ) {
836need_separator =
true;
840 if( need_separator ) os <<
",\n";
841os <<
" \"component\": [";
842need_separator =
false;
844 if( need_separator ) os <<
",";
845os <<
"\n "<< c->PrintJson();
846need_separator =
true;
849need_separator =
true;
854 if( need_separator ) os <<
",\n";
855os <<
" \"package\": {\n"<<
863need_separator =
true;
867 #ifdef NCBI_SIGNATURE 869 if( need_separator ) os <<
",\n";
871need_separator =
true;
876 if( need_separator ) os <<
",\n";
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
static void s_ConvertVersionInfo(CVersionInfo *vi, const char *str)
Define CVersionInfo, a version info storage class.
static const char * str(char *buf, int n)
#define NCBI_THROW2(exception_class, err_code, message, extra)
Throw exception with extra parameter.
CObject & operator=(const CObject &src) THROWS_NONE
Assignment operator.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate whitespace in a string (in-place)
static string XmlEncode(const CTempString str, TXmlEncode flags=eXmlEnc_Contents)
Encode a string for XML.
static string JsonEncode(const CTempString str, EJsonEncode encoding=eJsonEnc_UTF8)
Encode a string for JSON.
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
const char *const kEmptyCStr
Empty "C" string (points to a '\0').
static string & ToLower(string &str)
Convert string to lower case â string& version.
@ eJsonEnc_Quoted
Quote resulting string.
void ParseVersionString(const string &vstr, string *program_name, CVersionInfo *ver)
Parse string, extract version info and program name (case insensitive)
string GetExtraValue(EExtra key, const string &default_value=kEmptyStr) const
int m_Minor
Minor number.
int TPrintFlags
Binary OR of EPrintFlags.
static string ExtraNameJson(EExtra key)
static void x_Copy(CVersionAPI &to, const CVersionAPI &from)
void SetVersionInfo(int ver_major, int ver_minor, int patch_level=0, const string &ver_name=kEmptyStr)
Set version information.
int GetMajor(void) const
Major version.
string PrintJson(void) const
EMatch Match(const CVersionInfo &version_info) const
Check if version matches another version.
CVersionAPI(const SBuildInfo &build_info=SBuildInfo())
const SBuildInfo & GetBuildInfo() const
Get build info (date and tag, if set)
bool IsBetterVersion(const CVersionInfo &info, const CVersionInfo &cinfo, int &best_major, int &best_minor, int &best_patch_level)
Return true if one version info is matches another better than the best variant.
const CVersionInfo & GetVersionInfo() const
Get version information.
int m_PatchLevel
Patch level.
virtual string Print(void) const
Print version information.
string Print(size_t offset=0) const
const string & GetComponentName(void) const
Get component name.
virtual string Print(void) const
Print version information.
static CVersionInfo GetPackageVersion(void)
static string GetPackageConfig(void)
SBuildInfo & Extra(EExtra key, const string &value)
static string ExtraName(EExtra key)
virtual string PrintJson(void) const
Print version information as JSON.
int GetMinor(void) const
Minor version.
CVersionAPI & operator=(const CVersionAPI &version)
vector< pair< EExtra, string > > m_extra
CComponentVersionInfoAPI(const string &component_name, int ver_major, int ver_minor, int patch_level, const string &ver_name, const SBuildInfo &build_info)
Constructor.
unique_ptr< CVersionInfo > m_VersionInfo
CVersionInfo(int ver_major, int ver_minor, int patch_level=0, const string &name=kEmptyStr)
Constructor.
virtual string PrintJson(void) const
Print version information as JSON.
string Print(const string &appname, TPrintFlags flags=fPrintAll) const
Print version data, plain text.
EMatch
Version comparison result.
static string GetPackageName(void)
int GetPatchLevel(void) const
Patch level.
string PrintXml(const string &appname, TPrintFlags flags=fPrintAll) const
Print version data, XML.
string PrintXml(void) const
void AddComponentVersion(const string &component_name, int ver_major, int ver_minor, int patch_level, const string &ver_name, const SBuildInfo &build_info)
Add component version information.
vector< unique_ptr< CComponentVersionInfoAPI > > m_Components
virtual string PrintXml(void) const
Print version information as XML (see ncbi_version.xsd)
int m_Major
Major number.
static string ExtraNameXml(EExtra key)
void FromStr(const string &version)
Take version info from string.
#define NCBI_SBUILDINFO_DEFAULT()
virtual string PrintXml(void) const
Print version information ax XML.
CTime GetBuildTime(void) const
Converts 'date' parameter to CTime.
void SetVersion(int ver_major, int ver_minor, int patch_level=0)
static string ExtraNameAppLog(EExtra key)
string PrintJson(const string &appname, TPrintFlags flags=fPrintAll) const
Print version data, JSON.
@ fPackageShort
Print package info, if available.
@ fBuildSignature
Print build signature, if available.
@ fComponents
Print components version info.
@ fGI64bit
Print info about GI size.
@ fVersionInfo
Print version info.
@ fPackageFull
Print package info, if available.
@ fBuildInfo
Print build info (date and tag)
@ eConditionallyCompatible
patch level incompatibility
@ eNonCompatible
major, minor does not match
@ eFullyCompatible
exactly the same version
@ eBackwardCompatible
patch level is newer
@ eRevision
Not necessarily numeric.
@ eSubversionRevision
Numeric if present.
@ eStableComponentsVersion
unsigned int
A callback function used to compare two keys in a database.
const string version
version string
const struct ncbi::grid::netcache::search::fields::KEY key
const GenericPointer< typename T::ValueType > T2 value
static const BitmapCharRec ch2
#define NCBI_PACKAGE_CONFIG
#define NCBI_PACKAGE_NAME
#define NCBI_PACKAGE_VERSION_PATCH
#define NCBI_PACKAGE_VERSION_MINOR
#define NCBI_PACKAGE_VERSION_MAJOR
This class allows to add build info (date and tag) to application version.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4