OpenCores
URL https://opencores.org/ocsvn/lxp32/lxp32/trunk

Subversion Repositories lxp32

[/] [lxp32/] [trunk/] [tools/] [src/] [wigen/] [range.cpp] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 ring0_mipt
/*
2
 * Copyright (c) 2016 by Alex I. Kuznetsov.
3
 *
4
 * Part of the LXP32 CPU IP core.
5
 *
6
 * This module implements members of the Range class.
7
 */
8
 
9
#include "range.h"
10
 
11
#include <stdexcept>
12
 
13
Range::Range(): _valid(false) {}
14
 
15
Range::Range(int h,int l): _high(h),_low(l),_valid(true) {
16
        if(l>h) throw std::runtime_error("Invalid range");
17
}
18
 
19
void Range::assign(int h,int l) {
20
        if(l>h) throw std::runtime_error("Invalid range");
21
        _high=h;
22
        _low=l;
23
        _valid=true;
24
}
25
 
26
void Range::clear() {
27
        _valid=false;
28
}
29
 
30
bool Range::valid() const {
31
        return _valid;
32
}
33
 
34
int Range::high() const {
35
        if(!_valid) throw std::runtime_error("Invalid range");
36
        return _high;
37
}
38
 
39
int Range::low() const {
40
        if(!_valid) throw std::runtime_error("Invalid range");
41
        return _low;
42
}
43
 
44
int Range::length() const {
45
        if(!_valid) throw std::runtime_error("Invalid range");
46
        return _high-_low+1;
47
}
48
 
49
std::string Range::toString() const {
50
        if(!_valid) throw std::runtime_error("Invalid range");
51
        return std::to_string(_high)+" downto "+std::to_string(_low);
52
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.