# Path: gtimer/local/stack.py
# class Stack(object):
# 
#     def __init__(self, obj_class):
#         self.stack = []
#         self.obj_class = obj_class
# 
#     def create_next(self, *args, **kwargs):
#         self.stack.append(self.obj_class(*args, **kwargs))
#         return self.stack_return()
# 
#     def remove_last(self):
#         try:
#             self.stack.pop()
#         except IndexError:
#             pass
#         finally:
#             return self.stack_return()
# 
#     def stack_return(self):
#         current = None if len(self) < 1 else self[-1]
#         previous = None if len(self) < 2 else self[-2]
#         return current, previous
# 
#     def __len__(self):
#         return len(self.stack)
# 
#     def __getitem__(self, key):
#         return self.stack[key]
# 
# Path: gtimer/local/timer.py
# class Timer(object):
#     """ Current (temporary) values describing state of timer.
#     (Disappears or irrelevant after timing is complete.)
#     """
# 
#     def __init__(self,
#                  name,
#                  rgstr_stamps=None,
#                  dump=None,
#                  is_named_loop=False,
#                  in_loop=False,
#                  **kwargs):
#         self.name = str(name)
#         self.rgstr_stamps = rgstr_stamps if rgstr_stamps is not None else list()
#         self.dump = dump  # refers to a Times instance, not a Timer instance
#         self.is_named_loop = is_named_loop  # needed for copying dump and self agg
#         self.in_loop = bool(in_loop)
#         self.times = None
#         self.is_user_subdvsn = False
#         self.reset()
#         self.times = Times(name, **kwargs)
# 
#     def __deepcopy__(self, memo):
#         new = type(self)(self.name)
#         new.__dict__.update(self.__dict__)
#         new.subdvsn_awaiting = copy.deepcopy(self.subdvsn_awaiting, memo)
#         new.par_subdvsn_awaiting = copy.deepcopy(self.par_subdvsn_awaiting, memo)
#         for sub_times in itervalues(new.subdvsn_awaiting):
#             sub_times.parent = new.times
#         for sub_list in itervalues(new.par_subdvsn_awaiting):
#             for sub_times in sub_list:
#                 sub_times.parent = new.times
#         new.times = copy.deepcopy(self.times, memo)
#         # Dump needs rest of stack, see mgmt_priv.copy_timer_stack()
#         new.dump = None
#         return new
# 
#     def reset(self):
#         self.stopped = False
#         self.paused = False
#         self.tmp_total = 0.
#         self.self_cut = 0.
#         self.subdvsn_awaiting = dict()
#         self.par_subdvsn_awaiting = dict()
#         self.start_t = timer()
#         self.last_t = self.start_t
#         if self.times is not None:
#             self.times.reset()
# 
# Path: gtimer/local/loop.py
# class Loop(object):
#     """Hold info for name checking and assigning."""
# 
#     def __init__(self, name=None, rgstr_stamps=None, save_itrs=True):
#         self.name = None if name is None else str(name)
#         self.stamps = list()
#         self.rgstr_stamps = rgstr_stamps
#         self.itr_stamp_used = dict()
#         self.save_itrs = save_itrs
#         self.itr_stamps = dict()
#         self.first_itr = True


from gtimer.local.stack import Stack
from gtimer.local.timer import Timer
from gtimer.local.loop import Loop
    sm1 = None if rm1 is None else rm1.stamps


def create_next_loop(*args, **kwargs):
    global lp
    lp, _ = loop_stack.create_next(*args, **kwargs)


def remove_last_loop():
    global lp
    lp, _ = loop_stack.remove_last()


def refresh_shortcuts():
    global t, r, s, tm1, rm1, sm1, lp
    t, tm1 = timer_stack.stack_return()
    r = None if t is None else t.times
    s = None if r is None else r.stamps
    rm1 = None if tm1 is None else tm1.times
    sm1 = None if rm1 is None else rm1.stamps
    lp, _ = loop_stack.stack_return()


#
# Initialization.
#

def hard_reset():
    global timer_stack, loop_stack, root, lp
    timer_stack = Stack(Timer)

# Path: gtimer/local/stack.py
# class Stack(object):
# 
#     def __init__(self, obj_class):
#         self.stack = []
#         self.obj_class = obj_class
# 
#     def create_next(self, *args, **kwargs):
#         self.stack.append(self.obj_class(*args, **kwargs))
#         return self.stack_return()
# 
#     def remove_last(self):
#         try:
#             self.stack.pop()
#         except IndexError:
#             pass
#         finally:
#             return self.stack_return()
# 
#     def stack_return(self):
#         current = None if len(self) < 1 else self[-1]
#         previous = None if len(self) < 2 else self[-2]
#         return current, previous
# 
#     def __len__(self):
#         return len(self.stack)
# 
#     def __getitem__(self, key):
#         return self.stack[key]
# 
# Path: gtimer/local/timer.py
# class Timer(object):
#     """ Current (temporary) values describing state of timer.
#     (Disappears or irrelevant after timing is complete.)
#     """
# 
#     def __init__(self,
#                  name,
#                  rgstr_stamps=None,
#                  dump=None,
#                  is_named_loop=False,
#                  in_loop=False,
#                  **kwargs):
#         self.name = str(name)
#         self.rgstr_stamps = rgstr_stamps if rgstr_stamps is not None else list()
#         self.dump = dump  # refers to a Times instance, not a Timer instance
#         self.is_named_loop = is_named_loop  # needed for copying dump and self agg
#         self.in_loop = bool(in_loop)
#         self.times = None
#         self.is_user_subdvsn = False
#         self.reset()
#         self.times = Times(name, **kwargs)
# 
#     def __deepcopy__(self, memo):
#         new = type(self)(self.name)
#         new.__dict__.update(self.__dict__)
#         new.subdvsn_awaiting = copy.deepcopy(self.subdvsn_awaiting, memo)
#         new.par_subdvsn_awaiting = copy.deepcopy(self.par_subdvsn_awaiting, memo)
#         for sub_times in itervalues(new.subdvsn_awaiting):
#             sub_times.parent = new.times
#         for sub_list in itervalues(new.par_subdvsn_awaiting):
#             for sub_times in sub_list:
#                 sub_times.parent = new.times
#         new.times = copy.deepcopy(self.times, memo)
#         # Dump needs rest of stack, see mgmt_priv.copy_timer_stack()
#         new.dump = None
#         return new
# 
#     def reset(self):
#         self.stopped = False
#         self.paused = False
#         self.tmp_total = 0.
#         self.self_cut = 0.
#         self.subdvsn_awaiting = dict()
#         self.par_subdvsn_awaiting = dict()
#         self.start_t = timer()
#         self.last_t = self.start_t
#         if self.times is not None:
#             self.times.reset()
# 
# Path: gtimer/local/loop.py
# class Loop(object):
#     """Hold info for name checking and assigning."""
# 
#     def __init__(self, name=None, rgstr_stamps=None, save_itrs=True):
#         self.name = None if name is None else str(name)
#         self.stamps = list()
#         self.rgstr_stamps = rgstr_stamps
#         self.itr_stamp_used = dict()
#         self.save_itrs = save_itrs
#         self.itr_stamps = dict()
#         self.first_itr = True


# Path: gtimer/private/focus.py
from gtimer.local.stack import Stack
from gtimer.local.timer import Timer
from gtimer.local.loop import Loop

    sm1 = None if rm1 is None else rm1.stamps


def create_next_loop(*args, **kwargs):
    global lp
    lp, _ = loop_stack.create_next(*args, **kwargs)


def remove_last_loop():
    global lp
    lp, _ = loop_stack.remove_last()


def refresh_shortcuts():
    global t, r, s, tm1, rm1, sm1, lp
    t, tm1 = timer_stack.stack_return()
    r = None if t is None else t.times
    s = None if r is None else r.stamps
    rm1 = None if tm1 is None else tm1.times
    sm1 = None if rm1 is None else rm1.stamps
    lp, _ = loop_stack.stack_return()


#
# Initialization.
#

def hard_reset():
    global timer_stack, loop_stack, root, lp
    timer_stack = Stack(Timer)

    loop_stack = Stack(Loop)