File: DeviceStrHelpers.cpp

package info (click to toggle)
libapogee3 3.2%2B20221221183454-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,284 kB
  • sloc: cpp: 26,737; sh: 8; makefile: 3
file content (109 lines) | stat: -rw-r--r-- 3,025 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*! 
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright(c) 2011 Apogee Imaging Systems, Inc. 
* \class DeviceStrHelpers 
* \brief namespace to assit with parsing device strings 
* 
*/ 

#include "DeviceStrHelpers.h" 
#include "helpers.h" 
#include <regex>

//----------------------------------------------
//      GET    DEVICE       VECT
std::vector<std::string> DeviceStr::GetVect( std::string data )
{
    std::string pattern( "<d>(.*?)</d>" );
    std::regex re( pattern );
    std::sregex_iterator m1( data.begin(), data.end(), re );
    std::sregex_iterator m2;

    std::sregex_iterator iter;
    std::vector<std::string> matchStrs;
    for(iter = m1; iter != m2; ++iter)
    {
        if( (*iter)[1].str().size() )
        {
            matchStrs.push_back( (*iter)[1].str() ); 
        }
    }

    return matchStrs;
}

//----------------------------------------------
//      GET    CAMERAS       VECT
std::vector<std::string> DeviceStr::GetCameras( std::string data  )
{
    std::vector<std::string> devices = DeviceStr::GetVect( data );

    std::vector<std::string>::iterator iter;
    std::vector<std::string> cameras;
    std::string c("camera");
    for( iter = devices.begin(); iter != devices.end(); ++iter )
    {
        std::string type =  DeviceStr::GetType( (*iter) );
        if( 0 == type.compare( c ) )
        {
            cameras.push_back( (*iter) );
        }
    }

    return cameras;
}

//----------------------------------------------
//      GET    DEVICE   TYPE
std::string DeviceStr::GetType( const std::string & data )
{
    return help::GetItemFromFindStr( data, "deviceType=" );
}

//----------------------------------------------
//      GET    DEVICE   NAME
std::string DeviceStr::GetName( const std::string & data )
{
    return help::GetItemFromFindStr( data, "model=" );
}

//----------------------------------------------
//      GET    DEVICE  ADDR (id 1)
std::string DeviceStr::GetAddr( const std::string & data )
{
    return help::GetItemFromFindStr( data, "address=" );
}

//----------------------------------------------
//      GET    DEVICE     PORT (id 2)
std::string DeviceStr::GetPort( const std::string & data )
{
      std::string port = help::GetItemFromFindStr( data, "port=" );

        if( port.size() )
        {
            return port;    
        }
        else
        {
           return "0";
        }
}

//----------------------------------------------
//      GET    DEVICE       INTERFACE
std::string DeviceStr::GetInterface( const std::string & data )
{
    return help::GetItemFromFindStr( data, "interface=" );
}

//----------------------------------------------
//      GET    FW       VER
uint16_t DLL_EXPORT DeviceStr::GetFwVer( const std::string & data )
{
    std::string fwVerStr = help::GetItemFromFindStr( data, "firmwareRev=" );
    return help::Str2uShort( fwVerStr, true);
}