Subversion Repositories tpanel

Rev

Rev 480 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 480 Rev 486
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (C) 2022 by Andreas Theofilu <andreas@theosys.at>
2
 * Copyright (C) 2022 to 2025 by Andreas Theofilu <andreas@theosys.at>
3
 *
3
 *
4
 * This program is free software; you can redistribute it and/or modify
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
7
 * (at your option) any later version.
Line 554... Line 554...
554
    DECL_TRACER("TExpat::getAttributeDouble(const string& name, vector<ATTRIBUTE_t>& attrs)");
554
    DECL_TRACER("TExpat::getAttributeDouble(const string& name, vector<ATTRIBUTE_t>& attrs)");
555
 
555
 
556
    return atof(getAttribute(name, attrs).c_str());
556
    return atof(getAttribute(name, attrs).c_str());
557
}
557
}
558
 
558
 
559
bool TExpat::convertElementToBool(const string& content)
559
bool TExpat::convertElementToBool(const string& content, bool def)
560
{
560
{
561
    DECL_TRACER("TExpat::convertElementToBool(const string& content)");
561
    DECL_TRACER("TExpat::convertElementToBool(const string& content, bool def)");
562
 
562
 
563
    if (content == "true" || content == "True" || content == "TRUE")
563
    if (content == "true" || content == "True" || content == "TRUE" || content == "1")
564
        return true;
564
        return true;
565
 
565
 
566
    return false;
566
    return def;
567
}
567
}
568
 
568
 
569
int TExpat::convertElementToInt(const string& content)
569
int TExpat::convertElementToInt(const string& content, int def)
570
{
570
{
571
    DECL_TRACER("TExpat::convertElementToInt(const string& content)");
571
    DECL_TRACER("TExpat::convertElementToInt(const string& content, int def)");
572
 
572
 
573
    if (content.empty())
573
    if (content.empty())
574
    {
574
    {
575
        TError::setErrorMsg("Empty content!");
575
        MSG_WARNING("Error converting to INT: Empty content");
576
        return 0;
576
        return def;
577
    }
577
    }
578
 
578
 
579
    return atoi(content.c_str());
579
    return atoi(content.c_str());
580
}
580
}
581
 
581
 
582
long TExpat::convertElementToLong(const string& content)
582
long TExpat::convertElementToLong(const string& content, long def)
583
{
583
{
584
    DECL_TRACER("TExpat::convertElementToLong(const string& content)");
584
    DECL_TRACER("TExpat::convertElementToLong(const string& content, long def)");
585
 
585
 
586
    if (content.empty())
586
    if (content.empty())
587
    {
587
    {
588
        TError::setErrorMsg("Empty content!");
588
        MSG_WARNING("Error converting to LONG: Empty content");
589
        return 0;
589
        return def;
590
    }
590
    }
591
 
591
 
592
    return atol(content.c_str());
592
    return atol(content.c_str());
593
}
593
}
594
 
594
 
595
float TExpat::convertElementToFloat(const string& content)
595
float TExpat::convertElementToFloat(const string& content, float def)
596
{
596
{
597
    DECL_TRACER("TExpat::convertElementToFloat(const string& content)");
597
    DECL_TRACER("TExpat::convertElementToFloat(const string& content, float def)");
598
 
598
 
599
    if (content.empty())
599
    if (content.empty())
600
    {
600
    {
601
        TError::setErrorMsg("Empty content!");
601
        MSG_WARNING("Error converting to FLOAT: Empty content");
602
        return 0;
602
        return def;
603
    }
603
    }
604
 
604
 
605
    return (float)atof(content.c_str());
605
    return static_cast<float>(atof(content.c_str()));
606
}
606
}
607
 
607
 
608
double TExpat::convertElementToDouble(const string& content)
608
double TExpat::convertElementToDouble(const string& content, double def)
609
{
609
{
610
    DECL_TRACER("TExpat::convertElementToDouble(const string& content)");
610
    DECL_TRACER("TExpat::convertElementToDouble(const string& content, double def)");
611
 
611
 
612
    if (content.empty())
612
    if (content.empty())
613
    {
613
    {
614
        TError::setErrorMsg("Empty content!");
614
        MSG_WARNING("Error converting to DOUBLE: Empty content");
615
        return 0;
615
        return def;
616
    }
616
    }
617
 
617
 
618
    return atof(content.c_str());
618
    return atof(content.c_str());
619
}
619
}
620
 
620
 
Line 622... Line 622...
622
{
622
{
623
    DECL_TRACER("TExpat::setIndex(size_t index)");
623
    DECL_TRACER("TExpat::setIndex(size_t index)");
624
 
624
 
625
    if (index >= mElements.size())
625
    if (index >= mElements.size())
626
    {
626
    {
-
 
627
        MSG_ERROR("Error setting index: Invalid index " << index);
627
        TError::setErrorMsg("Invalid index " + std::to_string(index) + "!");
628
        TError::setErrorMsg("Invalid index " + std::to_string(index) + "!");
628
        mLastIter = mElements.end();
629
        mLastIter = mElements.end();
629
        return false;
630
        return false;
630
    }
631
    }
631
 
632
 
Line 665... Line 666...
665
        return vector<ATTRIBUTE_t>();
666
        return vector<ATTRIBUTE_t>();
666
 
667
 
667
    return mElements.at(index).attrs;
668
    return mElements.at(index).attrs;
668
}
669
}
669
 
670
 
-
 
671
bool TExpat::isElementTypeStart(size_t index)
-
 
672
{
-
 
673
    DECL_TRACER("TExpat::isElementTypeStart(size_t index)");
-
 
674
 
-
 
675
    if (index >= mElements.size() || mElements.at(index).eType != _ET_START)
-
 
676
        return false;
-
 
677
 
-
 
678
    return true;
-
 
679
}
-
 
680
 
-
 
681
bool TExpat::isElementTypeEnd(size_t index)
-
 
682
{
-
 
683
    DECL_TRACER("TExpat::isElementTypeEnd(size_t index)");
-
 
684
 
-
 
685
    if (index >= mElements.size() || mElements.at(index).eType == _ET_END)
-
 
686
        return true;
-
 
687
 
-
 
688
    return false;
-
 
689
}
-
 
690
 
-
 
691
bool TExpat::isElementTypeAtomic(size_t index)
-
 
692
{
-
 
693
    DECL_TRACER("TExpat::isElementTypeAtomic(size_t index)");
-
 
694
 
-
 
695
    if (index >= mElements.size() || mElements.at(index).eType != _ET_ATOMIC)
-
 
696
        return false;
-
 
697
 
-
 
698
    return true;
-
 
699
}
-
 
700
 
-
 
701
_ETYPE_t TExpat::getElementType(size_t index)
-
 
702
{
-
 
703
    DECL_TRACER("TExpat::getElementType(size_t index)");
-
 
704
 
-
 
705
    if (index >= mElements.size())
-
 
706
        return _ET_END;
-
 
707
 
-
 
708
    return mElements.at(index).eType;
-
 
709
}
-
 
710
 
-
 
711
string TExpat::getElementTypeStr(size_t index)
-
 
712
{
-
 
713
    DECL_TRACER("TExpat::getElementTypeStr(size_t index)");
-
 
714
 
-
 
715
    if (index >= mElements.size())
-
 
716
        return "END";
-
 
717
 
-
 
718
    switch(mElements.at(index).eType)
-
 
719
    {
-
 
720
        case _ET_START:     return "START";
-
 
721
        case _ET_END:       return "END";
-
 
722
        case _ET_ATOMIC:    return "ATOMIC";
-
 
723
    }
-
 
724
 
-
 
725
    // Should not come here but needed to satisfy the compiler.
-
 
726
    return "END";
-
 
727
}
-
 
728
 
670
string TExpat::getElementName(bool *valid)
729
string TExpat::getElementName(bool *valid)
671
{
730
{
672
    DECL_TRACER("TExpat::getElementName()");
731
    DECL_TRACER("TExpat::getElementName()");
673
 
732
 
674
    if (mLastIter != mElements.end())
733
    if (mLastIter != mElements.end())