File: fgmrank.cc

package info (click to toggle)
ftpgrab 0.1.2r-8
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 376 kB
  • ctags: 335
  • sloc: cpp: 2,790; makefile: 26
file content (108 lines) | stat: -rw-r--r-- 2,228 bytes parent folder | download | duplicates (3)
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
106
107
108
// fgmrank.cc

#include "fgmrank.h"

#ifndef __SGI_STL_VECTOR_H
#include <vector.h>
#endif

struct FGMatchRanking::Internal_FGMatchRanking {
  bool mIsMatch;
  vector<int> mValues;
};

FGMatchRanking::FGMatchRanking()
{
  mpInternals = new Internal_FGMatchRanking;
  mpInternals->mIsMatch = false;
}

FGMatchRanking::~FGMatchRanking()
{
  delete mpInternals;
}

FGMatchRanking::FGMatchRanking(const FGMatchRanking& other)
{
  mpInternals = new Internal_FGMatchRanking;
  *mpInternals = *other.mpInternals;
}

FGMatchRanking&
FGMatchRanking::operator=(const FGMatchRanking& other)
{
  if (this == &other) {
    return *this;
  }

  // Free existing stuff
  delete mpInternals;

  mpInternals = new Internal_FGMatchRanking;
  *mpInternals = *other.mpInternals;

  return *this;
}

void
FGMatchRanking::AddValue(int value)
{
  mpInternals->mValues.push_back(value);
}

void
FGMatchRanking::SetMatch(void)
{
  mpInternals->mIsMatch = true;
}

bool
FGMatchRanking::IsMatch(void) const
{
  return mpInternals->mIsMatch;
}

bool
FGMatchRanking::operator<(const FGMatchRanking& other) const
{
  // Always less than if we're not a match
  // n.b. nothing should be comparing against non-match anyway
  if (mpInternals->mIsMatch == false) {
    return true;
  }

  // Never less than, if comparing against non-match
  if (other.mpInternals->mIsMatch == false) {
    return false;
  }

  // Otherwise iterate through components one by one
  int thisSize = mpInternals->mValues.size();
  int otherSize = other.mpInternals->mValues.size();
  int min = thisSize;
  if (otherSize < min) {
    min = otherSize;
  }

  int index;
  for (index = 0; index < min; index++) {
    if (mpInternals->mValues[index] < other.mpInternals->mValues[index]) {
      // Yes we are an older version
      return true;
    } else if (mpInternals->mValues[index] > other.mpInternals->mValues[index]) {
      // Newer version.. so not older version
      return false;
    }
    // else.. equal so progress to next component and compare
  }

  // Oh we ran out of comparisions
  // If we have more bits of version we are greater (not less than)
  if (thisSize > otherSize) {
    return false;
  }

  // Oh we are equal
  // That's not less than
  return false;
}