Panda3D
 All Classes Functions Variables Enumerations
typedWritableReferenceCount.cxx
1 // Filename: typedWritableReferenceCount.cxx
2 // Created by: jason (08Jun00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "typedWritableReferenceCount.h"
16 #include "dcast.h"
17 
18 TypeHandle TypedWritableReferenceCount::_type_handle;
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: TypedWritableReferenceCount::as_reference_count
22 // Access: Public, Virtual
23 // Description: Returns the pointer cast to a ReferenceCount pointer,
24 // if it is in fact of that type.
25 ////////////////////////////////////////////////////////////////////
28  return this;
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: TypedWritableReferenceCount::decode_from_bam_stream
33 // Access: Published, Static
34 // Description: Reads the string created by a previous call to
35 // encode_to_bam_stream(), and extracts and returns the
36 // single object on that string. Returns NULL on error.
37 //
38 // This method is intended to replace
39 // decode_raw_from_bam_stream() when you know the stream
40 // in question returns an object of type
41 // TypedWritableReferenceCount, allowing for easier
42 // reference count management. Note that the caller is
43 // still responsible for maintaining the reference count
44 // on the return value.
45 ////////////////////////////////////////////////////////////////////
47 decode_from_bam_stream(const string &data, BamReader *reader) {
48  TypedWritable *object;
49  ReferenceCount *ref_ptr;
50 
51  if (!TypedWritable::decode_raw_from_bam_stream(object, ref_ptr, data, reader)) {
52  return NULL;
53  }
54 
55  return DCAST(TypedWritableReferenceCount, object);
56 }
virtual ReferenceCount * as_reference_count()
Returns the pointer cast to a ReferenceCount pointer, if it is in fact of that type.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
static bool decode_raw_from_bam_stream(TypedWritable *&ptr, ReferenceCount *&ref_ptr, const string &data, BamReader *reader=NULL)
Reads the string created by a previous call to encode_to_bam_stream(), and extracts the single object...
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
A base class for all things that want to be reference-counted.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85