lldb.formatters.cache

Package lldb :: Package formatters :: Module cache |
[hide private]
[frames] | no frames]

# Source Code for Module lldb.formatters.cache

     1  """
     2  Objective-C runtime wrapper for use by LLDB Python formatters
     3
     4  part of The LLVM Compiler Infrastructure
     5  This file is distributed under the University of Illinois Open Source
     6  License. See LICENSE.TXT for details.
     7  """
     8  import lldb.formatters.metrics
     9
    10 -class Cache:
    11 -        def __init__(self):
    12                  self.data = {}
    13                  self.statistics = lldb.formatters.metrics.Metrics()
    14                  self.statistics.add_metric('hit')
    15                  self.statistics.add_metric('miss')
    16
    17 -        def look_for_key(self,key):
    18                  if key in self.data:
    19                          return True
    20                  return False
    21
    22 -        def add_item(self,key,value,ok_to_replace=True):
    23                  if not(ok_to_replace) and self.look_for_key(key):
    24                          return False
    25                  self.data[key] = value
    26                  return True
    27
    28 -        def get_value(self,key,default=None):
    29                  if self.look_for_key(key):
    30                          self.statistics.metric_hit('hit',key)
    31                          return self.data[key]
    32                  else:
    33                          self.statistics.metric_hit('miss',key)
    34                          return default
    35