GAMS Data eXchange (GDX) API
Low-level "eXPert level" C++ API for reading and writing GAMS Data eXchange files
Loading...
Searching...
No Matches
gdx.hpp
1/*
2 * GAMS - General Algebraic Modeling System GDX API
3 *
4 * Copyright (c) 2017-2026 GAMS Software GmbH <support@gams.com>
5 * Copyright (c) 2017-2026 GAMS Development Corp. <support@gams.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26// WARNING: This file is generated by the "yaml2doxy" script from the API definition file "gdxapi.yaml"
27
28#pragma once
29
30#include "gxfile.hpp"
31
32#ifndef GDX_NS
33#define GDX_NS gdxlib::
34#endif
35
36namespace GDX_NS gdx
37{
38
41{
42public:
47 explicit TGXFileObj();
48
55
56 enum class TraceLevels : uint8_t
57 {
58 trl_none,
59 trl_errors,
60 trl_some,
61 trl_all
62 };
63 void SetTraceLevel( TraceLevels tl );
64
71 [[nodiscard]] int gdxStoreDomainSets() const;
72
79 void gdxStoreDomainSetsSet(int flag);
80
91 [[nodiscard]] int gdxAllowBogusDomains() const;
92
104 void gdxAllowBogusDomainsSet(int flag);
105
110 [[nodiscard]] int gdxMapAcronymsToNaN() const;
111
116 void gdxMapAcronymsToNaNSet(int flag);
117
129 int gdxAddAlias( const char *Id1, const char *Id2 );
130
139 int gdxAutoConvert( int NV );
140
145 int64_t gdxGetMemoryUsed();
146
149
174 int gdxAcronymAdd( const char *AName, const char *Txt, int AIndx );
175
181 int gdxAcronymCount() const;
182
195 int gdxAcronymGetInfo( int N, char *AName, char *Txt, int &AIndx ) const;
196
212 int gdxAcronymGetMapping( int N, int &orgIndx, int &newIndx, int &autoIndex );
213
220 int gdxAcronymIndex( double V ) const;
221
233 int gdxAcronymName( double V, char *AName );
234
251 int gdxAcronymNextNr( int NV );
252
275 int gdxAcronymSetInfo( int N, const char *AName, const char *Txt, int AIndx );
276
284 double gdxAcronymValue( int AIndx ) const;
285
287
288
291
300 int gdxSymbolAddComment( int SyNr, const char *Txt );
301
312 int gdxSymbolGetComment( int SyNr, int N, char *Txt );
313
315
316
319
329 int gdxSymbolGetDomain( int SyNr, int *DomainSyNrs );
330
357 int gdxSymbolGetDomainX( int SyNr, char **DomainIDs );
358
372 int gdxSymbolSetDomain( const char **DomainIDs );
373
386 int gdxSymbolSetDomainX( int SyNr, const char **DomainIDs );
387
417 int gdxGetDomainElements( int SyNr, int DimPos, int FilterNr, TDomainIndexProc_t DP, int &NrElem, void *Uptr );
418
420
421
424
429 int gdxErrorCount() const;
430
439 int gdxErrorStr( int ErrNr, char *ErrMsg ) const;
440
450 int gdxGetLastError();
451
453
454
457
464 int gdxClose();
465
488 int gdxOpenAppend( const char *FileName, const char *Producer, int &ErrNr );
489
507 int gdxOpenRead( const char *FileName, int &ErrNr );
508
528 int gdxOpenReadEx( const char *FileName, int ReadMode, int &ErrNr );
529
541 int gdxOpenWrite( const char *FileName, const char *Producer, int &ErrNr );
542
566 int gdxOpenWriteEx( const char *FileName, const char *Producer, int Compr, int &ErrNr );
567
569
570
573
580 int gdxFilterExists( int FilterNr );
581
592 int gdxFilterRegister( int UelMap );
593
599 int gdxFilterRegisterDone();
600
610 int gdxFilterRegisterStart( int FilterNr );
611
613
614
617
633 int gdxFindSymbol( const char *SyId, int &SyNr );
634
645 int gdxGetUEL( int UelNr, char *Uel );
646
648
649
652
661 int gdxSymbIndxMaxLength( int SyNr, int *LengthInfo );
662
667 int gdxSymbMaxLength() const;
668
674 int gdxUELMaxLength();
675
677
678
681
691 int gdxDataErrorCount() const;
692
713 int gdxDataErrorRecord( int RecNr, int *KeyInt, double *Values );
714
733 int gdxDataErrorRecordX( int RecNr, int *KeyInt, double *Values );
734
745 int gdxSetErrorRecordCutoff( int maxDataErrorRecords );
746
753 int gdxDataReadDone();
754
815 int gdxDataReadFilteredStart( int SyNr, const int *FilterAction, int &NrRecs );
816
826 int gdxDataReadMap( int RecNr, int *KeyInt, double *Values, int &DimFrst );
827
836 int gdxDataReadMapStart( int SyNr, int &NrRecs );
837
847 int gdxDataReadRaw( int *KeyInt, double *Values, int &DimFrst );
848
869 int gdxDataReadRawFast( int SyNr, TDataStoreProc_t DP, int &NrRecs );
870
898 int gdxDataReadRawFastEx( int SyNr, TDataStoreExProc_t DP, int &NrRecs, void *Uptr );
899
939 int gdxDataReadRawFastFilt( int SyNr, const char **UelFilterStr, TDataStoreFiltProc_t DP );
940
949 int gdxDataReadRawStart( int SyNr, int &NrRecs );
950
972 int gdxDataReadSlice( const char **UelFilterStr, int &Dimen, TDataStoreProc_t DP );
973
983 int gdxDataReadSliceStart( int SyNr, int *ElemCounts );
984
1002 int gdxDataReadStr( char **KeyStr, double *Values, int &DimFrst );
1003
1022 int gdxDataReadStrStart( int SyNr, int &NrRecs );
1023
1035 int gdxDataSliceUELS( const int *SliceKeyInt, char **KeyStr );
1036
1038
1039
1042
1050 int gdxGetSpecialValues( double *AVals );
1051
1059 int gdxMapValue( double D, int &sv );
1060
1066 int gdxResetSpecialValues();
1067
1079 int gdxSetReadSpecialValues( const double *AVals );
1080
1093 int gdxSetSpecialValues( const double *AVals );
1094
1096
1097
1100
1106 int gdxFileInfo( int &FileVer, int &ComprLev ) const;
1107
1114 int gdxSymbolDim( int SyNr );
1115
1127 int gdxSymbolInfo( int SyNr, char *SyId, int &Dimen, int &Typ );
1128
1192 int gdxSymbolInfoX( int SyNr, int &RecCnt, int &UserInfo, char *ExplTxt );
1193
1200 int gdxSystemInfo( int &SyCnt, int &UelCnt );
1201
1212 int gdxCurrentDim() const;
1213
1215
1216
1219
1230 int gdxAddSetText( const char *Txt, int &TxtNr );
1231
1267 int gdxGetElemText( int TxtNr, char *Txt, int &Node );
1268
1276 int gdxSetHasText( int SyNr );
1277
1288 int gdxSetTextNodeNr( int TxtNr, int Node );
1289
1291
1292
1295
1300 int gdxUELRegisterDone();
1301
1315 int gdxUELRegisterMap( int UMap, const char *Uel );
1316
1322 int gdxUELRegisterMapStart();
1323
1335 int gdxUELRegisterRaw( const char *Uel );
1336
1342 int gdxUELRegisterRawStart();
1343
1357 int gdxUELRegisterStr( const char *Uel, int &UelNr );
1358
1364 int gdxUELRegisterStrStart();
1365
1373 int gdxUMFindUEL( const char *Uel, int &UelNr, int &UelMap );
1374
1384 int gdxUMUelGet( int UelNr, char *Uel, int &UelMap );
1385
1393 int gdxUMUelInfo( int &UelCnt, int &HighMap );
1394
1403 int gdxRenameUEL( const char *OldName, const char *NewName );
1404
1406
1407
1410
1416 static int gdxGetDLLVersion( char *V );
1417
1426 int gdxFileVersion( char *FileStr, char *ProduceStr ) const;
1427
1434 int gdxSetTraceLevel( int N, const char *s );
1435
1437
1438
1441
1447 int gdxDataWriteDone();
1448
1456 int gdxDataWriteMap( const int *KeyInt, const double *Values );
1457
1521 int gdxDataWriteMapStart( const char *SyId, const char *ExplTxt, int Dimen, int Typ, int UserInfo );
1522
1536 int gdxDataWriteRaw( const int *KeyInt, const double *Values );
1537
1603 int gdxDataWriteRawStart( const char *SyId, const char *ExplTxt, int Dimen, int Typ, int UserInfo );
1604
1676 int gdxDataWriteRawStartKeyBounds( const char *SyId, const char *ExplTxt, int Dimen, int Typ, int UserInfo, const int *MinUELIndices, const int *MaxUELIndices );
1677
1732 int gdxDataWriteStr( const char **KeyStr, const double *Values );
1733
1749 int gdxDataWriteStrStart( const char *SyId, const char *ExplTxt, int Dimen, int Typ, int UserInfo );
1750
1752
1753
1754
1755private:
1756std::unique_ptr<gdlib::gmsstrm::TMiBufferedStream> FFile;
1757std::string lastFileName {};
1758TgxFileMode fmode { f_not_open }, fmode_AftReg { f_not_open };
1759enum : uint8_t
1760{
1761 stat_notopen,
1762 stat_read,
1763 stat_write
1764} fstatus { stat_notopen };
1765int fComprLev {};
1766std::unique_ptr<TUELTable> UELTable;
1767std::unique_ptr<TSetTextList> SetTextList {};
1768std::unique_ptr<int[]> MapSetText {};
1769int FCurrentDim {};
1770std::array<int, GLOBAL_MAX_INDEX_DIM> LastElem {}, PrevElem {}, MinElem {}, MaxElem {};
1771std::array<std::array<char, GLOBAL_UEL_IDENT_SIZE>, GLOBAL_MAX_INDEX_DIM> LastStrElem {};
1772int DataSize {};
1773tvarvaltype LastDataField {};
1774std::unique_ptr<TNameList> NameList;
1775std::unique_ptr<TDomainStrList> DomainStrList;
1776std::unique_ptr<LinkedDataType> SortList;
1777std::optional<LinkedDataIteratorType> ReadPtr;
1778std::unique_ptr<TTblGamsDataImpl<double>> ErrorList;
1779int MaxErrorRecords {11};
1780PgdxSymbRecord CurSyPtr {};
1781int ErrCnt {}, ErrCntTotal {};
1782int LastError {}, LastRepError {};
1783std::unique_ptr<TFilterList> FilterList;
1784TDFilter *CurFilter {};
1785TDomainList DomainList {};
1786bool StoreDomainSets { true }, AllowBogusDomain { true }, MapAcrToNaN {};
1787TIntlValueMapDbl intlValueMapDbl {}, readIntlValueMapDbl {};
1788TIntlValueMapI64 intlValueMapI64 {};
1789TraceLevels TraceLevel { TraceLevels::trl_all };
1790std::string TraceStr;
1791int VersionRead {};
1792std::string FProducer, FProducer2, FileSystemID;
1793int64_t MajorIndexPosition {};
1794int64_t NextWritePosition {};
1795int DataCount {}, NrMappedAdded {};
1796std::array<TgdxElemSize, GLOBAL_MAX_INDEX_DIM> ElemType {};
1797std::string MajContext;
1798std::array<TIntegerMapping, GLOBAL_MAX_INDEX_DIM> SliceIndxs {}, SliceRevMap {};
1799int SliceSyNr {};
1800std::array<std::string, GMS_MAX_INDEX_DIM> SliceElems;
1801bool DoUncompress {}, // when reading
1802 CompressOut {};// when writing
1803int DeltaForWrite {}; // delta for last dimension or first changed dimension
1804int DeltaForRead {}; // first position indicating change
1805double Zvalacr {}; // tricky
1806std::unique_ptr<TAcronymList> AcronymList;
1807std::array<TSetBitMap *, GLOBAL_MAX_INDEX_DIM> WrBitMaps {};
1808bool ReadUniverse {};
1809int UniverseNr {}, UelCntOrig {};// original uel count when we open the file
1810int AutoConvert { 1 };
1811int NextAutoAcronym {};
1812bool AppendActive {};
1813
1814#ifndef VERBOSE_TRACE
1815const TraceLevels defaultTraceLevel { TraceLevels::trl_none };
1816const bool verboseTrace {};
1817#else
1818const TraceLevels defaultTraceLevel { TraceLevels::trl_all };
1819const bool verboseTrace { true };
1820#endif
1821
1822//api wrapper magic for Fortran
1823TDataStoreFiltProc_t gdxDataReadRawFastFilt_DP {};
1824TDomainIndexProc_t gdxGetDomainElements_DP {};
1825
1826int64_t ReadUELPos {}, ReadAcronymPos {}, ReadSetTextPos {};
1827bool UelReadDeferred {}, SetTextReadDeferred {};
1828
1829bool PrepareSymbolWrite( std::string_view Caller, const char *AName, const char *AText, int ADim, int AType, int AUserInfo );
1830int PrepareSymbolRead( std::string_view Caller, int SyNr, const int *ADomainNrs, TgxFileMode newmode );
1831
1832void InitErrors();
1833void SetError( int N );
1834void ReportError( int N );
1835bool ErrorCondition( bool cnd, int N );
1836
1837bool MajorCheckMode( std::string_view Routine, TgxFileMode m );
1838bool MajorCheckMode( std::string_view Routine, const TgxModeSet &MS );
1839
1840bool CheckMode( std::string_view Routine );
1841bool CheckMode( std::string_view Routine, TgxFileMode m );
1842bool CheckMode( std::string_view Routine, const TgxModeSet &MS );
1843
1844void WriteTrace( std::string_view s ) const;
1845void InitDoWrite( int NrRecs );
1846bool DoWrite( const int *AElements, const double *AVals );
1847bool DoRead( double *AVals, int &AFDim );
1848void AddToErrorListDomErrs( const std::array<int, GLOBAL_MAX_INDEX_DIM> &AElements, const double *AVals );
1849void AddToErrorList( const int *AElements, const double *AVals );
1850void GetDefaultRecord( double *Avals ) const;
1851double AcronymRemap( double V );
1852bool IsGoodNewSymbol( const char *s );
1853bool ResultWillBeSorted( const int *ADomainNrs ) const;
1854
1855int gdxOpenReadXX( const char *Afn, int filemode, int ReadMode, int &ErrNr );
1856int ReadUELTable(bool isDeferred);
1857int ReadSetTextList(bool isDeferred);
1858
1859// This one is a helper function for a callback from a Fortran client
1860void gdxGetDomainElements_DP_FC( int RawIndex, int MappedIndex, void *Uptr );
1861int gdxDataReadRawFastFilt_DP_FC( const int *Indx, const double *Vals, void *Uptr );
1862
1863void mapDefaultRecordValues(double *AVals) const;
1864
1865public:
1866bool gdxGetDomainElements_DP_CallByRef {},
1867 gdxDataReadRawFastFilt_DP_CallByRef {},
1868 gdxDataReadRawFastEx_DP_CallByRef {};
1869};
1870
1871}// namespace gdx
1872
1873namespace gdx = GDX_NS gdx;
Definition: gdx.hpp:41
Definition: gxfile.hpp:196
Definition: gxfile.hpp:92