www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3341] New: Dummy stream

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3341

           Summary: Dummy stream
           Product: D
           Version: 2.032
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: dsimcha yahoo.com


--- Comment #0 from David Simcha <dsimcha yahoo.com> 2009-09-22 11:24:25 PDT ---
If std.stream is going to stay around much longer (not necessarily
recommended), a simple but useful enhancement would be to include a dummy
output stream, similar to /dev/null.  This would be useful when a function or
block of code expects an output stream, and you want to simply dispose of the
output.

If std.stream is going to be deprecated in the foreseeable future, then
whatever replaces it should have this feature.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 22 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3341


David Simcha <dsimcha yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #1 from David Simcha <dsimcha yahoo.com> 2009-09-22 11:44:14 PDT ---
This should do the job.  I tested that it compiles, and it's pretty hard to
have a logic error given that it's supposed to do nothing.  Just to make it
explicit, I hereby release the DummyStream class into the public domain, if
it's even copyrightable.

/**A dummy stream for disposing of output.  Supports the interface of an
 * OutputStream, simply does nothing for any method call.*/
class DummyStream : OutputStream {
    this() {}

    void writeExact(const void* buffer, size_t size){}
    size_t write(const(ubyte)[] buffer) { return buffer.length; }
    void write(byte x) {}
    void write(ubyte x) {}
    void write(short x) {}
    void write(ushort x) {}
    void write(int x) {}
    void write(uint x) {}
    void write(long x) {}
    void write(ulong x) {}
    void write(float x) {}
    void write(double x) {}
    void write(real x) {}
    void write(ifloat x) {}
    void write(idouble x) {}
    void write(ireal x) {}
    void write(cfloat x) {}
    void write(cdouble x) {}
    void write(creal x) {}
    void write(char x) {}
    void write(wchar x) {}
    void write(dchar x) {}
    void write(char[] s) {}
    void write(const(wchar)[] s) {}
    void writeLine(const(char)[] s) {}
    void writeLineW(const(wchar)[] s) {}
    void writeString(const(char)[] s) {}
    void writeStringW(const(wchar)[] s) {}
    size_t vprintf(char[] format, va_list args) { return 0; }
    size_t printf(char[] format, ...) { return 0; }
    OutputStream writef(...) { return this;}
    OutputStream writefln(...) { return this; }
    OutputStream writefx(TypeInfo[] arguments, void* argptr, int newline =
false) {
      return this;
    }
    void flush() {}
    void close() {}
    bool isOpen() { return true; }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 22 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3341


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


--- Comment #2 from Andrei Alexandrescu <andrei metalanguage.com> 2009-09-22
12:12:40 PDT ---
Thanks! The patch pretty much shows the age of the stream design...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 22 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3341


BCS <shro8822 vandals.uidaho.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |shro8822 vandals.uidaho.edu


--- Comment #3 from BCS <shro8822 vandals.uidaho.edu> 2009-09-22 12:40:52 PDT
---
(In reply to comment #1)
     size_t vprintf(char[] format, va_list args) { return 0; }
     size_t printf(char[] format, ...) { return 0; }

I'd think this should return the same as the function in the other classes do. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 22 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3341



--- Comment #4 from David Simcha <dsimcha yahoo.com> 2009-09-22 13:08:50 PDT ---
(In reply to comment #3)
 (In reply to comment #1)
     size_t vprintf(char[] format, va_list args) { return 0; }
     size_t printf(char[] format, ...) { return 0; }

I'd think this should return the same as the function in the other classes do.

I agree in principle, except that then you would have to do the whole formatting just to figure out what that number should be. This seems wasteful. I consider it to be a minor detail anyhow, since really, who the heck still uses vprintf and printf? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 22 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3341



--- Comment #5 from Sobirari Muhomori <maxmo pochta.ru> 2009-09-25 06:05:16 PDT
---
Hack.

    size_t vprintf(char[] format, va_list args) { return format.length; }
    size_t printf(char[] format, ...) { return format.length; }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 25 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3341


David Simcha <dsimcha yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |WONTFIX


--- Comment #6 from David Simcha <dsimcha yahoo.com> 2010-06-17 18:23:05 PDT ---
I'm resolving this as WONTFIX because we've decided std.stream is going the way
of the dodo.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 17 2010