LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
ObjectManager.h
Go to the documentation of this file.
1// Copyright 2002-2013 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6/***************************************************************************
7 * Copyright (C) 2004-2012 by CEA LIST *
8 * *
9 ***************************************************************************/
10
11#ifndef LIMA_COMMON_ABSTRACTFACTORYPATTERN_OBJECTMANAGER_H
12#define LIMA_COMMON_ABSTRACTFACTORYPATTERN_OBJECTMANAGER_H
13
14#include "MainFactory.h"
18
19namespace Lima
20{
21
28template <typename Object>
30{
31public:
32
36 virtual ~ObjectManager();
37
45 virtual std::shared_ptr<Object> getObject(const std::string& id);
46
47protected:
48
55 virtual std::shared_ptr<Object> createObject(const std::string& id) = 0;
56
57private:
58
59 typedef typename std::map<std::string, std::shared_ptr<Object>> ObjectMap;
60 typedef typename std::map<std::string, std::shared_ptr<Object>>::iterator ObjectMapItr;
61 ObjectMap m_objects;
62};
63
64template <typename Object>
66{
67 // for (ObjectMapItr it=m_objects.begin();
68 // it!=m_objects.end();
69 // it++)
70 // {
71 // delete it->second;
72 // it->second=0;
73 // }
74 m_objects.clear();
75}
76
77template <typename Object>
78std::shared_ptr<Object> ObjectManager<Object>::getObject(
79 const std::string& id) {
80 auto ioItr = m_objects.find(id);
81 if (ioItr == m_objects.end())
82 {
83 auto obj = this->createObject(id);
84 m_objects[id] = obj;
85 return obj;
86 }
87 return ioItr->second;
88}
89
90} // Lima
91
92#endif
Defines the MainFactory to create Object.
Manager for objects.
virtual std::shared_ptr< Object > createObject(const std::string &id)=0
create the required object.
virtual std::shared_ptr< Object > getObject(const std::string &id)
If object doesn't exists, call the create method.
virtual ~ObjectManager()
ObjectManager destructor.
originally detectModuleConfigurationStructure.h in detectlibraries
NAUTITIA.
launch exception related to the configuration file parsing