original_docstring: Writes the context state service implementation.
docstring: Writes the context state service implementation.
docstring_tokens: Writes the context state service implementation .
code: def WriteServiceContextStateImpl(self, filename):
      """Writes the context state service implementation."""
      file = CHeaderWriter(
          filename,
          "// It is included by context_state.cc\n")
      code = []
      for capability in _CAPABILITY_FLAGS:
        code.append("%s(%s)" %
                    (capability['name'],
                     ('false', 'true')['default' in capability]))
        code.append("cached_%s(%s)" %
                    (capability['name'],
                     ('false', 'true')['default' in capability]))
      file.Write("ContextState::EnableFlags::EnableFlags()\n    : %s {\n}\n" %
                 ",\n      ".join(code))
      file.Write("\n")
  
      file.Write("void ContextState::Initialize() {\n")
      for state_name in sorted(_STATES.keys()):
        state = _STATES[state_name]
        for item in state['states']:
          if isinstance(item['default'], list):
            for ndx, value in enumerate(item['default']):
              file.Write("  %s[%d] = %s;\n" % (item['name'], ndx, value))
          else:
            file.Write("  %s = %s;\n" % (item['name'], item['default']))
          if item.get('cached', False):
            if isinstance(item['default'], list):
              for ndx, value in enumerate(item['default']):
                file.Write("  cached_%s[%d] = %s;\n" % (item['name'], ndx, value))
            else:
              file.Write("  cached_%s = %s;\n" % (item['name'], item['default']))
      file.Write("}\n")
  
      file.Write("""
  void ContextState::InitCapabilities(const ContextState* prev_state) const {
  """)
      def WriteCapabilities(test_prev):
        for capability in _CAPABILITY_FLAGS:
          capability_name = capability['name']
          if test_prev:
            file.Write("""  if (prev_state->enable_flags.cached_%s !=
                                enable_flags.cached_%s)\n""" %
                       (capability_name, capability_name))
          file.Write("    EnableDisable(GL_%s, enable_flags.cached_%s);\n" %
                     (capability_name.upper(), capability_name))
  
      file.Write("  if (prev_state) {")
      WriteCapabilities(True)
      file.Write("  } else {")
      WriteCapabilities(False)
      file.Write("  }")
  
      file.Write("""}
  
  void ContextState::InitState(const ContextState *prev_state) const {
  """)
  
      def WriteStates(test_prev):
        # We need to sort the keys so the expectations match
        for state_name in sorted(_STATES.keys()):
          state = _STATES[state_name]
          if state['type'] == 'FrontBack':
            num_states = len(state['states'])
            for ndx, group in enumerate(Grouper(num_states / 2, state['states'])):
              if test_prev:
                file.Write("  if (")
              args = []
              for place, item in enumerate(group):
                item_name = CachedStateName(item)
                args.append('%s' % item_name)
                if test_prev:
                  if place > 0:
                    file.Write(' ||\n')
                  file.Write("(%s != prev_state->%s)" % (item_name, item_name))
              if test_prev:
                file.Write(")\n")
              file.Write(
                  "  gl%s(%s, %s);\n" %
                  (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args)))
          elif state['type'] == 'NamedParameter':
            for item in state['states']:
              item_name = CachedStateName(item)
  
              if 'extension_flag' in item:
                file.Write("  if (feature_info_->feature_flags().%s) {\n  " %
                           item['extension_flag'])
              if test_prev:
                if isinstance(item['default'], list):
                  file.Write("  if (memcmp(prev_state->%s, %s, "
                             "sizeof(%s) * %d)) {\n" %
                             (item_name, item_name, item['type'],
                              len(item['default'])))
                else:
                  file.Write("  if (prev_state->%s != %s) {\n  " %
                             (item_name, item_name))
              file.Write("  gl%s(%s, %s);\n" %
                         (state['func'],
                          (item['enum_set']
                             if 'enum_set' in item else item['enum']),
                          item['name']))
              if test_prev:
                if 'extension_flag' in item:
                  file.Write("  ")
                file.Write("  }")
              if 'extension_flag' in item:
                file.Write("  }")
          else:
            if 'extension_flag' in state:
              file.Write("  if (feature_info_->feature_flags().%s)\n  " %
                         state['extension_flag'])
            if test_prev:
              file.Write("  if (")
            args = []
            for place, item in enumerate(state['states']):
              item_name = CachedStateName(item)
              args.append('%s' % item_name)
              if test_prev:
                if place > 0:
                  file.Write(' ||\n')
                file.Write("(%s != prev_state->%s)" %
                           (item_name, item_name))
            if test_prev:
              file.Write("    )\n")
            file.Write("  gl%s(%s);\n" % (state['func'], ", ".join(args)))
  
      file.Write("  if (prev_state) {")
      WriteStates(True)
      file.Write("  } else {")
      WriteStates(False)
      file.Write("  }")
      file.Write("}\n")
  
      file.Write("""bool ContextState::GetEnabled(GLenum cap) const {
    switch (cap) {
  """)
      for capability in _CAPABILITY_FLAGS:
        file.Write("    case GL_%s:\n" % capability['name'].upper())
        file.Write("      return enable_flags.%s;\n" % capability['name'])
      file.Write("""    default:
        NOTREACHED();
        return false;
    }
  }
  """)
  
      self.WriteContextStateGetters(file, "ContextState")
      file.Close()
      self.generated_cpp_filenames.append(file.filename)
code_tokens: def WriteServiceContextStateImpl ( self , filename ) : file = CHeaderWriter ( filename , "// It is included by context_state.cc\n" ) code = [ ] for capability in _CAPABILITY_FLAGS : code . append ( "%s(%s)" % ( capability [ 'name' ] , ( 'false' , 'true' ) [ 'default' in capability ] ) ) code . append ( "cached_%s(%s)" % ( capability [ 'name' ] , ( 'false' , 'true' ) [ 'default' in capability ] ) ) file . Write ( "ContextState::EnableFlags::EnableFlags()\n    : %s {\n}\n" % ",\n      " . join ( code ) ) file . Write ( "\n" ) file . Write ( "void ContextState::Initialize() {\n" ) for state_name in sorted ( _STATES . keys ( ) ) : state = _STATES [ state_name ] for item in state [ 'states' ] : if isinstance ( item [ 'default' ] , list ) : for ndx , value in enumerate ( item [ 'default' ] ) : file . Write ( "  %s[%d] = %s;\n" % ( item [ 'name' ] , ndx , value ) ) else : file . Write ( "  %s = %s;\n" % ( item [ 'name' ] , item [ 'default' ] ) ) if item . get ( 'cached' , False ) : if isinstance ( item [ 'default' ] , list ) : for ndx , value in enumerate ( item [ 'default' ] ) : file . Write ( "  cached_%s[%d] = %s;\n" % ( item [ 'name' ] , ndx , value ) ) else : file . Write ( "  cached_%s = %s;\n" % ( item [ 'name' ] , item [ 'default' ] ) ) file . Write ( "}\n" ) file . Write ( """
  void ContextState::InitCapabilities(const ContextState* prev_state) const {
  """ ) def WriteCapabilities ( test_prev ) : for capability in _CAPABILITY_FLAGS : capability_name = capability [ 'name' ] if test_prev : file . Write ( """  if (prev_state->enable_flags.cached_%s !=
                                enable_flags.cached_%s)\n""" % ( capability_name , capability_name ) ) file . Write ( "    EnableDisable(GL_%s, enable_flags.cached_%s);\n" % ( capability_name . upper ( ) , capability_name ) ) file . Write ( "  if (prev_state) {" ) WriteCapabilities ( True ) file . Write ( "  } else {" ) WriteCapabilities ( False ) file . Write ( "  }" ) file . Write ( """}
  
  void ContextState::InitState(const ContextState *prev_state) const {
  """ ) def WriteStates ( test_prev ) : for state_name in sorted ( _STATES . keys ( ) ) : state = _STATES [ state_name ] if state [ 'type' ] == 'FrontBack' : num_states = len ( state [ 'states' ] ) for ndx , group in enumerate ( Grouper ( num_states / 2 , state [ 'states' ] ) ) : if test_prev : file . Write ( "  if (" ) args = [ ] for place , item in enumerate ( group ) : item_name = CachedStateName ( item ) args . append ( '%s' % item_name ) if test_prev : if place > 0 : file . Write ( ' ||\n' ) file . Write ( "(%s != prev_state->%s)" % ( item_name , item_name ) ) if test_prev : file . Write ( ")\n" ) file . Write ( "  gl%s(%s, %s);\n" % ( state [ 'func' ] , ( 'GL_FRONT' , 'GL_BACK' ) [ ndx ] , ", " . join ( args ) ) ) elif state [ 'type' ] == 'NamedParameter' : for item in state [ 'states' ] : item_name = CachedStateName ( item ) if 'extension_flag' in item : file . Write ( "  if (feature_info_->feature_flags().%s) {\n  " % item [ 'extension_flag' ] ) if test_prev : if isinstance ( item [ 'default' ] , list ) : file . Write ( "  if (memcmp(prev_state->%s, %s, " "sizeof(%s) * %d)) {\n" % ( item_name , item_name , item [ 'type' ] , len ( item [ 'default' ] ) ) ) else : file . Write ( "  if (prev_state->%s != %s) {\n  " % ( item_name , item_name ) ) file . Write ( "  gl%s(%s, %s);\n" % ( state [ 'func' ] , ( item [ 'enum_set' ] if 'enum_set' in item else item [ 'enum' ] ) , item [ 'name' ] ) ) if test_prev : if 'extension_flag' in item : file . Write ( "  " ) file . Write ( "  }" ) if 'extension_flag' in item : file . Write ( "  }" ) else : if 'extension_flag' in state : file . Write ( "  if (feature_info_->feature_flags().%s)\n  " % state [ 'extension_flag' ] ) if test_prev : file . Write ( "  if (" ) args = [ ] for place , item in enumerate ( state [ 'states' ] ) : item_name = CachedStateName ( item ) args . append ( '%s' % item_name ) if test_prev : if place > 0 : file . Write ( ' ||\n' ) file . Write ( "(%s != prev_state->%s)" % ( item_name , item_name ) ) if test_prev : file . Write ( "    )\n" ) file . Write ( "  gl%s(%s);\n" % ( state [ 'func' ] , ", " . join ( args ) ) ) file . Write ( "  if (prev_state) {" ) WriteStates ( True ) file . Write ( "  } else {" ) WriteStates ( False ) file . Write ( "  }" ) file . Write ( "}\n" ) file . Write ( """bool ContextState::GetEnabled(GLenum cap) const {
    switch (cap) {
  """ ) for capability in _CAPABILITY_FLAGS : file . Write ( "    case GL_%s:\n" % capability [ 'name' ] . upper ( ) ) file . Write ( "      return enable_flags.%s;\n" % capability [ 'name' ] ) file . Write ( """    default:
        NOTREACHED();
        return false;
    }
  }
  """ ) self . WriteContextStateGetters ( file , "ContextState" ) file . Close ( ) self . generated_cpp_filenames . append ( file . filename )
short_docstring: Writes the context state service implementation.
short_docstring_tokens: Writes the context state service implementation .
comment: """Writes the context state service implementation."""$SEP$# We need to sort the keys so the expectations match