1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-  */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef _MORKYARN_
7 #define _MORKYARN_ 1
8 
9 #ifndef _MORK_
10 #  include "mork.h"
11 #endif
12 
13 // 456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
14 
15 #define morkDerived_kYarn /*i*/ 0x7952 /* ascii 'yR' */
16 
17 /*| morkYarn: a reference counted nsIMdbYarn C struct.  This is for use in those
18 **| few cases where single instances of reference counted buffers are needed
19 **| in Mork, and we expect few enough instances that overhead is not a factor
20 **| in decided whether to use such a thing.
21 |*/
22 class morkYarn : public morkNode {  // refcounted yarn
23 
24   // public: // slots inherited from morkNode (meant to inform only)
25   // nsIMdbHeap*       mNode_Heap;
26 
27   // mork_base      mNode_Base;     // must equal morkBase_kNode
28   // mork_derived   mNode_Derived;  // depends on specific node subclass
29 
30   // mork_access    mNode_Access;   // kOpen, kClosing, kShut, or kDead
31   // mork_usage     mNode_Usage;    // kHeap, kStack, kMember, kGlobal, kNone
32   // mork_able      mNode_Mutable;  // can this node be modified?
33   // mork_load      mNode_Load;     // is this node clean or dirty?
34 
35   // mork_uses      mNode_Uses;     // refcount for strong refs
36   // mork_refs      mNode_Refs;     // refcount for strong refs + weak refs
37 
38  public:  // state is public because the entire Mork system is private
39   mdbYarn mYarn_Body;
40 
41   // { ===== begin morkNode interface =====
42  public:                                             // morkNode virtual methods
43   virtual void CloseMorkNode(morkEnv* ev) override;  // CloseYarn() only if open
44   virtual ~morkYarn();  // assert that CloseYarn() executed earlier
45 
46  public:  // morkYarn construction & destruction
47   morkYarn(morkEnv* ev, const morkUsage& inUsage, nsIMdbHeap* ioHeap);
48   void CloseYarn(morkEnv* ev);  // called by CloseMorkNode();
49 
50  private:  // copying is not allowed
51   morkYarn(const morkYarn& other);
52   morkYarn& operator=(const morkYarn& other);
53 
54  public:  // dynamic type identification
IsYarn()55   mork_bool IsYarn() const {
56     return IsNode() && mNode_Derived == morkDerived_kYarn;
57   }
58   // } ===== end morkNode methods =====
59 
60  public:  // typing
61   static void NonYarnTypeError(morkEnv* ev);
62 
63  public:  // typesafe refcounting inlines calling inherited morkNode methods
SlotWeakYarn(morkYarn * me,morkEnv * ev,morkYarn ** ioSlot)64   static void SlotWeakYarn(morkYarn* me, morkEnv* ev, morkYarn** ioSlot) {
65     morkNode::SlotWeakNode((morkNode*)me, ev, (morkNode**)ioSlot);
66   }
67 
SlotStrongYarn(morkYarn * me,morkEnv * ev,morkYarn ** ioSlot)68   static void SlotStrongYarn(morkYarn* me, morkEnv* ev, morkYarn** ioSlot) {
69     morkNode::SlotStrongNode((morkNode*)me, ev, (morkNode**)ioSlot);
70   }
71 };
72 
73 // 456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
74 
75 #endif /* _MORKYARN_ */
76