Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  Nestable.h

  Sprache: C
 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


#ifndef ds_Nestable_h
#define ds_Nestable_h

#include "mozilla/Assertions.h"

namespace js {

// A base class for nestable structures.
//
// This subclasses of this class must follow a LIFO destruction order, The
// easiest way to ensure that is adding MOZ_STACK_CLASS to the subclasses.
// This class doesn't have the MOZ_STACK_CLASS annotation in order to allow
// specific cases where the subclasses can be allocated on heap for reduced
// stack usage and other implementation specific reasons, but even in such
// cases the subclasses must follow a LIFO destruction order.
template <typename Concrete>
class Nestable {
  Concrete** stack_;
  Concrete* enclosing_;

 protected:
  explicit Nestable(Concrete** stack) : stack_(stack), enclosing_(*stack) {
    *stack_ = static_cast<Concrete*>(this);
  }

  // These method are protected. Some derived classes, such as ParseContext,
  // do not expose the ability to walk the stack.
  Concrete* enclosing() const { return enclosing_; }

  template <typename Predicate /* (Concrete*) -> bool */>
  static Concrete* findNearest(Concrete* it, Predicate predicate) {
    while (it && !predicate(it)) {
      it = it->enclosing();
    }
    return it;
  }

  template <typename T>
  static T* findNearest(Concrete* it) {
    while (it && !it->template is<T>()) {
      it = it->enclosing();
    }
    return it ? &it->template as<T>() : nullptr;
  }

  template <typename T, typename Predicate /* (T*) -> bool */>
  static T* findNearest(Concrete* it, Predicate predicate) {
    while (it && (!it->template is<T>() || !predicate(&it->template as<T>()))) {
      it = it->enclosing();
    }
    return it ? &it->template as<T>() : nullptr;
  }

 public:
  ~Nestable() {
    MOZ_ASSERT(*stack_ == static_cast<Concrete*>(this));
    *stack_ = enclosing_;
  }
};

}  // namespace js

#endif /* ds_Nestable_h */

Messung V0.5 in Prozent
C=82 H=83 G=82

¤ Dauer der Verarbeitung: 0.4 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002