C#版 バグベアード擬き プロファイルデータ構造部

とりあえずオリジナルのプロファイルデータ構造部をC#へ移植。

using System;
using System.Collections.Generic;
#if BUG_WITHOUT_LOCATION_INFO
#else
using System.Diagnostics;
#endif

public class bug_puppy
{
    ///////////////////////////////////////////////////////////////////////////
    //
    //  bug_profile_time_type
    //
    
    class bug_profile_time_type
    {
        public long value;
        
        public bug_profile_time_type(long a_value)
        {
            value = a_value;
        }
        public bug_profile_time_type(bug_profile_time_type a)
        {
            value = a.value;
        }
        
        public static long get_current_tick()
        {
            return DateTime.Now.Ticks;
        }
        
        public static long get_tick_resolution()
        {
            return 1000000;
        }
        public long get_sec()
        {
            //return value /get_tick_resolution();
            return value / 1000000;
        }
        public long get_usec()
        {
            //const long tick_resolution = get_tick_resolution();
            //const long scale = 1000000;
            //return ((value %tick_resolution) *scale) /tick_resolution;
            return value % 1000000;
        }
        
        public string get_string(string a)
        {
            if (0 <= value)
            {
                return string.Format
                (
                    "{0}.{1:D6}",
                    get_sec().ToString(),
                    get_usec().ToString()
                );
            }
            else
            {
                return string.Format("-{0}", new bug_profile_time_type(-value).get_string(a));
            }
        }
        public bool less_than(bug_profile_time_type a)
        {
            return value < a.value;
        }
    }
    
    
    ///////////////////////////////////////////////////////////////////////////
    //
    //  bug_profile_time_set, bug_profile_time_score, bug_profile_time_score_set
    //
    
    class bug_profile_time_set
    {
    
        public long whole_time;
        public long bug_time;
        public long work_time;
        
        public bug_profile_time_set()
        {
            whole_time = 0;
            bug_time = 0;
            work_time = 0;
        }
        public bug_profile_time_set(bug_profile_time_set a)
        {
            assign(a);
        }
        
        public bug_profile_time_type get_whole_time()
        {
            return new bug_profile_time_type(whole_time);
        }
        public bug_profile_time_type get_bug_time()
        {
            return new bug_profile_time_type(bug_time);
        }
        public bug_profile_time_type get_work_time()
        {
            return new bug_profile_time_type(work_time);
        }
        
        public string get_string(string separator)
        {
            return
                get_whole_time().get_string(separator) + separator
                + get_bug_time().get_string(separator) + separator
                + get_work_time().get_string(separator);
        }
        
        public bug_profile_time_type get_core_value()
        {
            return get_work_time();
        }
        public bool less_than(bug_profile_time_set a)
        {
            return get_core_value().less_than(a.get_core_value());
        }

        public bug_profile_time_set assign(bug_profile_time_set a)
        {
            whole_time = a.whole_time;
            bug_time = a.bug_time;
            work_time = a.work_time;
            return this;
        }
        public bug_profile_time_set add(bug_profile_time_set a)
        {
            whole_time += a.whole_time;
            bug_time += a.bug_time;
            work_time += a.work_time;
            return this;
        }
        public bug_profile_time_set div(long a)
        {
            whole_time /= a;
            bug_time /= a;
            work_time /= a;
            return this;
        }
    }

    class bug_profile_time_score
    {
    
        public bug_profile_time_set self_time_set;
        public bug_profile_time_set sub_time_set;
        
        public bug_profile_time_score()
        {
            self_time_set = new bug_profile_time_set();
            sub_time_set = new bug_profile_time_set();
        }
        public bug_profile_time_score(bug_profile_time_score a)
        {
            self_time_set = new bug_profile_time_set(a.self_time_set);
            sub_time_set = new bug_profile_time_set(a.sub_time_set);
        }
        
        public bug_profile_time_set get_all_time_set()
        {
            var result = new bug_profile_time_set(self_time_set);
            result.bug_time += sub_time_set.bug_time;
            result.work_time += sub_time_set.work_time;
            return result;
        }
        public bug_profile_time_set get_self_time_set()
        {
            return self_time_set;
        }
        public bug_profile_time_set get_sub_time_set()
        {
            return sub_time_set;
        }

        public string get_string(string separator)
        {
            return
                get_all_time_set().get_string(separator) + separator
                + get_self_time_set().get_string(separator) + separator
                + get_sub_time_set().get_string(separator);
        }

        public bug_profile_time_set get_core_value()
        {
            return get_all_time_set();
        }
        public bool less_than(bug_profile_time_score a)
        {
            return get_core_value().less_than(a.get_core_value());
        }

        public bug_profile_time_score assign(bug_profile_time_score a)
        {
            self_time_set.assign(a.self_time_set);
            sub_time_set.assign(a.sub_time_set);
            return this;
        }
        public bug_profile_time_score add(bug_profile_time_score a)
        {
            self_time_set.add(a.self_time_set);
            sub_time_set.add(a.sub_time_set);
            return this;
        }
        public bug_profile_time_score div(long a)
        {
            self_time_set.div(a);
            sub_time_set.div(a);
            return this;
        }
    };

    class bug_profile_time_score_set
    {
        public bug_profile_time_score total_score;
        public string min_begin_stamp;
        public bug_profile_time_score min_score;
        public string max_begin_stamp;
        public bug_profile_time_score max_score;
        public long count;
        
        public bug_profile_time_score_set()
        {
            total_score = new bug_profile_time_score();
            min_score = new bug_profile_time_score();
            max_score = new bug_profile_time_score();
            count = 0;
        }
        public bug_profile_time_score_set(bug_profile_time_score_set a)
        {
            total_score = new bug_profile_time_score(a.total_score);
            min_score = new bug_profile_time_score(a.min_score);
            max_score = new bug_profile_time_score(a.max_score);
            count = a.count;
        }

        public bug_profile_time_score get_total_score()
        {
            return total_score;
        }
        public bug_profile_time_score get_min_score()
        {
            return min_score;
        }
        public bug_profile_time_score get_max_score()
        {
            return max_score;
        }
        public bug_profile_time_score get_average_score()
        {
            if (0 != count)
            {
                return new bug_profile_time_score(get_total_score()).div(get_count());
            }
            else
            {
                return get_total_score();
            }
        }
        public long get_count()
        {
            return count;
        }

        public string get_string(string separator)
        {
            return
                get_total_score().get_string(separator) + separator
                + get_count().ToString() + separator
                + get_average_score().get_string(separator) + separator
                + min_begin_stamp + separator
                + get_min_score().get_string(separator) + separator
                + max_begin_stamp + separator
                + get_max_score().get_string(separator);
        }
        
        public void add_score(string a_begin_stamp, bug_profile_time_score a_time_score)
        {
            if (0 == get_count())
            {
                total_score.assign(a_time_score);
                set_min_score(a_begin_stamp, a_time_score);
                set_max_score(a_begin_stamp, a_time_score);
            }
            else
            {
                total_score.add(a_time_score);

                if (a_time_score.less_than(min_score))
                {
                    set_min_score(a_begin_stamp, a_time_score);
                }
                if (max_score.less_than(a_time_score))
                {
                    set_max_score(a_begin_stamp, a_time_score);
                }
            }
            ++count;
        }
        
        private void set_min_score(string a_begin_stamp, bug_profile_time_score a_time_score)
        {
            min_begin_stamp = a_begin_stamp;
            min_score.assign(a_time_score);
        }
        private void set_max_score(string a_begin_stamp, bug_profile_time_score a_time_score)
        {
            max_begin_stamp = a_begin_stamp;
            max_score.assign(a_time_score);
        }
    }

    // 省略

}