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-2020 Kicad Developers, see change_log.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 <refdes_utils.h>
34 
35 #include <vector>
36 
37 #include <wx/arrstr.h>
38 
39 // Helper class to store parameters for a regulator
41 {
42 public:
43  wxString m_Name; // Regulator name
44  int m_Type; // type: with separate sense pin (normal) (=0)
45  // or adjustable 3 pins reg (=1)
46  double m_Vref; // Vreference in volt
47  double m_Iadj; // 3 pin type only: I adjust in micro amp
48 
49 public:
50  REGULATOR_DATA( const wxString& aName, double aVref, int aType, double aIadj = 0)
51  {
52  m_Type = aType;
53  m_Vref = aVref;
54  m_Name = aName;
55  m_Iadj = aIadj;
56  }
57 };
58 
59 // Helper class to store the list of known regulators
61 {
62 public:
63  std::vector <REGULATOR_DATA*> m_List;
64 
65 public:
68  {
69  for( unsigned ii = 0; ii < m_List.size(); ii++ )
70  delete m_List[ii];
71  }
72 
73  unsigned int GetCount()
74  {
75  return m_List.size();
76  }
77 
78  void Add( REGULATOR_DATA* aItem )
79  {
80  // add new item an try to keep alphabetic order,
81  // and because name have numbers inside, use a KiCad compare function
82  // that handles number as numbers not ascii chars
83  unsigned ii = 0;
84  for( ; ii < m_List.size(); ii++ )
85  {
86  if( UTIL::RefDesStringCompare( aItem->m_Name, m_List[ii]->m_Name ) < 0 )
87  break;
88  }
89  m_List.insert( m_List.begin() + ii, aItem );
90  }
91 
92  REGULATOR_DATA* GetReg( const wxString& aName )
93  {
94  for( unsigned ii = 0; ii < m_List.size(); ii++ )
95  {
96  if( aName.CmpNoCase( m_List[ii]->m_Name ) == 0 )
97  {
98  return m_List[ii];
99  }
100  }
101  return NULL;
102  }
103 
104  void Remove( const wxString & aRegName )
105  {
106  for( unsigned ii = 0; ii < m_List.size(); ii++ )
107  {
108  if( aRegName.CmpNoCase( m_List[ii]->m_Name ) == 0 )
109  {
110  // Found! remove it
111  m_List.erase( m_List.begin() + ii );
112  break;
113  }
114  }
115  }
116 
122  void Replace( REGULATOR_DATA* aItem )
123  {
124  // Search for the old regulator
125  for( unsigned ii = 0; ii < m_List.size(); ii++ )
126  {
127  if( aItem->m_Name.CmpNoCase( m_List[ii]->m_Name ) == 0 )
128  {
129  // Found! remove it
130  delete m_List[ii];
131  m_List[ii] = aItem;
132  break;
133  }
134  }
135  }
136 
137  wxArrayString GetRegList() const
138  {
139  wxArrayString list;
140  for( unsigned ii = 0; ii < m_List.size(); ii++ )
141  list.Add( m_List[ii]->m_Name );
142 
143  return list;
144  }
145 };
146 
147 #endif // CLASS_REGULATOR_DATA_H
std::vector< REGULATOR_DATA * > m_List
Collection of utility functions for component reference designators (refdes)
REGULATOR_DATA * GetReg(const wxString &aName)
int RefDesStringCompare(const wxString &aFirst, const wxString &aSecond)
Acts just like the strcmp function but treats numbers within the string text correctly for sorting.
REGULATOR_DATA(const wxString &aName, double aVref, int aType, double aIadj=0)
wxArrayString GetRegList() const
#define NULL
void Add(REGULATOR_DATA *aItem)
unsigned int GetCount()
void Remove(const wxString &aRegName)
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...