Annotation of nono/lib/memorystream.h, revision 1.1.1.3

1.1       root        1: //
                      2: // nono
1.1.1.2   root        3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
                      7: #pragma once
                      8: 
                      9: #include "header.h"
                     10: 
                     11: // ホストのメモリ領域に対するストリームクラスみたいなもの。
                     12: // データの受け渡しはホストエンディアンで、
                     13: // アクセスはビッグエンディアンになる。
                     14: class MemoryStreamBE
                     15: {
                     16:  public:
                     17:        // コンストラクタ
                     18:        MemoryStreamBE() {
                     19:        }
                     20:        MemoryStreamBE(void *p) {
                     21:                SetPtr(p);
                     22:        }
                     23:        // デストラクタ不要
                     24: 
                     25:        // ポインタを設定する
                     26:        void SetPtr(void *p) {
1.1.1.3 ! root       27:                ptr = (uint8 *)p;
1.1       root       28:        }
                     29: 
                     30:        // ポインタを取得する
                     31:        void *GetPtr() const {
1.1.1.3 ! root       32:                return (void *)ptr;
1.1       root       33:        }
                     34: 
                     35:        // 1バイト読み込んでポインタを進める
                     36:        uint32 Read8() {
1.1.1.3 ! root       37:                uint32 data = *ptr++;
1.1       root       38:                return data;
                     39:        }
                     40:        // BE で2バイト読み込んでポインタを進める
                     41:        uint32 Read16() {
1.1.1.3 ! root       42:                uint32 data;
        !            43:                data  = Read8() << 8;
        !            44:                data |= Read8();
        !            45:                return data;
1.1       root       46:        }
                     47:        // BE で4バイト読み込んでポインタを進める
                     48:        uint32 Read32() {
1.1.1.3 ! root       49:                uint32 data;
        !            50:                data  = Read16() << 16;
        !            51:                data |= Read16();
        !            52:                return data;
1.1       root       53:        }
                     54: 
                     55:        // 1バイト書き込んでポインタを進める
                     56:        void Write8(uint32 data) {
1.1.1.3 ! root       57:                *ptr++ = data;
1.1       root       58:        }
                     59:        // BE で2バイト書き込んでポインタを進める
                     60:        void Write16(uint32 data) {
1.1.1.3 ! root       61:                Write8(data >> 8);
        !            62:                Write8(data & 0xff);
1.1       root       63:        }
                     64:        // BE で4バイト書き込んでポインタを進める
                     65:        void Write32(uint32 data) {
1.1.1.3 ! root       66:                Write16(data >> 16);
        !            67:                Write16(data & 0xffff);
1.1       root       68:        }
                     69: 
                     70:  private:
1.1.1.3 ! root       71:        uint8 *ptr {};
1.1       root       72: };

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.