Mercurial > hg > orthanc
comparison OrthancFramework/Sources/Toolbox.cpp @ 5577:9e74e761b108 find-refactoring
integration mainline->find-refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 26 Apr 2024 17:43:22 +0200 |
parents | d7eaa568da15 |
children | f7adfb22e20e |
comparison
equal
deleted
inserted
replaced
5574:5a13483d12c5 | 5577:9e74e761b108 |
---|---|
2674 return oss.str(); | 2674 return oss.str(); |
2675 } | 2675 } |
2676 } | 2676 } |
2677 | 2677 |
2678 | 2678 |
2679 bool Toolbox::ParseVersion(unsigned int& major, | |
2680 unsigned int& minor, | |
2681 unsigned int& revision, | |
2682 const char* version) | |
2683 { | |
2684 if (version == NULL) | |
2685 { | |
2686 throw OrthancException(ErrorCode_NullPointer); | |
2687 } | |
2688 | |
2689 #ifdef _MSC_VER | |
2690 #define ORTHANC_SCANF sscanf_s | |
2691 #else | |
2692 #define ORTHANC_SCANF sscanf | |
2693 #endif | |
2694 | |
2695 int a, b, c; | |
2696 if (ORTHANC_SCANF(version, "%4d.%4d.%4d", &a, &b, &c) == 3) | |
2697 { | |
2698 if (a >= 0 && | |
2699 b >= 0 && | |
2700 c >= 0) | |
2701 { | |
2702 major = static_cast<unsigned int>(a); | |
2703 minor = static_cast<unsigned int>(b); | |
2704 revision = static_cast<unsigned int>(c); | |
2705 return true; | |
2706 } | |
2707 else | |
2708 { | |
2709 return false; | |
2710 } | |
2711 } | |
2712 else if (ORTHANC_SCANF(version, "%4d.%4d", &a, &b) == 2) | |
2713 { | |
2714 if (a >= 0 && | |
2715 b >= 0) | |
2716 { | |
2717 major = static_cast<unsigned int>(a); | |
2718 minor = static_cast<unsigned int>(b); | |
2719 revision = 0; | |
2720 return true; | |
2721 } | |
2722 else | |
2723 { | |
2724 return false; | |
2725 } | |
2726 } | |
2727 else if (ORTHANC_SCANF(version, "%4d", &a) == 1 && | |
2728 a >= 0) | |
2729 { | |
2730 if (a >= 0) | |
2731 { | |
2732 major = static_cast<unsigned int>(a); | |
2733 minor = 0; | |
2734 revision = 0; | |
2735 return true; | |
2736 } | |
2737 else | |
2738 { | |
2739 return false; | |
2740 } | |
2741 } | |
2742 else | |
2743 { | |
2744 return false; | |
2745 } | |
2746 } | |
2747 | |
2748 | |
2749 bool Toolbox::IsVersionAbove(const char* version, | |
2750 unsigned int major, | |
2751 unsigned int minor, | |
2752 unsigned int revision) | |
2753 { | |
2754 /** | |
2755 * Note: Similar standalone functions are implemented in | |
2756 * "OrthancCPlugin.h" and "OrthancPluginCppWrapper.cpp". | |
2757 **/ | |
2758 | |
2759 unsigned int actualMajor, actualMinor, actualRevision; | |
2760 | |
2761 if (version == NULL) | |
2762 { | |
2763 throw OrthancException(ErrorCode_NullPointer); | |
2764 } | |
2765 else if (!strcmp(version, "mainline")) | |
2766 { | |
2767 // Assume compatibility with the mainline | |
2768 return true; | |
2769 } | |
2770 else if (ParseVersion(actualMajor, actualMinor, actualRevision, version)) | |
2771 { | |
2772 if (actualMajor > major) | |
2773 { | |
2774 return true; | |
2775 } | |
2776 | |
2777 if (actualMajor < major) | |
2778 { | |
2779 return false; | |
2780 } | |
2781 | |
2782 // Check the minor version number | |
2783 assert(actualMajor == major); | |
2784 | |
2785 if (actualMinor > minor) | |
2786 { | |
2787 return true; | |
2788 } | |
2789 | |
2790 if (actualMinor < minor) | |
2791 { | |
2792 return false; | |
2793 } | |
2794 | |
2795 // Check the patch level version number | |
2796 assert(actualMajor == major); | |
2797 | |
2798 if (actualRevision >= revision) | |
2799 { | |
2800 return true; | |
2801 } | |
2802 else | |
2803 { | |
2804 return false; | |
2805 } | |
2806 } | |
2807 else | |
2808 { | |
2809 throw OrthancException(ErrorCode_ParameterOutOfRange, "Not a valid version: " + std::string(version)); | |
2810 } | |
2811 } | |
2679 } | 2812 } |
2680 | 2813 |
2681 | 2814 |
2682 | 2815 |
2683 OrthancLinesIterator* OrthancLinesIterator_Create(const std::string& content) | 2816 OrthancLinesIterator* OrthancLinesIterator_Create(const std::string& content) |