本文整理汇总了C++中ola::StringToInt方法的典型用法代码示例。如果您正苦于以下问题:C++ ola::StringToInt方法的具体用法?C++ ola::StringToInt怎么用?C++ ola::StringToInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ola
的用法示例。
在下文中一共展示了ola::StringToInt方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: StartHook
bool ArtNetDevice::StartHook() {
unsigned int subnet = 0;
StringToInt(m_preferences->GetValue(K_SUBNET_KEY), &subnet);
unsigned int net;
StringToInt(m_preferences->GetValue(K_NET_KEY), &net);
ola::network::Interface interface;
auto_ptr<ola::network::InterfacePicker> picker(
ola::network::InterfacePicker::NewPicker());
ola::network::InterfacePicker::Options options;
options.include_loopback = m_preferences->GetValueAsBool(K_LOOPBACK_KEY);
if (!picker->ChooseInterface(
&interface,
m_preferences->GetValue(K_IP_KEY),
options)) {
OLA_INFO << "Failed to find an interface";
return false;
}
ArtNetNodeOptions node_options;
node_options.always_broadcast = m_preferences->GetValueAsBool(
K_ALWAYS_BROADCAST_KEY);
node_options.use_limited_broadcast_address = m_preferences->GetValueAsBool(
K_LIMITED_BROADCAST_KEY);
// OLA Output ports are ArtNet input ports
StringToInt(m_preferences->GetValue(K_OUTPUT_PORT_KEY),
&node_options.input_port_count);
m_node = new ArtNetNode(interface, m_plugin_adaptor, node_options);
m_node->SetNetAddress(net);
m_node->SetSubnetAddress(subnet);
m_node->SetShortName(m_preferences->GetValue(K_SHORT_NAME_KEY));
m_node->SetLongName(m_preferences->GetValue(K_LONG_NAME_KEY));
for (unsigned int i = 0; i < node_options.input_port_count; i++) {
AddPort(new ArtNetOutputPort(this, i, m_node));
}
for (unsigned int i = 0; i < ARTNET_MAX_PORTS; i++) {
AddPort(new ArtNetInputPort(this, i, m_plugin_adaptor, m_node));
}
if (!m_node->Start()) {
DeleteAllPorts();
delete m_node;
m_node = NULL;
return false;
}
ostringstream str;
str << K_DEVICE_NAME << " [" << interface.ip_address << "]";
SetName(str.str());
m_timeout_id = m_plugin_adaptor->RegisterRepeatingTimeout(
POLL_INTERVAL,
NewCallback(m_node, &ArtNetNode::SendPoll));
return true;
}
示例2:
void StringUtilsTest::testStringToUInt8() {
uint8_t value;
OLA_ASSERT_FALSE(StringToInt("", &value));
OLA_ASSERT_FALSE(StringToInt("-1", &value));
OLA_ASSERT_FALSE(StringToInt("256", &value));
OLA_ASSERT_TRUE(StringToInt("0", &value));
OLA_ASSERT_EQ((uint8_t) 0, value);
OLA_ASSERT_TRUE(StringToInt("1", &value));
OLA_ASSERT_EQ((uint8_t) 1, value);
OLA_ASSERT_TRUE(StringToInt("143", &value));
OLA_ASSERT_EQ((uint8_t) 143, value);
OLA_ASSERT_TRUE(StringToInt("255", &value));
OLA_ASSERT_EQ((uint8_t) 255, value);
}
示例3: main
/*
* Main
*/
int main(int argc, char *argv[]) {
TrackerOptions options;
options.help = false;
options.log_level = ola::OLA_LOG_WARN;
ParseOptions(argc, argv, &options);
if (options.help)
DisplayHelpAndExit(argv[0]);
if (options.args.empty())
DisplayHelpAndExit(argv[0]);
vector<unsigned int> universes;
vector<string>::const_iterator iter = options.args.begin();
for (; iter != options.args.end(); ++iter) {
unsigned int universe;
if (!StringToInt(*iter, &universe, true)) {
cerr << "Invalid Universe " << *iter << endl;
exit(ola::EXIT_USAGE);
}
universes.push_back(universe);
}
ola::InitLogging(options.log_level, ola::OLA_LOG_STDERR);
ola::OlaCallbackClientWrapper ola_client;
if (!ola_client.Setup()) {
OLA_FATAL << "Setup failed";
exit(ola::EXIT_UNAVAILABLE);
}
ss = ola_client.GetSelectServer();
UniverseTracker tracker(&ola_client, universes);
ola::InstallSignal(SIGINT, InteruptSignal);
cout << "Actions:" << endl;
cout << " p - Print stats" << endl;
cout << " q - Quit" << endl;
cout << " r - Reset stats" << endl;
bool r = tracker.Run();
if (r)
tracker.PrintStats();
return r;
}
示例4: testStringToInt
void StringUtilsTest::testStringToInt() {
int value;
OLA_ASSERT_FALSE(StringToInt("", &value));
OLA_ASSERT_FALSE(StringToInt("a", &value));
OLA_ASSERT_FALSE(StringToInt("2147483649", &value));
OLA_ASSERT_TRUE(StringToInt("-2147483648", &value));
OLA_ASSERT_EQ(static_cast<int>(-2147483647 - 1), value);
OLA_ASSERT_TRUE(StringToInt("-2147483647", &value));
OLA_ASSERT_EQ(-2147483647, value);
OLA_ASSERT_TRUE(StringToInt("-1", &value));
OLA_ASSERT_EQ(-1, value);
OLA_ASSERT_TRUE(StringToInt("0", &value));
OLA_ASSERT_EQ(0, value);
OLA_ASSERT_TRUE(StringToInt("1", &value));
OLA_ASSERT_EQ(1, value);
OLA_ASSERT_TRUE(StringToInt("143", &value));
OLA_ASSERT_EQ(143, value);
OLA_ASSERT_TRUE(StringToInt("2147483647", &value));
OLA_ASSERT_EQ(2147483647, value);
OLA_ASSERT_FALSE(StringToInt("2147483648", &value));
// strict mode on
OLA_ASSERT_FALSE(StringToInt("2147483649 ", &value, true));
OLA_ASSERT_FALSE(StringToInt("-2147483648bar", &value, true));
OLA_ASSERT_FALSE(StringToInt("-2147483647 baz", &value, true));
OLA_ASSERT_FALSE(StringToInt("-1.", &value, true));
OLA_ASSERT_FALSE(StringToInt("0!", &value, true));
OLA_ASSERT_FALSE(StringToInt("1 this is a test", &value, true));
OLA_ASSERT_FALSE(StringToInt("143car", &value, true));
OLA_ASSERT_FALSE(StringToInt("2147483647 [email protected]#", &value, true));
OLA_ASSERT_FALSE(StringToInt("2147483648mm", &value, true));
}
示例5: testStringToUInt
void StringUtilsTest::testStringToUInt() {
unsigned int value;
OLA_ASSERT_FALSE(StringToInt("", &value));
OLA_ASSERT_FALSE(StringToInt("-1", &value));
OLA_ASSERT_TRUE(StringToInt("0", &value));
OLA_ASSERT_EQ(0u, value);
OLA_ASSERT_TRUE(StringToInt("1", &value));
OLA_ASSERT_EQ(1u, value);
OLA_ASSERT_TRUE(StringToInt("65537", &value));
OLA_ASSERT_EQ(65537u, value);
OLA_ASSERT_TRUE(StringToInt("4294967295", &value));
OLA_ASSERT_EQ(4294967295U, value);
OLA_ASSERT_FALSE(StringToInt("4294967296", &value));
OLA_ASSERT_FALSE(StringToInt("foo", &value));
// same tests with strict mode on
OLA_ASSERT_FALSE(StringToInt("-1 foo", &value, true));
OLA_ASSERT_FALSE(StringToInt("0 ", &value, true));
OLA_ASSERT_FALSE(StringToInt("1 bar baz", &value, true));
OLA_ASSERT_FALSE(StringToInt("65537cat", &value, true));
OLA_ASSERT_FALSE(StringToInt("4294967295bat bar", &value, true));
}