WvStreams
pwvstream.h
1 /* -*- Mode: C++ -*-
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  */
5 #ifndef __PWVSTREAM_H
6 #define __PWVSTREAM_H
7 
8 #include "iwvstream.h"
9 #include "wvstream.h" // FIXME: don't include this!
10 #include "wvstreamclone.h" // FIXME: don't include this!
11 #include "wvmoniker.h"
12 #include "wvtr1.h"
13 
36 class PWvStream : public wv::shared_ptr<WvStream>
37 {
38  static WvStream *clean_stream(IWvStream *s)
39  {
40  WvStream *ss = dynamic_cast<WvStream *>(s);
41  if (ss)
42  return ss;
43  else
44  return new WvStreamClone(s);
45  }
46 
47  static WvStream *make_stream(WvStringParm moniker, IObject *obj)
48  {
49  IWvStream *s = IWvStream::create(moniker, obj);
50  if (!s)
51  s = wvcreate<IWvStream>("null:");
52  assert(s != NULL);
53  return clean_stream(s);
54  }
55 
56 public:
57  PWvStream()
58  {
59  // Pointer points to NULL right now, but it could be reassigned
60  // later using operator=().
61  }
62 
64  : wv::shared_ptr<WvStream>(clean_stream(s),
65  wv::bind(&IWvStream::release, _1))
66  {
67  }
68 
69  PWvStream(WvStringParm moniker, IObject *obj = 0)
70  : wv::shared_ptr<WvStream>(make_stream(moniker, obj),
71  wv::bind(&IWvStream::release, _1))
72  {
73  // Note: pointer is definitely not NULL here, because make_stream is
74  // careful.
75  }
76 
77  WvStream *addRef() const
78  {
79  if (get())
80  get()->addRef();
81  return get();
82  }
83 };
84 
85 #endif // __PWVSTREAM_H
IWvStream
Definition: iwvstream.h:24
get
Interface * get(IObject *aObj)
XPLC equivalent to dynamic_cast.
Definition: utils.h:184
PWvStream
PWvStream is a smart pointer to an IWvStream object.
Definition: pwvstream.h:36
IObject::release
virtual unsigned int release()=0
Indicate that you are finished using this object.
WvStreamClone
WvStreamClone simply forwards all requests to the "cloned" stream.
Definition: wvstreamclone.h:23
IObject
Definition: IObject.h:65
WvStream
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
Definition: wvstream.h:24