void OscReceiver::ProcessMessage( const osc::ReceivedMessage& m, const IpEndpointName& ){ boost::regex top_re("^/datajockey/(\\w*)(.*)$"); boost::regex mixer_re("^mixer$"); boost::regex xfade_re("^crossfade$"); boost::regex master_re("^master$"); boost::cmatch matches; std::string addr; try { if(boost::regex_match(m.AddressPattern(), matches, top_re)){ std::string sub_match(matches[1]); if(boost::regex_match(sub_match, mixer_re)){ processMixerMessage(matches[2], m); } else if(boost::regex_match(sub_match, master_re)){ processMasterMessage(matches[2], m); } else if(boost::regex_match(sub_match, xfade_re)){ processXFadeMessage(matches[2], m); } } } catch( osc::Exception& e ){ std::cerr << "An Exception occured while processing incoming OSC packets." << std::endl; std::cerr << e.what() << std::endl; } }
void init(int max_length) { seg_parts = new int[max_length + 1]; seg_part_len = new int*[max_length + 1]; seg_part_pos = new int*[max_length + 1]; indexes = new HashMap<size_t, vector<int>>*[max_length + 1]; for (int len = 1; len <= max_length; len++) { int to_match_len = helper->max_possible_length(len); seg_parts[len] = len + to_match_len - 2 * helper->require_overlap(len, to_match_len) + 1 + 1e-6; int part = seg_parts[len]; indexes[len] = new HashMap<size_t, vector<int>>[part]; seg_part_pos[len] = new int[part + 1]; seg_part_len[len] = new int[part]; int larger_num = len - len / part * part; for (int k = 0; k < part - larger_num; k++) { seg_part_len[len][k] = len / part; } for (int k = part - larger_num; k < part; k++) { seg_part_len[len][k] = len / part + 1; } seg_part_pos[len][0] = 0; for (int k = 1; k <= part; k++) { seg_part_pos[len][k] = seg_part_pos[len][k - 1] + seg_part_len[len][k - 1]; } assert(seg_part_pos[len][part] == len); } sub_matches = new vector<sub_match>[max_length + 1]; for (int len = 1; len <= max_length; len++) { for (int match_len = len; match_len <= min(helper->max_possible_length(len), max_length); match_len++) { int overlap = helper->require_overlap(len, match_len); int hr = match_len - overlap; int hs = len - overlap; for (int part = 0; part < seg_parts[match_len]; part++) { int p = seg_part_pos[match_len][part]; int l = seg_part_len[match_len][part]; int low = max(0, max(p - hr, p - part)); int high = min(len - l, min(p + hs, p + len - match_len + seg_parts[match_len] - part - 1)); for (int s = low; s <= high; s++) { sub_matches[len].push_back(sub_match()); sub_match &last = sub_matches[len].back(); last.match_len = match_len; last.match_part = part; last.start_pos = s; last.part_len = l; } } } } }
static bool do_match (const char* string, char** sub_pats, int n_sub_pats, bool star_at_start, bool star_at_end) { for (int i = 1; i <= n_sub_pats; i++) { int string_len = strlen (string); /* string mustn't be exhausted while sub-patterns remain */ if (string_len == 0) return false; /* with, eg, string = "abcdefg", and sub-pattern "d?", try: abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg d? d? d? d? d? d? here, string_len = 7, pat_len = 2 */ int pat_len = n_chars_in_pattern (sub_pats[i]); int first_position = 0; int last_position = string_len - pat_len; /* musn't slide first sub-pattern if no stars at start of whole pattern */ if (i == 1 && !star_at_start) last_position = 0; /* last sub-pattern must match end of string if no stars at end of whole pattern */ else if (i == n_sub_pats && !star_at_end) first_position = last_position; /* here, last_position = 5, so match at positions 0,1,2,3,4,5 */ /* slide the pattern along the string, looking for a match. Sliding is permissible if the sub-pattern has stars before and after it */ int j; bool matched; for (j = first_position, matched = false; j <= last_position; j++) { if (j < 0) continue; // recent bug / == *.doc if (sub_match (string+j, sub_pats[i])) { matched = true; break; } } /* give up if match failure */ if (!matched) return false; /* step over the matched characters in the string with, eg, string = "abcdefg", and sub-pattern "d?", match will occur with j = 3, and string will reduce to "fg" */ string += j + pat_len; } /* end of sub-patterns - match ok if string exhausted or star at end*/ return strlen (string) == 0 || star_at_end; }