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

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:  protected:
                     17:        union union_ptr {
                     18:                uint8 *b;
                     19:                uint16 *w;
                     20:                uint32 *l;
                     21:        };
                     22: 
                     23:  public:
                     24:        // コンストラクタ
                     25:        MemoryStreamBE() {
                     26:        }
                     27:        MemoryStreamBE(void *p) {
                     28:                SetPtr(p);
                     29:        }
                     30:        // デストラクタ不要
                     31: 
                     32:        // ポインタを設定する
                     33:        void SetPtr(void *p) {
                     34:                ptr.b = (uint8 *)p;
                     35:        }
                     36: 
                     37:        // ポインタを取得する
                     38:        void *GetPtr() const {
                     39:                return (void *)ptr.b;
                     40:        }
                     41: 
                     42:        // 1バイト読み込んでポインタを進める
                     43:        uint32 Read8() {
                     44:                uint32 data = *ptr.b++;
                     45:                return data;
                     46:        }
                     47:        // BE で2バイト読み込んでポインタを進める
                     48:        uint32 Read16() {
                     49:                uint32 data = *ptr.w++;
                     50:                return be16toh(data);
                     51:        }
                     52:        // BE で4バイト読み込んでポインタを進める
                     53:        uint32 Read32() {
                     54:                uint32 data = *ptr.l++;
                     55:                return be32toh(data);
                     56:        }
                     57: 
                     58:        // 1バイト書き込んでポインタを進める
                     59:        void Write8(uint32 data) {
                     60:                *ptr.b++ = data;
                     61:        }
                     62:        // BE で2バイト書き込んでポインタを進める
                     63:        void Write16(uint32 data) {
                     64:                *ptr.w++ = htobe16(data);
                     65:        }
                     66:        // BE で4バイト書き込んでポインタを進める
                     67:        void Write32(uint32 data) {
                     68:                *ptr.l++ = htobe32(data);
                     69:        }
                     70: 
                     71:  private:
                     72:        union_ptr ptr {};
                     73: };

unix.superglobalmegacorp.com

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