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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [common/] [autobuffer.h] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 sergeykhbr
/*
2
 *  Copyright 2018 Sergey Khabarov, sergeykhbr@gmail.com
3
 *
4
 *  Licensed under the Apache License, Version 2.0 (the "License");
5
 *  you may not use this file except in compliance with the License.
6
 *  You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *  Unless required by applicable law or agreed to in writing, software
11
 *  distributed under the License is distributed on an "AS IS" BASIS,
12
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *  See the License for the specific language governing permissions and
14
 *  limitations under the License.
15
 */
16
 
17
#ifndef __DEBUGGER_AUTOBUFFER_H__
18
#define __DEBUGGER_AUTOBUFFER_H__
19
 
20
#include <stdint.h>
21
#include <string.h>
22
 
23
namespace debugger {
24
 
25
/**
26
 * @brief String buffer declaration.
27
 * @details This buffer is used to form configuration string of the kernel.
28
 */
29
class AutoBuffer {
30
 public:
31
    /** Create empty string buffer. */
32
    AutoBuffer();
33
    ~AutoBuffer();
34
 
35
    /**
36
     * @brief Write input data of the specified size into buffer's memory.
37
     * @param[in] p Pointer on input data.
38
     * @param[in] sz Input buffer size in bytes.
39
     */
40
    void write_bin(const char *p, int sz);
41
    /**
42
     * @brief Write single symbol into buffer's memory.
43
     * @param[in] s Input character value.
44
     */
45
    void write_string(const char s);
46
    /**
47
     * @brief Write input string into buffer's memory.
48
     * @param[in] s Pointer on string buffer.
49
     */
50
    void write_string(const char *s);
51
    /**
52
     * @brief Write integer value as a hex string into buffer's memory.
53
     * @param[in] s Input integer value.
54
     */
55
    void write_uint64(uint64_t v);
56
    /**
57
     * @brief Write a single byte into buffer's memory.
58
     * @details This method is very usefull to write special characters, like
59
     *          '\0', '\n' etc.
60
     * @param[in] s Input byte value.
61
     */
62
    void write_byte(uint8_t v);
63
 
64
    /**
65
     * @brief Get allocated memory pointer.
66
     * @return Pointer on allocated memory region.
67
     */
68
    char *getBuffer() { return buf_; }
69
 
70
    /** Get total number of written symbols. */
71
    int size() { return buf_len_; }
72
    /** Reset buffer's value. */
73
    void clear() {
74
        buf_len_ = 0;
75
        if (buf_) {
76
            buf_[buf_len_] = 0;
77
        }
78
    }
79
 
80
 private:
81
    char *buf_;
82
    int buf_len_;
83
    int buf_size_;
84
};
85
 
86
}  // namespace debugger
87
 
88
#endif  // __DEBUGGER_AUTOBUFFER_H__

powered by: WebSVN 2.1.0

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