00001 // Filename: pStatViewLevel.cxx 00002 // Created by: drose (11Jul00) 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 "pStatViewLevel.h" 00016 #include "pStatClientData.h" 00017 00018 #include "pStatCollectorDef.h" 00019 #include "pnotify.h" 00020 00021 #include <algorithm> 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Function: PStatViewLevel::get_net_value 00025 // Access: Public 00026 // Description: Returns the total level value (or elapsed time) 00027 // represented by this Collector, including all values 00028 // in its child Collectors. 00029 //////////////////////////////////////////////////////////////////// 00030 double PStatViewLevel:: 00031 get_net_value() const { 00032 double net = _value_alone; 00033 00034 Children::const_iterator ci; 00035 for (ci = _children.begin(); ci != _children.end(); ++ci) { 00036 net += (*ci)->get_net_value(); 00037 } 00038 00039 return net; 00040 } 00041 00042 00043 // STL function object for sorting children in order by the 00044 // collector's sort index, used in sort_children(), below. 00045 class SortCollectorLevels { 00046 public: 00047 SortCollectorLevels(const PStatClientData *client_data) : 00048 _client_data(client_data) { 00049 } 00050 bool operator () (const PStatViewLevel *a, const PStatViewLevel *b) const { 00051 return 00052 _client_data->get_collector_def(a->get_collector())._sort > 00053 _client_data->get_collector_def(b->get_collector())._sort; 00054 } 00055 const PStatClientData *_client_data; 00056 }; 00057 00058 //////////////////////////////////////////////////////////////////// 00059 // Function: PStatViewLevel::sort_children 00060 // Access: Public 00061 // Description: Sorts the children of this view level into order as 00062 // specified by the client's sort index. 00063 //////////////////////////////////////////////////////////////////// 00064 void PStatViewLevel:: 00065 sort_children(const PStatClientData *client_data) { 00066 SortCollectorLevels sort_levels(client_data); 00067 00068 sort(_children.begin(), _children.end(), sort_levels); 00069 } 00070 00071 //////////////////////////////////////////////////////////////////// 00072 // Function: PStatViewLevel::get_num_children 00073 // Access: Public 00074 // Description: Returns the number of children of this 00075 // Level/Collector. These are the Collectors whose 00076 // value is considered to be part of the total value of 00077 // this level's Collector. 00078 //////////////////////////////////////////////////////////////////// 00079 int PStatViewLevel:: 00080 get_num_children() const { 00081 return _children.size(); 00082 } 00083 00084 //////////////////////////////////////////////////////////////////// 00085 // Function: PStatViewLevel::get_child 00086 // Access: Public 00087 // Description: Returns the nth child of this Level/Collector. 00088 //////////////////////////////////////////////////////////////////// 00089 const PStatViewLevel *PStatViewLevel:: 00090 get_child(int n) const { 00091 nassertr(n >= 0 && n < (int)_children.size(), NULL); 00092 return _children[n]; 00093 }