chromium/third_party/cld_3/src/src/registry.h

/* Copyright 2016 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

// Registry for component registration. These classes can be used for creating
// registries of components conforming to the same interface. This is useful for
// making a component-based architecture where the specific implementation
// classes can be selected at runtime. There is support for both class-based and
// instance based registries.
//
// Example:
//  function.h:
//
//   class Function : public RegisterableInstance<Function> {
//    public:
//     virtual double Evaluate(double x) = 0;
//   };
//
//   #define REGISTER_FUNCTION(type, component)
//     REGISTER_INSTANCE_COMPONENT(Function, type, component);
//
//  function.cc:
//
//   REGISTER_INSTANCE_REGISTRY("function", Function);
//
//   class Cos : public Function {
//    public:
//     double Evaluate(double x) { return cos(x); }
//   };
//
//   class Exp : public Function {
//    public:
//     double Evaluate(double x) { return exp(x); }
//   };
//
//   REGISTER_FUNCTION("cos", Cos);
//   REGISTER_FUNCTION("exp", Exp);
//
//   Function *f = Function::Lookup("cos");
//   double result = f->Evaluate(arg);

#ifndef REGISTRY_H_
#define REGISTRY_H_

#include <string.h>

#include <string>

#include "base.h"

namespace chrome_lang_id {

// Component metadata with information about name, class, and code location.
class ComponentMetadata {};

// The master registry contains all registered component registries. A registry
// is not registered in the master registry until the first component of that
// type is registered.
class RegistryMetadata : public ComponentMetadata {};

// Registry for components. An object can be registered with a type name in the
// registry. The named instances in the registry can be returned using the
// Lookup() method. The components in the registry are put into a linked list
// of components. It is important that the component registry can be statically
// initialized in order not to depend on initialization order.
template <class T>
struct ComponentRegistry {};

// Base class for registerable class-based components.
template <class T>
class RegisterableClass {};

// Base class for registerable instance-based components.
template <class T>
class RegisterableInstance {};

}  // namespace chrome_lang_id

#endif  // REGISTRY_H_