summaryrefslogtreecommitdiff
path: root/src/inc/shim/runtimeselector.inl
blob: 5b73a69d9402db91589949e66146b175b4f36641 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//
// runtimeselector.inl
//
// implementation that select the best runtime
// 
// Note: must be platform independent
//
// ======================================================================================

// Constructor
//
// Simply marks the fact that no data is set
inline RuntimeSelector::RuntimeSelector()
{
    m_bHasSomething=false;
}

// Sets the runtime version requested
//
// Input:
// version - version to set
inline void RuntimeSelector::SetRequestedVersion(const VersionInfo& version)
{
    m_RequestedVersion=version;
};


// Returns whether the given runtime can be used
//
// Input:
// runtimeInfo - the runtime info
//
// Output: 
// return value - true: can be used, false: cannot be used
inline bool RuntimeSelector::IsAcceptable(const  RuntimeInfo& runtimeInfo)  const 
{
    return ( m_RequestedVersion.Major() ==  runtimeInfo.Version().Major() &&
                  m_RequestedVersion.Minor() ==  runtimeInfo.Version().Minor());
}


// Returns add the given runtime to the potentially used runtimes list
//
// Input:
// runtimeInfo - the runtime info
//
// Output: 
// return value - S_OK added, S_FALSE not added (not a failure) or a failure code
inline HRESULT RuntimeSelector::Add(const RuntimeInfo& runtimeInfo)
{
    HRESULT hr = S_FALSE;
    if(!IsAcceptable(runtimeInfo))
        return S_FALSE;

    if(!m_bHasSomething || IsBetter(runtimeInfo,m_Best))
    {
        m_Best=runtimeInfo;
        hr=S_OK;        
    }

    m_bHasSomething=true;
    return hr;
};

// Returns add the best runtime of the options given (see Add)
//
// Output: 
// return value - the best option
inline RuntimeInfo RuntimeSelector::GetBest()
{
    return m_Best;
};

// Returns whether we have any usable choices
//
// Output: 
// return value - true if the has something usable 
inline bool RuntimeSelector::HasUsefulRuntimeInfo()
{
    return m_bHasSomething;
};

// Compares two given options
//
// Input: 
// ri1, ri2 - runtimes to compare
//
// Output: 
// return value - true if ri1 is better than ri2
inline bool RuntimeSelector::IsBetter(const RuntimeInfo& ri1, const RuntimeInfo& ri2) 
{
    switch(ri1.Version().Compare(ri2.Version()))
    {
        case -1: return false;
        case 1: return true;
        default:
        return (BetterLocation(ri1.Location(),ri2.Location())==ri1.Location());
    }
};