本文整理汇总了C++中json::value::get方法的典型用法代码示例。如果您正苦于以下问题:C++ value::get方法的具体用法?C++ value::get怎么用?C++ value::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::value
的用法示例。
在下文中一共展示了value::get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set_checkbox_bits
// sets checkboxes by bit mask
inline void set_checkbox_bits(dom::element& el, const json::value& t )
{
selected_cb selected;
dom::element r = el.parent(); // ATTN: I assume here that all checkboxes in the group belong to the same parent!
r.find_all(&selected, "[type='checkbox'][name='%S']", el.get_attribute("name"));
int m = 1, v = selected.elements.size()==1?(t.get(false)?1:0):t.get(0);
for( unsigned int n = 0; n < selected.elements.size(); ++n, m <<= 1 )
{
dom::element& e = selected.elements[n];
if( (v & m) != 0)
e.set_state( STATE_CHECKED, 0 ) ;
else
e.set_state( 0, STATE_CHECKED ) ;
}
}
示例2: cppcms_error
cache_pool::cache_pool(json::value const &settings) :
d(new _data())
{
std::string type = settings.get("cache.backend","none");
#ifndef CPPCMS_NO_CACHE
if(type=="thread_shared") {
if(settings.get("service.worker_processes",0)>1)
throw cppcms_error(
"Can't use `thread_shared' backend with more then one process ether set "
"service.worker_processes to 0 or 1 or use cache.backend=\"process_shared\"");
unsigned items = settings.get("cache.limit",64);
d->module=impl::thread_cache_factory(items);
}
else if(type=="process_shared") {
#if defined(CPPCMS_WIN32)
throw cppcms_error("The 'process_shared' backend is not supported under MS Windows and Cygwin platforms");
#elif defined(CPPCMS_NO_PREFOK_CACHE)
throw cppcms_error("The 'process_shared' backend is disabled during build procedure");
#else // has prefork cache
size_t memory = settings.get("cache.memory",16384);
if(memory < 64)
throw cppcms_error("'process_shared' cache backend requires at least 64 KB of cache memory: cache.memory >= 64");
unsigned items = settings.get("cache.limit",memory);
d->module=impl::process_cache_factory(memory*1024,items);
#endif // prefork cache
}
else
#endif // no cache
if(type != "none" ) {
throw cppcms_error("Unsupported cache backend `" + type + "'");
}
#ifndef CPPCMS_NO_TCP_CACHE
if(settings.find("cache.tcp").type()==json::is_object) {
std::vector<std::string> ips=settings.get<std::vector<std::string> >("cache.tcp.ips");
std::vector<int> ports = settings.get<std::vector<int> >("cache.tcp.ports");
if(ips.empty() || ports.empty() || ips.size()!=ports.size()) {
throw cppcms_error("Invalid settings in cache.tcp.ports or cache.tcp.ips");
}
booster::intrusive_ptr<impl::base_cache> l1=d->module;
d->module=impl::tcp_cache_factory(ips,ports,l1);
}
#endif // no tcp cace
}
示例3: set_radio_index
inline void set_radio_index( dom::element& el, const json::value& t )
{
selected_cb selected;
dom::element r = el.parent(); // ATTN: I assume here that all radios in the group belong to the same parent!
r.find_all(&selected, "[type='radio'][name='%S']", el.get_attribute("name"));
unsigned int idx = (unsigned int)t.get(0);
for( unsigned int n = 0; n < selected.elements.size(); ++n )
{
dom::element& e = selected.elements[n];
if ( n == idx)
{
e.set_value(json::value(true));
break;
}
}
}
示例4: set_value
/** Set value of the DOM element. Sets value for elements recognized by get_ctl_type() function.
* \param[in] el \b const dom::element&, The element.
* \param[in] v \b const json::value&, The value.
**/
inline void set_value(dom::element& el, const json::value& v )
{
switch(get_ctl_type(el))
{
case CTL_UNKNOWN: break;
case CTL_EDIT:
case CTL_DECIMAL:
case CTL_CURRENCY:
case CTL_PASSWORD:
case CTL_NUMERIC:
case CTL_PROGRESS:
case CTL_SLIDER:
case CTL_SELECT_SINGLE:
case CTL_SELECT_MULTIPLE:
case CTL_DD_SELECT:
case CTL_TEXTAREA:
case CTL_DATE:
case CTL_CALENDAR:
case CTL_HIDDEN:
default:
el.set_value(v);
break;
// special cases:
case CTL_BUTTON: break;
case CTL_CHECKBOX: set_checkbox_bits(el,v); break;
case CTL_RADIO: set_radio_index(el,v); break;
case CTL_HTMLAREA:
{
aux::w2utf utf8(static_cast<const wchar_t*>(v.get( L"" )));
el.set_html( utf8, utf8.length() );
//el.update();
} break;
case CTL_NO:
assert(false);
break;
}
}
示例5: set_glass
json::value main_frame::set_glass(json::value on_off)
{
json::value pv = get_glass();
switch_glass(on_off.get(false));
return pv;
}
示例6: daemonize
void daemonizer::daemonize(json::value const &conf)
{
if(getppid() == 1)
return;
if(!conf.get("daemon.enable",false))
return;
int gid = -1;
int uid = -1;
int devnull_fd = -1;
int lock_fd = -1;
try {
devnull_fd = open("/dev/null",O_RDWR);
if(devnull_fd < 0) {
int err = errno;
throw cppcms_error(err,"Failed to open /dev/null");
}
std::string group = conf.get("daemon.group","");
if(!group.empty()) {
struct group *gr = getgrnam(group.c_str());
if(!gr)
throw cppcms_error("Invalid group " + group);
gid = gr->gr_gid;
}
std::string user = conf.get("daemon.user","");
if(!user.empty()) {
struct passwd *pw = getpwnam(user.c_str());
if(!pw)
throw cppcms_error("Invalid user " + user);
uid = pw->pw_uid;
if(gid==-1)
gid = pw->pw_gid;
}
std::string chroot_dir = conf.get("daemon.chroot","");
if(!chroot_dir.empty()) {
global_urandom_fd = open("/dev/urandom",O_RDONLY);
if(global_urandom_fd < 0) {
int err = errno;
throw cppcms_error(err,"Failed to open /dev/urandom");
}
if(chdir(chroot_dir.c_str()) < 0) {
int err = errno;
throw cppcms_error(err,"Failed to chdir to " + chroot_dir);
}
if(chroot(chroot_dir.c_str()) < 0) {
int err = errno;
throw cppcms_error(err,"Failed to chroot to " + chroot_dir);
}
}
int fd_limit = conf.get("daemon.fdlimit",-1);
if(fd_limit != -1) {
struct rlimit lm;
lm.rlim_cur = fd_limit;
lm.rlim_max = fd_limit;
if(setrlimit(RLIMIT_NOFILE,&lm) < 0) {
int err = errno;
throw cppcms_error(err,"Failed to change daemon.fdlimit");
}
}
if(gid!=-1) {
if(setgid(gid) < 0) {
int err = errno;
throw cppcms_error(err,"Failed setgid to group " + group);
}
}
if(uid!=-1) {
if(setuid(uid) < 0) {
int err = errno;
throw cppcms_error(err,"Failed setuid to user " + user);
}
}
std::string lock_file = conf.get("daemon.lock","");
if(!lock_file.empty()) {
if(lock_file[0]!='/') {
char *wd = 0;
std::vector<char> buf(256);
while((wd=getcwd(&buf.front(),buf.size()))==0 && errno==ERANGE)
buf.resize(buf.size()*2);
if(!wd) {
int err=errno;
throw cppcms_error(err,"getcwd failed");
}
lock_file=wd + ("/" + lock_file);
}
//.........这里部分代码省略.........