summaryrefslogtreecommitdiff
path: root/gridelement.c
blob: af18fcd29ace0d3f9409857289123f86b2267696 (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
#include "gridelement.h"
#include "channelepg.h"

long cGridElement::idCounter;

cGridElement::cGridElement(cChannelEpg *owner) {
    id = idCounter;
    idCounter++;
    init = true;
    active = false;
    hasTimer = false;
    hasSwitchTimer = false;
    this->owner = owner;
}

cGridElement::~cGridElement(void) {
}

bool cGridElement::Match(time_t t) {
    if ((StartTime() < t) && (EndTime() > t))
        return true;
    else
        return false;
}

bool cGridElement::IsFirst(void) {
    return owner->IsFirst(this);
}

int cGridElement::CalcOverlap(cGridElement *neighbor) {
    int overlap = 0;
    if (Intersects(neighbor)) {
        if ((StartTime() <= neighbor->StartTime()) && (EndTime() <= neighbor->EndTime())) {
            overlap = EndTime() - neighbor->StartTime();
        } else if ((StartTime() >= neighbor->StartTime()) && (EndTime() >= neighbor->EndTime())) {
            overlap = neighbor->EndTime() - StartTime();
        } else if ((StartTime() >= neighbor->StartTime()) && (EndTime() <= neighbor->EndTime())) {
            overlap = Duration();
        } else if ((StartTime() <= neighbor->StartTime()) && (EndTime() >= neighbor->EndTime())) {
            overlap = neighbor->EndTime() - neighbor->StartTime();
        }
    }
    return overlap;
}

bool cGridElement::Intersects(cGridElement *neighbor) {
    return ! ( (neighbor->EndTime() <= StartTime()) || (neighbor->StartTime() >= EndTime()) ); 
}

const cChannel *cGridElement::Channel(void) { 
    return owner->Channel(); 
}

cChannelEpg *cGridElement::Owner(void) {
    return owner;
}