library/src/utility/BP-StringFormattingSessions.cc
// Search through a string formatting session for all entries matching parameters set within
// query structure.
Search through a string formatting session for all entries matching parameters set within
query structure.
Search through a string formatting session for all entries matching parameters set within query structure .
P_BP_SFS_SEARCH_RESULTS BP_SearchStringFormattingSession(P_BP_SF_SESSION session, P_BP_SFS_SEARCH_QUERY query)
{
	if(!session || !query)
		return NULL;
	if(!session->tq)
		return NULL;
	P_BP_SFS_SEARCH_RESULTS results = (P_BP_SFS_SEARCH_RESULTS) tq_calloc
	(
			session->tq,
			sizeof(BP_SFS_SEARCH_RESULTS),
			1,
			BPLN
	);
	results->session = session;
	size_t row_group_id_len    = 0;
	size_t row_id_len          = 0;
	size_t column_group_id_len = 0;
	size_t column_id_len       = 0;
	size_t string_entry_len    = 0;
	if(query->row_group_id)
		row_group_id_len = bpstrlen(query->row_group_id);
	if(query->row_id)
		row_id_len = bpstrlen(query->row_id);
	if(query->column_group_id)
		column_group_id_len = bpstrlen(query->column_group_id);
	if(query->column_id)
		column_id_len = bpstrlen(query->column_id);
	if(query->string_entry_id)
		string_entry_len = bpstrlen(query->string_entry_id);
	size_t row_group_n    = 0;
	size_t row_n          = 0;
	size_t column_group_n = 0;
	size_t column_n       = 0;
	size_t string_entry_n = 0;
	if(!row_group_id_len || !query->row_group_id)
		return NULL;
	P_BP_SF_SESSION               session_candidate = NULL;
	P_BP_SFS_STRING_ROW_GROUP     row_group_candidate = NULL;
	P_BP_SFS_STRING_ROW           row_candidate = NULL;
	P_BP_SFS_STRING_COLUMN_GROUP  column_group_candidate = NULL;
	P_BP_SFS_STRING_COLUMN        column_candidate = NULL;
	P_BP_SFS_STRING_ENTRY         string_entry_candidate = NULL;
	if(session->row_group_n)
	for(; row_group_n < session->row_group_n; row_group_n++)
	{
		session_candidate      = NULL;
		row_group_candidate    = NULL;
		row_candidate          = NULL;
		column_group_candidate = NULL;
		column_candidate       = NULL;
		string_entry_candidate = NULL;
		session_candidate = session;
		row_group_candidate = session_candidate->row_groups[row_group_n];
		if(row_group_id_len != row_group_candidate->row_group_identifier_len)
		{
			row_group_candidate = NULL;
			continue;
		}
		if
		(
			memcmp
			(
				row_group_candidate->row_group_identifier,
				query->row_group_id,
				row_group_id_len
			) != 0
		)
		{
			row_group_candidate = NULL;
			continue;
		}
		if(!row_group_candidate)
			continue;
		%
		%
		if(row_group_candidate->row_n && row_id_len)
		{
			for
			(
					row_n = 0;
					row_n < row_group_candidate->row_n;
					row_n++
			)
			{
				row_candidate = row_group_candidate->rows[row_n];
				if(row_candidate->row_identifier_len == row_id_len)
				if
				(
					memcmp
					(
						row_candidate->row_identifier,
						query->row_id,
						row_id_len
					) != 0
				)
				{
					row_candidate = NULL;
					continue;
				}
				%
				%
				if(row_candidate->col_group_n && column_group_id_len)
				{
					for
					(
						column_group_n = 0;
						column_group_n < row_candidate->col_group_n;
						column_group_n++
					)
					{
						column_group_candidate = row_candidate->col_groups[column_group_n];
						if(column_group_candidate->column_group_identifier_len == column_group_id_len)
						if
						(
							memcmp
							(
								column_group_candidate->column_group_identifier,
								query->column_group_id,
								column_group_id_len
							) != 0
						)
						{
							column_group_candidate = NULL;
							continue;
						}
					}
					if(!column_group_candidate)
						continue;
					%
					%
					if(column_group_candidate->columns && column_id_len)
					{
						for
						(
							column_n = 0;
							column_n < column_group_candidate->columns_n;
							column_n++
						)
						{
							column_candidate = column_group_candidate->columns[column_n];
							if(column_candidate->column_identifier_len == column_id_len)
							if
							(
								memcmp
								(
									column_candidate->column_identifier,
									query->column_id,
									column_id_len
								) != 0
							)
							{
								column_candidate = NULL;
								continue;
							}
							%
							%
							if(column_candidate->col_data && string_entry_len)
							{
								for
								(
									string_entry_n = 0;
									string_entry_n < column_candidate->entries;
									string_entry_n++
								)
								{
									string_entry_candidate = column_candidate->col_data[string_entry_n];
									if(string_entry_candidate->string_entry_identifier_len == string_entry_len)
									{
										if
										(
											memcmp
											(
												string_entry_candidate->string_entry_identifier,
												query->string_entry_id,
												string_entry_len
											) != 0
										)
										{
											string_entry_candidate = NULL;
											continue;
										}
										else
										{
											if(string_entry_candidate)
											BP_AddStringResultEntryToSFSSearchResults
											(
												results,
												session_candidate,
												row_group_candidate,
												row_candidate,
												column_group_candidate,
												column_candidate,
												string_entry_candidate
											);
										}
									}
								}
							}
							else
							{
								if(!string_entry_len)
								if(column_id_len == column_candidate->column_identifier_len)
								{
									if
									(
										memcmp
										(
											column_candidate->column_identifier,
											query->column_id,
											column_candidate->column_identifier_len
										) == 0
									)
									{
										BP_AddStringResultEntryToSFSSearchResults
										(
											results,
											session_candidate,
											row_group_candidate,
											row_candidate,
											column_group_candidate,
											column_candidate,
											string_entry_candidate
										);
									}
								}
							}
						}
					}
					else
					{
						if(!column_id_len)
						if(column_group_id_len == column_group_candidate->column_group_identifier_len)
						{
							if
							(
								memcmp
								(
									column_group_candidate->column_group_identifier,
									query->column_group_id,
									column_group_candidate->column_group_identifier_len
								) == 0
							)
							{
								BP_AddStringResultEntryToSFSSearchResults
								(
									results,
									session_candidate,
									row_group_candidate,
									row_candidate,
									column_group_candidate,
									column_candidate,
									string_entry_candidate
								);
							}
						}
					} 
				}
				else
				{
					if(!column_group_id_len)
					if(row_id_len == row_candidate->row_identifier_len)
					{
						if
						(
								memcmp
								(
									row_candidate->row_identifier,
									query->row_id,
									row_candidate->row_identifier_len
								) == 0
						)
						{
							BP_AddStringResultEntryToSFSSearchResults
							(
								results,
								session_candidate,
								row_group_candidate,
								row_candidate,
								column_group_candidate,
								column_candidate,
								string_entry_candidate
							);
						}
					}
				}
			} 
		}
		else
		{
			if(!row_id_len)
			if(row_group_id_len == row_group_candidate->row_group_identifier_len)
			{
				if
				(
						memcmp
						(
							row_group_candidate->row_group_identifier,
							query->row_group_id,
							row_group_candidate->row_group_identifier_len
						) == 0
				)
				{
					BP_AddStringResultEntryToSFSSearchResults
					(
						results,
						session_candidate,
						row_group_candidate,
						row_candidate,
						column_group_candidate,
						column_candidate,
						string_entry_candidate
					);
				}
			}
		} 
	}
	return results;
}
P_BP_SFS_SEARCH_RESULTS BP_SearchStringFormattingSession ( P_BP_SF_SESSION session , P_BP_SFS_SEARCH_QUERY query ) { if ( ! session || ! query ) return NULL ; if ( ! session -> tq ) return NULL ; P_BP_SFS_SEARCH_RESULTS results = ( P_BP_SFS_SEARCH_RESULTS ) tq_calloc ( session -> tq , sizeof ( BP_SFS_SEARCH_RESULTS ) , 1 , BPLN ) ; results -> session = session ; size_t row_group_id_len = 0 ; size_t row_id_len = 0 ; size_t column_group_id_len = 0 ; size_t column_id_len = 0 ; size_t string_entry_len = 0 ; if ( query -> row_group_id ) row_group_id_len = bpstrlen ( query -> row_group_id ) ; if ( query -> row_id ) row_id_len = bpstrlen ( query -> row_id ) ; if ( query -> column_group_id ) column_group_id_len = bpstrlen ( query -> column_group_id ) ; if ( query -> column_id ) column_id_len = bpstrlen ( query -> column_id ) ; if ( query -> string_entry_id ) string_entry_len = bpstrlen ( query -> string_entry_id ) ; size_t row_group_n = 0 ; size_t row_n = 0 ; size_t column_group_n = 0 ; size_t column_n = 0 ; size_t string_entry_n = 0 ; if ( ! row_group_id_len || ! query -> row_group_id ) return NULL ; P_BP_SF_SESSION session_candidate = NULL ; P_BP_SFS_STRING_ROW_GROUP row_group_candidate = NULL ; P_BP_SFS_STRING_ROW row_candidate = NULL ; P_BP_SFS_STRING_COLUMN_GROUP column_group_candidate = NULL ; P_BP_SFS_STRING_COLUMN column_candidate = NULL ; P_BP_SFS_STRING_ENTRY string_entry_candidate = NULL ; if ( session -> row_group_n ) for ( ; row_group_n < session -> row_group_n ; row_group_n ++ ) { session_candidate = NULL ; row_group_candidate = NULL ; row_candidate = NULL ; column_group_candidate = NULL ; column_candidate = NULL ; string_entry_candidate = NULL ; session_candidate = session ; row_group_candidate = session_candidate -> row_groups [ row_group_n ] ; if ( row_group_id_len != row_group_candidate -> row_group_identifier_len ) { row_group_candidate = NULL ; continue ; } if ( memcmp ( row_group_candidate -> row_group_identifier , query -> row_group_id , row_group_id_len ) != 0 ) { row_group_candidate = NULL ; continue ; } if ( ! row_group_candidate ) continue ; if ( row_group_candidate -> row_n && row_id_len ) { for ( row_n = 0 ; row_n < row_group_candidate -> row_n ; row_n ++ ) { row_candidate = row_group_candidate -> rows [ row_n ] ; if ( row_candidate -> row_identifier_len == row_id_len ) if ( memcmp ( row_candidate -> row_identifier , query -> row_id , row_id_len ) != 0 ) { row_candidate = NULL ; continue ; } if ( row_candidate -> col_group_n && column_group_id_len ) { for ( column_group_n = 0 ; column_group_n < row_candidate -> col_group_n ; column_group_n ++ ) { column_group_candidate = row_candidate -> col_groups [ column_group_n ] ; if ( column_group_candidate -> column_group_identifier_len == column_group_id_len ) if ( memcmp ( column_group_candidate -> column_group_identifier , query -> column_group_id , column_group_id_len ) != 0 ) { column_group_candidate = NULL ; continue ; } } if ( ! column_group_candidate ) continue ; if ( column_group_candidate -> columns && column_id_len ) { for ( column_n = 0 ; column_n < column_group_candidate -> columns_n ; column_n ++ ) { column_candidate = column_group_candidate -> columns [ column_n ] ; if ( column_candidate -> column_identifier_len == column_id_len ) if ( memcmp ( column_candidate -> column_identifier , query -> column_id , column_id_len ) != 0 ) { column_candidate = NULL ; continue ; } if ( column_candidate -> col_data && string_entry_len ) { for ( string_entry_n = 0 ; string_entry_n < column_candidate -> entries ; string_entry_n ++ ) { string_entry_candidate = column_candidate -> col_data [ string_entry_n ] ; if ( string_entry_candidate -> string_entry_identifier_len == string_entry_len ) { if ( memcmp ( string_entry_candidate -> string_entry_identifier , query -> string_entry_id , string_entry_len ) != 0 ) { string_entry_candidate = NULL ; continue ; } else { if ( string_entry_candidate ) BP_AddStringResultEntryToSFSSearchResults ( results , session_candidate , row_group_candidate , row_candidate , column_group_candidate , column_candidate , string_entry_candidate ) ; } } } } else { if ( ! string_entry_len ) if ( column_id_len == column_candidate -> column_identifier_len ) { if ( memcmp ( column_candidate -> column_identifier , query -> column_id , column_candidate -> column_identifier_len ) == 0 ) { BP_AddStringResultEntryToSFSSearchResults ( results , session_candidate , row_group_candidate , row_candidate , column_group_candidate , column_candidate , string_entry_candidate ) ; } } } } } else { if ( ! column_id_len ) if ( column_group_id_len == column_group_candidate -> column_group_identifier_len ) { if ( memcmp ( column_group_candidate -> column_group_identifier , query -> column_group_id , column_group_candidate -> column_group_identifier_len ) == 0 ) { BP_AddStringResultEntryToSFSSearchResults ( results , session_candidate , row_group_candidate , row_candidate , column_group_candidate , column_candidate , string_entry_candidate ) ; } } } } else { if ( ! column_group_id_len ) if ( row_id_len == row_candidate -> row_identifier_len ) { if ( memcmp ( row_candidate -> row_identifier , query -> row_id , row_candidate -> row_identifier_len ) == 0 ) { BP_AddStringResultEntryToSFSSearchResults ( results , session_candidate , row_group_candidate , row_candidate , column_group_candidate , column_candidate , string_entry_candidate ) ; } } } } } else { if ( ! row_id_len ) if ( row_group_id_len == row_group_candidate -> row_group_identifier_len ) { if ( memcmp ( row_group_candidate -> row_group_identifier , query -> row_group_id , row_group_candidate -> row_group_identifier_len ) == 0 ) { BP_AddStringResultEntryToSFSSearchResults ( results , session_candidate , row_group_candidate , row_candidate , column_group_candidate , column_candidate , string_entry_candidate ) ; } } } } return results ; }
Search through a string formatting session for all entries matching parameters set within
query structure.
Search through a string formatting session for all entries matching parameters set within query structure .
// ensure we have a query // ensure we have a tail queue allocator // allocate space for results // set the session // first search for row group // next search for row // next search for column group // next search for column // next search for string entry // set search value length indicators // set row group id length (if necessary) // set row id length (if necessary) // set column group id length (if necessary) // set column id (if necessary) // set string entry length if necessary // row iterators // we must at least have a row group id for searching // search result candidates // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Cascading Search Entry Point %%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // walk row groups // reset all candidates on loop // cascade and set candidates // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // 1) Run exclusionary group checks %%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // printf("\n Got Row Group Id Len?: %u - %u", row_group_id_len, row_group_candidate->row_group_identifier_len); // set row group candidate // ensure lengths match up // if the length check passed, run memory compare check // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // 2) Row Cascading Checks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // walk rows and search // set row candidate as current row // run candidate checks // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // 2) Column Group Cascading Checks %%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set row candidate as current row // run candidate checks // ensure we have a column group candidate // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // 4) Column Group Cascading Checks %%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set row candidate as current row // run candidate checks // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // 5) String Entry Cascading Checks %%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set string entry candidate // run candidate checks // add result if we have a match and no row_id to match // ensure that we have a memory wise match // add result if we have a match and no row_id to match // ensure that we have a memory wise match // end cascading row search for() column group // add result if we have a match and no row_id to match // ensure that we have a memory wise match // end cascading row search for() column group // add result if we have a match and no row_id to match // ensure that we have a memory wise match // end cascading row search for() row group // return the pointer