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

Subversion Repositories lxp32

[/] [lxp32/] [trunk/] [tools/] [src/] [lxp32asm/] [utils.h] - 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 declares the members of the Utils namespace.
7
 */
8
 
9
#ifndef UTILS_H_INCLUDED
10
#define UTILS_H_INCLUDED
11
 
12
#include <string>
13
#include <type_traits>
14
 
15
namespace Utils {
16
        template <typename T> std::string hex(const T &w) {
17
                static_assert(std::is_integral<T>::value,"Argument must be of integral type");
18
                const char *hexstr="0123456789ABCDEF";
19
                std::string res;
20
 
21
                res.reserve(sizeof(T)*2);
22
 
23
                for(int i=sizeof(T)*8-4;i>=0;i-=4) {
24
                        res.push_back(hexstr[(w>>i)&0x0F]);
25
                }
26
                return res;
27
        }
28
 
29
        template <typename T> std::string bin(const T &w) {
30
                static_assert(std::is_integral<T>::value,"Argument must be of integral type");
31
                std::string res;
32
 
33
                res.reserve(sizeof(T)*8);
34
 
35
                for(int i=sizeof(T)*8-1;i>=0;i--) {
36
                        if(((w>>i)&1)!=0) res.push_back('1');
37
                        else res.push_back('0');
38
                }
39
                return res;
40
        }
41
 
42
        std::string urlEncode(const std::string &str);
43
        std::string urlDecode(const std::string &str);
44
 
45
        std::string normalizeSeparators(const std::string &path);
46
        std::string nativeSeparators(const std::string &path);
47
        bool isAbsolutePath(const std::string &path);
48
        bool fileExists(const std::string &path);
49
        std::string relativePath(const std::string &from,const std::string &to);
50
 
51
        std::string dequoteString(const std::string &str);
52
 
53
        bool ishexdigit(char ch);
54
        bool isoctdigit(char ch);
55
 
56
        template <typename T> bool isPowerOf2(const T &x) {
57
                static_assert(std::is_integral<T>::value,"Argument must be of integral type");
58
                return (x!=0)&&((x&(x-1))==0);
59
        }
60
}
61
 
62
#endif

powered by: WebSVN 2.1.0

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