KiCad PCB EDA Suite
Loading...
Searching...
No Matches
class_regulator_data.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KICAD, a free EDA CAD application.
3 *
4 * Copyright (C) 1992-2011 jean-pierre.charras
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
25
26#ifndef CLASS_REGULATOR_DATA_H
27#define CLASS_REGULATOR_DATA_H
28
29#include <string_utils.h>
30
31#include <vector>
32
33#include <wx/arrstr.h>
34
35// Helper class to store parameters for a regulator
37{
38public:
39 REGULATOR_DATA( const wxString& aName, double aVrefMin, double aVrefTyp, double aVrefMax,
40 int aType, double aIadjTyp = 0, double aIadjMax = 0 ) :
41 m_Name( aName ),
42 m_Type( aType ), m_VrefMin( aVrefMin ), m_VrefTyp( aVrefTyp ), m_VrefMax( aVrefMax ),
43 m_IadjTyp( aIadjTyp ), m_IadjMax( aIadjMax )
44 {
45 }
46
47public:
48 wxString m_Name; // Regulator name
49 int m_Type; // type: with separate sense pin (normal) (=0)
50 // or adjustable 3 pins reg (=1)
51 double m_VrefMin; // min Vreference in volt
52 double m_VrefTyp; // typ Vreference in volt
53 double m_VrefMax; // max Vreference in volt
54 double m_IadjTyp; // 3 pin type only: typ I adjust in micro amp
55 double m_IadjMax; // 3 pin type only: max I adjust in micro amp
56};
57
58// Helper class to store the list of known regulators
60{
61public:
64 {
65 for( REGULATOR_DATA* regulator : m_List )
66 delete regulator;
67 }
68
69 unsigned int GetCount()
70 {
71 return m_List.size();
72 }
73
74 void Add( REGULATOR_DATA* aItem )
75 {
76 // add new item an try to keep alphabetic order,
77 // and because name have numbers inside, use a KiCad compare function
78 // that handles number as numbers not ASCII chars
79 unsigned ii = 0;
80
81 for( ; ii < m_List.size(); ii++ )
82 {
83 if( StrNumCmp( aItem->m_Name, m_List[ii]->m_Name, true ) < 0 )
84 break;
85 }
86
87 m_List.insert( m_List.begin() + ii, aItem );
88 }
89
90 REGULATOR_DATA* GetReg( const wxString& aName )
91 {
92 for( REGULATOR_DATA* regulator : m_List )
93 {
94 if( aName.CmpNoCase( regulator->m_Name ) == 0 )
95 return regulator;
96 }
97 return nullptr;
98 }
99
100 void Remove( const wxString& aRegName )
101 {
102 for( unsigned ii = 0; ii < m_List.size(); ii++ )
103 {
104 if( aRegName.CmpNoCase( m_List[ii]->m_Name ) == 0 )
105 {
106 // Found! remove it
107 m_List.erase( m_List.begin() + ii );
108 break;
109 }
110 }
111 }
112
118 void Replace( REGULATOR_DATA* aItem )
119 {
120 // Search for the old regulator
121 for( unsigned ii = 0; ii < m_List.size(); ii++ )
122 {
123 if( aItem->m_Name.CmpNoCase( m_List[ii]->m_Name ) == 0 )
124 {
125 // Found! remove it
126 delete m_List[ii];
127 m_List[ii] = aItem;
128 break;
129 }
130 }
131 }
132
133 wxArrayString GetRegList() const
134 {
135 wxArrayString list;
136
137 for( REGULATOR_DATA* regulator : m_List )
138 list.Add( regulator->m_Name );
139
140 return list;
141 }
142
143 void Clear() { m_List.clear(); }
144
145 std::vector <REGULATOR_DATA*> m_List;
146};
147
148#endif // CLASS_REGULATOR_DATA_H
REGULATOR_DATA(const wxString &aName, double aVrefMin, double aVrefTyp, double aVrefMax, int aType, double aIadjTyp=0, double aIadjMax=0)
void Remove(const wxString &aRegName)
wxArrayString GetRegList() const
void Replace(REGULATOR_DATA *aItem)
Replace an old REGULATOR_DATA by a new one The old one is deleted the 2 items must have the same name...
void Add(REGULATOR_DATA *aItem)
REGULATOR_DATA * GetReg(const wxString &aName)
unsigned int GetCount()
std::vector< REGULATOR_DATA * > m_List
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.