Panda3D
|
00001 // Filename: bufferContextChain.cxx 00002 // Created by: drose (16Mar06) 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 "bufferContextChain.h" 00016 #include "bufferContext.h" 00017 #include "indent.h" 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function: BufferContextChain::get_first 00021 // Access: Public 00022 // Description: Returns the first BufferContext object stored in the 00023 // tracker. You can walk through the entire list of 00024 // objects stored on the tracker by calling get_next() 00025 // on each returned object, until the return value is 00026 // NULL. 00027 //////////////////////////////////////////////////////////////////// 00028 BufferContext *BufferContextChain:: 00029 get_first() { 00030 // This method is declared non-inline so we can include 00031 // bufferContext.h, which is necessary for proper downcasting of the 00032 // _next pointer. 00033 if (_next == this) { 00034 return NULL; 00035 } 00036 return (BufferContext *)_next; 00037 } 00038 00039 //////////////////////////////////////////////////////////////////// 00040 // Function: BufferContextChain::take_from 00041 // Access: Public 00042 // Description: Moves all of the BufferContexts from the other 00043 // tracker onto this one. 00044 //////////////////////////////////////////////////////////////////// 00045 void BufferContextChain:: 00046 take_from(BufferContextChain &other) { 00047 _total_size += other._total_size; 00048 _count += other._count; 00049 other._total_size = 0; 00050 other._count = 0; 00051 00052 LinkedListNode *llnode = other._next; 00053 while (llnode != &other) { 00054 nassertv(((BufferContext *)llnode)->_owning_chain == &other); 00055 ((BufferContext *)llnode)->_owning_chain = this; 00056 llnode = ((BufferContext *)llnode)->_next; 00057 } 00058 00059 take_list_from(&other); 00060 } 00061 00062 //////////////////////////////////////////////////////////////////// 00063 // Function: BufferContextChain::write 00064 // Access: Public 00065 // Description: 00066 //////////////////////////////////////////////////////////////////// 00067 void BufferContextChain:: 00068 write(ostream &out, int indent_level) const { 00069 indent(out, indent_level) 00070 << _count << " objects, consuming " << _total_size << " bytes:\n"; 00071 00072 LinkedListNode *llnode = _next; 00073 while (llnode != this) { 00074 ((BufferContext *)llnode)->write(out, indent_level + 2); 00075 llnode = ((BufferContext *)llnode)->_next; 00076 } 00077 }