00001 // Filename: typedWritableReferenceCount.cxx 00002 // Created by: jason (08Jun00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "typedWritableReferenceCount.h" 00016 00017 TypeHandle TypedWritableReferenceCount::_type_handle; 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function: TypedWritableReferenceCount::as_reference_count 00021 // Access: Public, Virtual 00022 // Description: Returns the pointer cast to a ReferenceCount pointer, 00023 // if it is in fact of that type. 00024 //////////////////////////////////////////////////////////////////// 00025 ReferenceCount *TypedWritableReferenceCount:: 00026 as_reference_count() { 00027 return this; 00028 } 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: TypedWritableReferenceCount::decode_from_bam_stream 00032 // Access: Published, Static 00033 // Description: Reads the string created by a previous call to 00034 // encode_to_bam_stream(), and extracts and returns the 00035 // single object on that string. Returns NULL on error. 00036 // 00037 // This method is intended to replace 00038 // decode_raw_from_bam_stream() when you know the stream 00039 // in question returns an object of type 00040 // TypedWritableReferenceCount, allowing for easier 00041 // reference count management. Note that the caller is 00042 // still responsible for maintaining the reference count 00043 // on the return value. 00044 //////////////////////////////////////////////////////////////////// 00045 PT(TypedWritableReferenceCount) TypedWritableReferenceCount:: 00046 decode_from_bam_stream(const string &data, BamReader *reader) { 00047 TypedWritable *object; 00048 ReferenceCount *ref_ptr; 00049 00050 if (!TypedWritable::decode_raw_from_bam_stream(object, ref_ptr, data, reader)) { 00051 return NULL; 00052 } 00053 00054 return DCAST(TypedWritableReferenceCount, object); 00055 }