/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
class CACHEWrapper {
 var $cache;
 var $mask;
 
 var $itemcache;
 
 var $DEFAULT_CONFIG;
 
 function __construct(CACHE $cache, MASK $mask = NULL) {
    $this->cache = $cache;
    $this->mask = $mask;

    $this->itemcache = false;

     $this->DEFAULT_CONFIG = array(
	'type' => CACHEDB::TYPE_AUTO,
	'limit' => 0,
	'amount' => 0
    );
 }
 
 function GetCache() {
    return $this->cache;
 }
 
 function GetMask() {
    return $this->mask;
 }

 function GetGroupProps() {
    return $this->cache->req->GetGroupProps();
 }

 function GetOption($prop, $default = NULL) {
    return $this->cache->reader->GetGroupOption($this->cache->group, $prop, $default);
 }
 
 function GetMaskIDs() {
    return $this->mask->GetIDs();
 }
 
 function GetWidth() {
    if (($this->mask)&&($this->mask->ids)) return sizeof($this->mask->ids);
    try {
        $mask = $this->cache->CreateMask();
    } catch (ADEIException $ae) {
        if ($ae->getCode() == ADEIException::NO_CACHE) return 0;
        throw $ae;
    }
    return sizeof($mask->ids);
 }

 private function GetCachedItems($flags, $query_flags = false) {
    if ($this->itemcache) {
	$cf = $this->itemcache['flags'];
	$exact_match = $query_flags&CACHESet::EXACT_FLAGS;
	if (((!$exact_match)&&(($cf&$flags) == $flags))||(($exact_match)&&($flags == $cf))) {
	    return $this->itemcache['items'];
	}

	if ($query_flags&CACHESet::CACHE_ITEMS) {
	    unset($this->itemcache);
	}
    }
    
    if ($query_flags === false) $query_flags = $flags;
    $items = $this->cache->GetItemList($this->mask, $query_flags);

    if ($query_flags&CACHESet::CACHE_ITEMS) {
	$this->itemcache = array(
	    'flags' => $query_flags,
	    'items' => &$items
	);
    }
    
    return $items;
 }

 function CreateAxes(GRAPHAxes $axes, $flags = 0) {
    $itemlist = $this->GetCachedItems(
	REQUEST::NEED_AXISINFO, 
	($flags&CACHESet::CACHE_ITEMS)?($flags|REQUEST::NEED_AXISINFO):(REQUEST::NEED_AXISINFO|REQUEST::ONLY_AXISINFO)
    );
    
    $size = $this->GetWidth();
    for ($i=0;$i<$size;$i++) {
	$axes->GetAxis(is_array($itemlist[$i])?$itemlist[$i]['axis']:false);
    }
 }
 
 function GetItemList($flags = 0) {
    return $this->GetCachedItems($flags);
 }

 function GetGroupTitle() {
    return $this->cache->GetTitle();
 }

 function GetIntervals(INTERVAL $ivl = NULL, array $cfg = NULL, $flags = 0) {
    if (isset($cfg['resolution'])) $resolution = $cfg['resolution'];
    else $resolution = $this->cache->resolution->Get($ivl, $cfg['amount']);

    try {
        $res = $this->cache->GetIntervals($this->mask, $ivl, $cfg['limit'], $cfg['amount'], $resolution, $flags);
    } catch (ADEIException $ae) {
        if ($ae->getCode() == ADEIException::NO_CACHE) return array();
        throw $ae;
    }
    
    return $res;
 }

 function GetNeighbors($x, array $cfg = NULL, $flags = 0) {
    try {
        $res = $this->cache->GetNeighbors($this->mask, $x, ($cfg&&isset($cfg['amount']))?$cfg['amount']:false, $flags);
    } catch (ADEIException $ae) {
        if ($ae->getCode() == ADEIException::NO_CACHE) return array();
        throw $ae;
    }

    return $res;
 }

 function GetPoints(INTERVAL $ivl = NULL, array $cfg = NULL, $flags = 0) {
    if (!$cfg) $cfg = &$this->DEFAULT_CONFIG;
    
    if (isset($cfg['resolution'])) $resolution = $cfg['resolution'];
    else $resolution = $this->cache->resolution->Get($ivl, $cfg['amount']);
    
    try {
        $res = $this->cache->GetPoints($this->mask, $ivl, $cfg['type'], $cfg['limit'], $cfg['amount'], $resolution, $flags);
    } catch (ADEIException $ae) {
        if ($ae->getCode() == ADEIException::NO_CACHE) return array();
        throw $ae;
    }
    return $res;
 }

 function GetAllPoints(INTERVAL $ivl = NULL, $limit = 0) {
    try {
        $res = $this->cache->GetAllPoints($this->mask, $ivl, $limit);
    } catch (ADEIException $ae) {
        if ($ae->getCode() == ADEIException::NO_CACHE) return array();
        throw $ae;
    }
    
    return $res;
 }
 
 function GetResolution() {
    return $this->cache->resolution;
 }
}
?>