50 m_PatchLevel(patch_level),
75 int major, minor, patch = 0;
131 os <<
" (" <<
m_Name <<
")";
140 os <<
"<version_info";
142 os <<
" major=\"" <<
m_Major <<
160 bool need_separator =
false;
162 os <<
"\"major\": " <<
m_Major <<
167 need_separator =
true;
170 if ( need_separator ) os <<
", ";
219 int& best_patch_level)
225 if (
info.GetMajor() == -1) {
226 if (major > best_major) {
229 best_patch_level = patch_level;
235 if (
info.GetMajor() != major) {
240 if (
info.GetMinor() == -1) {
241 if (minor > best_minor) {
244 best_patch_level = patch_level;
248 if (
info.GetMinor() > minor) {
251 if (
info.GetMinor() < minor) {
254 best_patch_level = patch_level;
261 if (patch_level > best_patch_level) {
264 best_patch_level = patch_level;
272 string* program_name,
282 program_name->erase();
286 string::size_type pos;
288 const char* vstr_str = vstr.c_str();
292 pos = lo_vstr.find(
"(");
293 if (pos != string::npos) {
294 string::size_type pos2 = lo_vstr.find(
")", pos);
295 if (pos2 == string::npos) {
297 eFormat,
"Version string format error", 0);
299 for (++pos; pos < pos2; ++pos) {
300 program_name->push_back(vstr.at(pos));
312 const char* version_pattern =
"version";
314 pos = lo_vstr.find(version_pattern);
315 if (pos == string::npos) {
316 version_pattern =
"v.";
317 pos = lo_vstr.find(version_pattern);
319 if (pos == string::npos) {
320 version_pattern =
"ver";
321 pos = lo_vstr.find(version_pattern);
323 if (pos == string::npos) {
324 version_pattern =
"";
326 const char* ch = vstr_str;
328 if (
isdigit((
unsigned char)(*ch))) {
329 if (ch == vstr_str) {
331 const char*
ch2 = ch + 1;
344 if (
isspace((
unsigned char) ch[-1])) {
357 if (pos != string::npos) {
358 int pname_end = (
int)(pos - 1);
359 for (; pname_end >= 0; --pname_end) {
360 char ch = vstr[pname_end];
361 if (!
isspace((
unsigned char) ch))
364 if (pname_end <= 0) {
366 program_name->append(vstr.c_str(), pname_end + 1);
369 pos += strlen(version_pattern);
370 for(; pos < vstr.length(); ++pos) {
374 if (!
isspace((
unsigned char) ch))
378 const char* ver_str = vstr_str + pos;
383 *program_name = vstr;
385 if (program_name->empty()) {
400 const string& name,
const SBuildInfo& build_info)
401 :
CVersionInfo(ver_major, ver_minor, patch_level, name),
402 m_ComponentName( component_name ), m_BuildInfo(build_info)
408 const string& name,
const SBuildInfo& build_info)
410 m_ComponentName( component_name ), m_BuildInfo(build_info)
428 "</component>" << endl;
445 : date(__DATE__
" " __TIME__) {
450 if (!
value.empty()) {
471 for(
const auto& e :
m_extra) {
472 if (e.first ==
key) {
477 return default_value;
505 case eBuildDate:
return "ncbi_app_build_date";
506 case eBuildTag:
return "ncbi_app_build_tag";
510 case eBuildID:
return "ncbi_app_build_id";
515 case eBuiltAs:
return "ncbi_app_built_as";
516 case eRevision:
return "ncbi_app_revision";
519 return "ncbi_app_unk";
549 for(
const auto& e :
m_extra) {
559 if ( !
date.empty() ) {
562 if ( !
tag.empty() ) {
566 for(
const auto& e :
m_extra) {
569 os <<
"</build_info>" << endl;
576 bool need_separator =
false;
578 if ( !
date.empty() ) {
580 need_separator =
true;
582 if ( !
tag.empty() ) {
583 if ( need_separator ) os <<
", ";
585 need_separator =
true;
587 for(
const auto& e :
m_extra) {
588 if ( need_separator ) os <<
", ";
590 need_separator =
true;
613 m_BuildInfo(build_info)
621 m_BuildInfo(build_info)
649 int patch_level,
const string& ver_name)
652 ver_major, ver_minor, patch_level, ver_name) );
656 int patch_level,
const string& ver_name,
660 ver_major, ver_minor, patch_level, ver_name) );
682 const string& component_name,
int ver_major,
int ver_minor,
683 int patch_level,
const string& ver_name,
const SBuildInfo& build_info)
687 patch_level, ver_name, build_info));
738 #ifdef NCBI_SIGNATURE
740 os <<
" Build-Signature: " <<
' ' << NCBI_SIGNATURE << endl;
745 os <<
" GI-64bit: TRUE" << endl;
747 os <<
" GI-64bit: FALSE" << endl;
757 os << endl <<
' ' << c->Print() << endl;
768 os <<
"<?xml version=\"1.0\"?>\n"
769 "<ncbi_version xmlns=\"ncbi:version\"\n"
770 " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
771 " xs:schemaLocation=\"ncbi:version ncbi_version.xsd\">\n";
774 if ( !appname.empty() ) {
794 os <<
"</package>\n";
798 #ifdef NCBI_SIGNATURE
800 os <<
"<build_signature>" <<
NStr::XmlEncode(NCBI_SIGNATURE) <<
"</build_signature>\n";
808 os <<
"</ncbi_version>\n";
817 bool need_separator =
false;
819 os <<
"{\n \"ncbi_version\": {\n";
822 if ( !appname.empty() ) {
826 need_separator =
true;
830 if ( need_separator ) os <<
",\n";
831 os <<
" \"component\": [";
832 need_separator =
false;
834 if ( need_separator ) os <<
",";
835 os <<
"\n " << c->PrintJson();
836 need_separator =
true;
839 need_separator =
true;
844 if ( need_separator ) os <<
",\n";
845 os <<
" \"package\": {\n" <<
853 need_separator =
true;
857 #ifdef NCBI_SIGNATURE
859 if ( need_separator ) os <<
",\n";
861 need_separator =
true;
866 if ( need_separator ) os <<
",\n";
868 need_separator =
true;
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.
#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 spaces 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.
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 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)
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 struct ncbi::grid::netcache::search::fields::KEY key
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
static const char * prefix[]
static const char * str(char *buf, int n)
This class allows to add build info (date and tag) to application version.