diff options
author | Frank Wuerthwein <fkw@ucsd.edu> | 2009-02-13 00:39:31 +0000 |
---|---|---|
committer | Frank Wuerthwein <fkw@ucsd.edu> | 2009-02-13 00:39:31 +0000 |
commit | 6abeb8fd73ee84b36b0d9b52c778c7b5046a4d2e (patch) | |
tree | a0978368196a31dad2411da6004cc5610db13e56 /src/lib | |
parent | 4fc8a0676ff8207d4b606e3077c5827e118a6f63 (diff) |
Improve DS selection by name
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/rrdFile.js | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/lib/rrdFile.js b/src/lib/rrdFile.js index b8ed7a0..a9053fc 100644 --- a/src/lib/rrdFile.js +++ b/src/lib/rrdFile.js @@ -62,7 +62,7 @@ InvalidRRD.prototype.toString = function() { // ============================================================
// RRD DS Info class
- function RRDDS(rrd_data,rrd_data_idx,my_idx) {
+function RRDDS(rrd_data,rrd_data_idx,my_idx) {
this.rrd_data=rrd_data;
this.rrd_data_idx=rrd_data_idx;
this.my_idx=my_idx;
@@ -310,7 +310,16 @@ RRDHeader.prototype.getLastUpdate = function() { RRDHeader.prototype.getNrDSs = function() {
return this.ds_cnt;
}
-RRDHeader.prototype.getDS = function(idx) {
+RRDHeader.prototype.getDSNames = function() {
+ var ds_names=[]
+ for (var idx=0; idx<this.ds_cnt; idx++) {
+ var ds=this.getDSbyIdx(idx);
+ var ds_name=ds.getName()
+ ds_names.push(ds_name);
+ }
+ return ds_names;
+}
+RRDHeader.prototype.getDSbyIdx = function(idx) {
if ((idx>=0) && (idx<this.ds_cnt)) {
return new RRDDS(this.rrd_data,this.ds_def_idx+this.ds_el_size*idx,idx);
} else {
@@ -319,12 +328,12 @@ RRDHeader.prototype.getDS = function(idx) { }
RRDHeader.prototype.getDSbyName = function(name) {
for (var idx=0; idx<this.ds_cnt; idx++) {
- var ds=this.getDS(idx);
+ var ds=this.getDSbyIdx(idx);
var ds_name=ds.getName()
if (ds_name==name)
return ds;
}
- return undefined;
+ throw RangeError("DS name "+ name +" unknown.");
}
RRDHeader.prototype.getNrRRAs = function() {
@@ -366,11 +375,15 @@ function RRDFile(bf) { this.getNrDSs = function() {
return this.rrd_header.getNrDSs();
}
- this.getDS = function(idx) {
- return this.rrd_header.getDS(idx);
+ this.getDSNames = function() {
+ return this.rrd_header.getDSNames();
}
- this.getDSbyName = function(name) {
- return this.rrd_header.getDSbyName(name);
+ this.getDS = function(id) {
+ if (typeof id == "number") {
+ return this.rrd_header.getDSbyIdx(id);
+ } else {
+ return this.rrd_header.getDSbyName(id);
+ }
}
this.getNrRRAs = function() {
|