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

Subversion Repositories lxp32

[/] [lxp32/] [trunk/] [tools/] [src/] [wigen/] [range.cpp] - Diff between revs 2 and 9

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 2 Rev 9
/*
/*
 * Copyright (c) 2016 by Alex I. Kuznetsov.
 * Copyright (c) 2016 by Alex I. Kuznetsov.
 *
 *
 * Part of the LXP32 CPU IP core.
 * Part of the LXP32 CPU IP core.
 *
 *
 * This module implements members of the Range class.
 * This module implements members of the Range class.
 */
 */
 
 
#include "range.h"
#include "range.h"
 
 
#include <stdexcept>
#include <stdexcept>
 
 
Range::Range(): _valid(false) {}
Range::Range(): _valid(false) {}
 
 
Range::Range(int h,int l): _high(h),_low(l),_valid(true) {
Range::Range(int h,int l): _high(h),_low(l),_valid(true) {
        if(l>h) throw std::runtime_error("Invalid range");
        if(l>h) throw std::runtime_error("Invalid range");
}
}
 
 
void Range::assign(int h,int l) {
void Range::assign(int h,int l) {
        if(l>h) throw std::runtime_error("Invalid range");
        if(l>h) throw std::runtime_error("Invalid range");
        _high=h;
        _high=h;
        _low=l;
        _low=l;
        _valid=true;
        _valid=true;
}
}
 
 
void Range::clear() {
void Range::clear() {
        _valid=false;
        _valid=false;
}
}
 
 
bool Range::valid() const {
bool Range::valid() const {
        return _valid;
        return _valid;
}
}
 
 
int Range::high() const {
int Range::high() const {
        if(!_valid) throw std::runtime_error("Invalid range");
        if(!_valid) throw std::runtime_error("Invalid range");
        return _high;
        return _high;
}
}
 
 
int Range::low() const {
int Range::low() const {
        if(!_valid) throw std::runtime_error("Invalid range");
        if(!_valid) throw std::runtime_error("Invalid range");
        return _low;
        return _low;
}
}
 
 
int Range::length() const {
int Range::length() const {
        if(!_valid) throw std::runtime_error("Invalid range");
        if(!_valid) throw std::runtime_error("Invalid range");
        return _high-_low+1;
        return _high-_low+1;
}
}
 
 
std::string Range::toString() const {
std::string Range::toString() const {
        if(!_valid) throw std::runtime_error("Invalid range");
        if(!_valid) throw std::runtime_error("Invalid range");
        return std::to_string(_high)+" downto "+std::to_string(_low);
        return std::to_string(_high)+" downto "+std::to_string(_low);
}
}
 
 

powered by: WebSVN 2.1.0

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