LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
constraintFunctionManager.cpp
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 *
8 * @file constraintFunctionManager.cpp
9 * @author besancon (besanconr@zoe.cea.fr)
10 * @date Wed Mar 16 2005
11 * @version $Id$
12 * copyright Copyright (C) 2005-2012 by CEA LIST
13 *
14 ***********************************************************************/
15
18#include "constraintFunction.h"
19#include "boost/tuple/tuple.hpp" // for tie
20
21namespace Lima {
22namespace LinguisticProcessing {
23namespace Automaton {
24
29
31{
32 std::multimap<std::string,ConstraintFunction*>::iterator
33 func=m_constraintMap.begin(),
34 func_end=m_constraintMap.end();
35
36 for (;func!=func_end;func++) {
37 if ((*func).second!=0) {
38 delete (*func).second;
39 (*func).second=0;
40 }
41 }
42 m_constraintMap.clear();
43}
44
46getConstraintFunction(const std::string& id,
47 MediaId language,
48 const LimaString& complement) {
49// AULOGINIT;
50// LDEBUG << "getConstraintFunction: "<< id
51// << "," << complement;
52
53 std::multimap<std::string,ConstraintFunction*>::const_iterator
54 it,it_end;
55 boost::tie(it,it_end)=m_constraintMap.equal_range(id);
56 for (;it!=it_end; it++) {
57 if ((*it).second->getComplementString() == complement
58 && static_cast<MediaId>((*it).second->getLanguage()) == language) {
59// LDEBUG << "getConstraintFunction: function exist: "
60// << (*it).first << "," << (*it).second->getComplementString()
61// << "->" << (*it).second;
62 return (*it).second;
63 }
64 }
65// LDEBUG << "getConstraintFunction: function does not exist";
66 return createConstraintFunction(id,language,complement);
67}
68
69// not efficient but only for debug
71getFunctionName(const ConstraintFunction* functionPtr,
72 std::string& id,
73 LimaString& complement) const {
74 std::multimap<std::string,ConstraintFunction*>::const_iterator
75 it=m_constraintMap.begin(),
76 it_end=m_constraintMap.end();
77 for (;it!=it_end; it++) {
78 if ((*it).second==functionPtr) {
79 id=(*it).first;
80 complement=(*it).second->getComplementString();
81 return true;
82 }
83 }
84 return false;
85}
86
88createConstraintFunction(const std::string& id,
89 MediaId language,
90 const LimaString& complement) {
91
92
93 ConstraintFunction* newConstraint=
95 getFactory(id)->create(language,complement);
96 m_constraintMap.insert(make_pair(id,newConstraint));
97
98#ifdef DEBUG_LP
100 LDEBUG << "ConstraintFunctionManager::createConstraintFunction( id:"<< id
101 << ", language:" << language << ",complement:" << complement << ")->" << newConstraint
102 ;
103#endif
104
105 return newConstraint;
106}
107
108
109} // end namespace
110} // end namespace
111} // end namespace
#define LDEBUG
Definition LimaCommon.h:157
#define AULOGINIT
ConstraintFunction * createConstraintFunction(const std::string &id, MediaId language, const LimaString &complement=LimaString())
bool getFunctionName(const ConstraintFunction *functionPtr, std::string &id, LimaString &complement) const
ConstraintFunction * getConstraintFunction(const std::string &id, MediaId language, const LimaString &complement=LimaString())
static std::shared_ptr< AbstractConstraintFunctionFactory > getFactory(const std::string &id)
get the factory corresponding to the given id
NAUTITIA.
QString LimaString
Definition LimaString.h:33