OpenScop  0.9.0
strings.h
Go to the documentation of this file.
00001 
00002     /*+-----------------------------------------------------------------**
00003      **                       OpenScop Library                          **
00004      **-----------------------------------------------------------------**
00005      **                           strings.h                             **
00006      **-----------------------------------------------------------------**
00007      **                   First version: 13/07/2011                     **
00008      **-----------------------------------------------------------------**
00009 
00010  
00011  *****************************************************************************
00012  * OpenScop: Structures and formats for polyhedral tools to talk together    *
00013  *****************************************************************************
00014  *    ,___,,_,__,,__,,__,,__,,_,__,,_,__,,__,,___,_,__,,_,__,                *
00015  *    /   / /  //  //  //  // /   / /  //  //   / /  // /  /|,_,             *
00016  *   /   / /  //  //  //  // /   / /  //  //   / /  // /  / / /\             *
00017  *  |~~~|~|~~~|~~~|~~~|~~~|~|~~~|~|~~~|~~~|~~~|~|~~~|~|~~~|/_/  \            *
00018  *  | G |C| P | = | L | P |=| = |C| = | = | = |=| = |=| C |\  \ /\           *
00019  *  | R |l| o | = | e | l |=| = |a| = | = | = |=| = |=| L | \# \ /\          *
00020  *  | A |a| l | = | t | u |=| = |n| = | = | = |=| = |=| o | |\# \  \         *
00021  *  | P |n| l | = | s | t |=| = |d| = | = | = | |   |=| o | | \# \  \        *
00022  *  | H | | y |   | e | o | | = |l|   |   | = | |   | | G | |  \  \  \       *
00023  *  | I | |   |   | e |   | |   | |   |   |   | |   | |   | |   \  \  \      *
00024  *  | T | |   |   |   |   | |   | |   |   |   | |   | |   | |    \  \  \     *
00025  *  | E | |   |   |   |   | |   | |   |   |   | |   | |   | |     \  \  \    *
00026  *  | * |*| * | * | * | * |*| * |*| * | * | * |*| * |*| * | /      \* \  \   *
00027  *  | O |p| e | n | S | c |o| p |-| L | i | b |r| a |r| y |/        \  \ /   *
00028  *  '---'-'---'---'---'---'-'---'-'---'---'---'-'---'-'---'          '--'    *
00029  *                                                                           *
00030  * Copyright (C) 2008 University Paris-Sud 11 and INRIA                      *
00031  *                                                                           *
00032  * (3-clause BSD license)                                                    *
00033  * Redistribution and use in source  and binary forms, with or without       *
00034  * modification, are permitted provided that the following conditions        *
00035  * are met:                                                                  *
00036  *                                                                           *
00037  * 1. Redistributions of source code must retain the above copyright notice, *
00038  *    this list of conditions and the following disclaimer.                  *
00039  * 2. Redistributions in binary form must reproduce the above copyright      *
00040  *    notice, this list of conditions and the following disclaimer in the    *
00041  *    documentation and/or other materials provided with the distribution.   *
00042  * 3. The name of the author may not be used to endorse or promote products  *
00043  *    derived from this software without specific prior written permission.  *
00044  *                                                                           *
00045  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR      *
00046  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES *
00047  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.   *
00048  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,          *
00049  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT  *
00050  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
00051  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY     *
00052  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT       *
00053  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF  *
00054  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.         *
00055  *                                                                           *
00056  * OpenScop Library, a library to manipulate OpenScop formats and data       *
00057  * structures. Written by:                                                   *
00058  * Cedric Bastoul     <Cedric.Bastoul@u-psud.fr> and                         *
00059  * Louis-Noel Pouchet <Louis-Noel.pouchet@inria.fr>                          *
00060  *                                                                           *
00061  *****************************************************************************/
00062 
00063 
00064 #ifndef OSL_STRINGS_H
00065 # define OSL_STRINGS_H
00066 
00067 # include <stdio.h>
00068 # include <osl/interface.h>
00069 
00070 # if defined(__cplusplus)
00071 extern "C"
00072   {
00073 # endif
00074 
00075 # define OSL_URI_STRINGS "strings"
00076 
00077 /* The "strings" type is simply a NULL-terminated array of C character
00078  * strings, i.e. a char **. It is encapsulated into a structure to allow
00079  * its manipulation through a generic type.
00080  */
00081 struct osl_strings {
00082   char ** string; 
00083 };
00084 typedef struct osl_strings               osl_strings_t;
00085 typedef struct osl_strings       *       osl_strings_p;
00086 typedef struct osl_strings const         osl_const_strings_t;
00087 typedef struct osl_strings       * const osl_strings_const_p;
00088 typedef struct osl_strings const *       osl_const_strings_p;
00089 typedef struct osl_strings const * const osl_const_strings_const_p;
00090 
00091 
00092 /*+***************************************************************************
00093  *                          Structure display function                       *
00094  *****************************************************************************/
00095 void            osl_strings_idump(FILE *, osl_strings_p, int);
00096 void            osl_strings_dump(FILE *, osl_strings_p);
00097 char *          osl_strings_sprint(osl_strings_p);
00098 void            osl_strings_print(FILE *, osl_strings_p);
00099 
00100 
00101 /*****************************************************************************
00102  *                               Reading function                            *
00103  *****************************************************************************/
00104 osl_strings_p   osl_strings_sread(char **);
00105 osl_strings_p   osl_strings_read(FILE *);
00106 
00107 /*+***************************************************************************
00108  *                    Memory allocation/deallocation function                *
00109  *****************************************************************************/
00110 osl_strings_p   osl_strings_malloc();
00111 void            osl_strings_free(osl_strings_p);
00112 
00113 /*+***************************************************************************
00114  *                            Processing functions                           *
00115  *****************************************************************************/
00116 osl_strings_p   osl_strings_clone(osl_strings_p);
00117 void            osl_strings_add(osl_strings_p, char const * const);
00118 size_t          osl_strings_find(osl_strings_p, char const * const);
00119 int             osl_strings_equal(osl_strings_p, osl_strings_p);
00120 size_t          osl_strings_size(osl_const_strings_const_p);
00121 osl_strings_p   osl_strings_encapsulate(char *);
00122 osl_interface_p osl_strings_interface();
00123 osl_strings_p   osl_strings_generate(char *, int);
00124 
00125 
00126 # if defined(__cplusplus)
00127   }
00128 # endif
00129 
00130 # if defined(__cplusplus)
00131 #include <vector>
00132 #include <string>
00133 
00134 namespace osl
00135 {
00141   inline
00142   std::vector<std::string> osl_strings_to_cpp(osl_const_strings_const_p s) {
00143     if (s != nullptr && s->string != nullptr) {
00144       return std::vector<std::string>(s->string,
00145                                       s->string + osl_strings_size(s));
00146     }
00147     else { return std::vector<std::string>(); }
00148   }
00149 }
00150 # endif
00151 
00152 #endif /* define OSL_STRINGS_H */