00001 // Filename: pStatViewLevel.cxx00002 // Created by: drose (11Jul00)00003 //00004 ////////////////////////////////////////////////////////////////////00005 //00006 // PANDA 3D SOFTWARE00007 // Copyright (c) Carnegie Mellon University. All rights reserved.00008 //00009 // All use of this software is subject to the terms of the revised BSD00010 // license. You should have received a copy of this license along00011 // 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_value00025 // Access: Public00026 // Description: Returns the total level value (or elapsed time)00027 // represented by this Collector, including all values00028 // in its child Collectors.00029 ////////////////////////////////////////////////////////////////////00030 doublePStatViewLevel::00031get_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 the00044 // collector's sort index, used in sort_children(), below.00045class SortCollectorLevels {
00046 public:
00047 SortCollectorLevels(constPStatClientData *client_data) :
00048 _client_data(client_data) {
00049 }
00050 bool operator () (constPStatViewLevel *a, constPStatViewLevel *b) const {
00051 return00052 _client_data->get_collector_def(a->get_collector())._sort >
00053 _client_data->get_collector_def(b->get_collector())._sort;
00054 }
00055 constPStatClientData *_client_data;
00056 };
00057
00058 ////////////////////////////////////////////////////////////////////00059 // Function: PStatViewLevel::sort_children00060 // Access: Public00061 // Description: Sorts the children of this view level into order as00062 // specified by the client's sort index.00063 ////////////////////////////////////////////////////////////////////00064 voidPStatViewLevel::00065sort_children(constPStatClientData *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_children00073 // Access: Public00074 // Description: Returns the number of children of this00075 // Level/Collector. These are the Collectors whose00076 // value is considered to be part of the total value of00077 // this level's Collector.00078 ////////////////////////////////////////////////////////////////////00079 intPStatViewLevel::00080get_num_children() const {
00081 return _children.size();
00082 }
00083
00084 ////////////////////////////////////////////////////////////////////00085 // Function: PStatViewLevel::get_child00086 // Access: Public00087 // Description: Returns the nth child of this Level/Collector.00088 ////////////////////////////////////////////////////////////////////00089 constPStatViewLevel *PStatViewLevel::00090get_child(int n) const {
00091 nassertr(n >= 0 && n < (int)_children.size(), NULL);
00092 return _children[n];
00093 }