KiCad PCB EDA Suite
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 (C) 1992-2021 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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
30#ifndef CLASS_REGULATOR_DATA_H
31#define CLASS_REGULATOR_DATA_H
32
33#include <string_utils.h>
34
35#include <vector>
36
37#include <wx/arrstr.h>
38
39// Helper class to store parameters for a regulator
41{
42public:
43 REGULATOR_DATA( const wxString& aName, double aVref, int aType, double aIadj = 0) :
44 m_Name( aName ),
45 m_Type( aType ),
46 m_Vref( aVref ),
47 m_Iadj( aIadj )
48 {
49 }
50
51public:
52 wxString m_Name; // Regulator name
53 int m_Type; // type: with separate sense pin (normal) (=0)
54 // or adjustable 3 pins reg (=1)
55 double m_Vref; // Vreference in volt
56 double m_Iadj; // 3 pin type only: I adjust in micro amp
57};
58
59// Helper class to store the list of known regulators
61{
62public:
65 {
66 for( REGULATOR_DATA* regulator : m_List )
67 delete regulator;
68 }
69
70 unsigned int GetCount()
71 {
72 return m_List.size();
73 }
74
75 void Add( REGULATOR_DATA* aItem )
76 {
77 // add new item an try to keep alphabetic order,
78 // and because name have numbers inside, use a KiCad compare function
79 // that handles number as numbers not ASCII chars
80 unsigned ii = 0;
81
82 for( ; ii < m_List.size(); ii++ )
83 {
84 if( StrNumCmp( aItem->m_Name, m_List[ii]->m_Name, true ) < 0 )
85 break;
86 }
87
88 m_List.insert( m_List.begin() + ii, aItem );
89 }
90
91 REGULATOR_DATA* GetReg( const wxString& aName )
92 {
93 for( REGULATOR_DATA* regulator : m_List )
94 {
95 if( aName.CmpNoCase( regulator->m_Name ) == 0 )
96 return regulator;
97 }
98 return nullptr;
99 }
100
101 void Remove( const wxString& aRegName )
102 {
103 for( unsigned ii = 0; ii < m_List.size(); ii++ )
104 {
105 if( aRegName.CmpNoCase( m_List[ii]->m_Name ) == 0 )
106 {
107 // Found! remove it
108 m_List.erase( m_List.begin() + ii );
109 break;
110 }
111 }
112 }
113
119 void Replace( REGULATOR_DATA* aItem )
120 {
121 // Search for the old regulator
122 for( unsigned ii = 0; ii < m_List.size(); ii++ )
123 {
124 if( aItem->m_Name.CmpNoCase( m_List[ii]->m_Name ) == 0 )
125 {
126 // Found! remove it
127 delete m_List[ii];
128 m_List[ii] = aItem;
129 break;
130 }
131 }
132 }
133
134 wxArrayString GetRegList() const
135 {
136 wxArrayString list;
137
138 for( REGULATOR_DATA* regulator : m_List )
139 list.Add( regulator->m_Name );
140
141 return list;
142 }
143
144 std::vector <REGULATOR_DATA*> m_List;
145};
146
147#endif // CLASS_REGULATOR_DATA_H
REGULATOR_DATA(const wxString &aName, double aVref, int aType, double aIadj=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.