ws/types.h
Go to the documentation of this file.
00001 /* 00002 * Copyright 2006-2009 Savarese Software Research Corporation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * https://www.savarese.com/software/ApacheLicense-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00022 #ifndef __SSRC_WSPR_WS_TYPES_H 00023 #define __SSRC_WSPR_WS_TYPES_H 00024 00025 #include <ssrc/wispers/ws/protocol.h> 00026 #include <boost/regex.hpp> 00027 #include <boost/ptr_container/ptr_vector.hpp> 00028 00029 __BEGIN_NS_SSRC_WSPR_WS 00030 00031 typedef 00032 boost::function<void (const WebServiceCall &, 00033 const NS_SSRC_WISP_PROTOCOL::MessageInfo &)> 00034 call_handler_type; 00035 00036 typedef std::unordered_map<string, call_handler_type> call_handler_map; 00037 00038 struct CallParameter { 00039 /* 00040 enum ParameterType { 00041 Nil = LUA_TNIL, 00042 Boolean = LUA_TBOOLEAN, 00043 LightUserData = LUA_TLIGHTUSERDATA, 00044 Number = LUA_TNUMBER, 00045 String = LUA_TSTRING, 00046 Table = LUA_TTABLE, 00047 Function = LUA_TFUNCTION, 00048 UserData = LUA_TUSERDATA, 00049 Thread = LUA_TTHREAD 00050 }; 00051 00052 parameter_type type; 00053 */ 00054 const bool multi_value; 00055 const bool optional; 00056 const unsigned int min_size; 00057 const unsigned int max_size; 00058 const string name; 00059 00060 CallParameter(const string & name, 00061 const unsigned int min_size = 1, 00062 const unsigned int max_size = 128, 00063 const bool multi_value = false, 00064 const bool optional = false) : 00065 multi_value(multi_value), optional(optional), 00066 min_size(min_size), max_size(max_size), name(name) 00067 { } 00068 00069 inline virtual bool validate(const string & value) const { 00070 return (value.size() >= min_size && value.size() <= max_size); 00071 } 00072 }; 00073 00074 struct PatternParameter : public CallParameter { 00075 typedef CallParameter super; 00076 const boost::regex pattern; 00077 00078 PatternParameter(const string & name, 00079 const string & pattern, 00080 const unsigned int min_size = 1, 00081 const unsigned int max_size = 128, 00082 const bool multi_value = false, 00083 const bool optional = false) : 00084 super(name, min_size, max_size, multi_value, optional), 00085 pattern(pattern) 00086 { } 00087 00088 inline virtual bool validate(const string & value) const { 00089 return (super::validate(value) && boost::regex_match(value, pattern)); 00090 } 00091 }; 00092 00093 typedef boost::ptr_vector<CallParameter> parameter_sequence; 00094 00095 __END_NS_SSRC_WSPR_WS 00096 00097 #endif
Copyright © 2006-2011 Savarese Software Research Corporation. All rights reserved.