This file is indexed.

/usr/include/lvtk-1/lvtk/ext/atom.hpp is in lvtk-dev 1.2.0~dfsg0-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
/*
    atom.hpp - support file for writing LV2 plugins in C++
    Copyright (C) 2012 Michael Fisher <mfisher31@gmail.com>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 01222-1307  USA
*/

/** @headerfile lvtk/ext/atom.hpp */
/** @page atom LVTK Atom
    C++ convenience wrappers for LV2 Atoms<br />
 */

#ifndef LVTK_ATOM_HPP
#define LVTK_ATOM_HPP

#include <string>

#include <lv2/lv2plug.in/ns/ext/atom/atom.h>
#include <lv2/lv2plug.in/ns/ext/atom/forge.h>
#include <lv2/lv2plug.in/ns/ext/atom/util.h>

namespace lvtk {

   /** Typedefs for an Atom data types */
   typedef LV2_Atom_Event         AtomEvent;
   typedef LV2_Atom_Property_Body PropertyBody;
   typedef LV2_Atom_Forge_Frame   ForgeFrame;
   typedef LV2_Atom_Forge_Ref     ForgeRef;
   typedef LV2_Atom_Object_Query  ObjectQuery;


   /** Basic wrapper for an LV2_Atom_Object
       This class is intended to be created on the stack */
   struct AtomObject
   {
      /** Create an AtomObject from raw data */
      AtomObject (const void* atom) : p_obj ((LV2_Atom_Object*) atom) { }

      /** Create an AtomObject from a ForgeRef */
      AtomObject (ForgeRef ref) : p_obj ((LV2_Atom_Object*) ref) { }

      AtomObject (const AtomObject& other) : p_obj (other.p_obj) { }

      /** Return the object type */
      inline uint32_t
      otype() const
      {
          return p_obj->body.otype;
      }

      /** Return the object's id */
      inline uint32_t
      id() const
      {
          return p_obj->body.id;
      }

      /** Return the object's total size */
      inline uint32_t
      total_size() const
      {
          return lv2_atom_total_size ((LV2_Atom*) p_obj);
      }

      /** Get an object's values for various keys.

          The value pointer of each item in @p query will be set to the location of
          the corresponding value in @p object.  Every value pointer in @p query MUST
          be initialised to NULL.  This function reads @p object in a single linear
          sweep.  By allocating @p query on the stack, objects can be "queried"
          quickly without allocating any memory.  This method is realtime safe.

          This function can only do "flat" queries, it is not smart enough to match
          variables in nested objects.
      */
      inline void
      query (ObjectQuery& query)
      {
          lv2_atom_object_query (p_obj, &query);
      }

      /** Get the underlying LV2_Atom_Object pointer */
      inline LV2_Atom_Object* cobj() const     { return p_obj; }

      /** @internal */
      inline operator LV2_Atom_Object*()       { return p_obj; }

      /** @internal */
      inline AtomObject&
      operator= (const AtomObject& other)
      {
         p_obj = other.p_obj;
         return *this;
      }

      /** A Property Iterator for an AtomObjects */
      class iterator
      {
      public:

          iterator (LV2_Atom_Object* o, LV2_Atom_Property_Body* i)
              : index (i), obj (o) { }

          const PropertyBody& operator*()  const { assert (index); return *index; }
          const PropertyBody* operator->() const { assert (index); return index; }

          iterator& operator++()
          {
              index = lv2_atom_object_next (index);
              if (lv2_atom_object_is_end (&obj->body, obj->atom.size, index))
                  index = 0;
              return *this;
          }

          iterator operator++(int)
          {
              iterator ret (obj, index);
              ++(*this);
              return ret;
          }

          bool operator== (const iterator& other) const { return index == other.index; }
          bool operator!= (const iterator& other) const { return index != other.index; }

      private:

          friend class AtomObject;
          LV2_Atom_Property_Body* index;
          LV2_Atom_Object*        obj;

      };

      iterator begin() const { return iterator (p_obj, lv2_atom_object_begin (&p_obj->body)); }
      iterator end()   const { return iterator (p_obj, 0); }

   private:

      LV2_Atom_Object* p_obj;

   };


   /** Basic wrapper for an LV2_Atom
       These are intended to be used on the stack */
   struct Atom
   {
      /** Create a null Atom */
      Atom () : p_atom (0) { }

      /** Create an Atom from raw data */
      Atom (const void* atom) : p_atom ((LV2_Atom*) atom)  { }

      /** Create an Atom from a Forge Ref */
      Atom (ForgeRef ref) : p_atom ((LV2_Atom*) ref) { }

      /** Create an Atom from an AtomEvent */
      Atom (AtomEvent* ev) : p_atom (&ev->body) { }

      /** Pad a size to 64 bits */
      inline static uint32_t
      pad_size (uint32_t size)
      {
          return lv2_atom_pad_size (size);
      }

      /** Determine if the Atom is null */
      inline bool
      is_null()
      {
          return lv2_atom_is_null (p_atom);
      }

      /** Get the Atom's body */
      inline void*
      body() const
      {
          return LV2_ATOM_BODY (p_atom);
      }

      /** Get the body as a boolean */
      inline bool
      as_bool() const
      {
          return ((LV2_Atom_Bool*)p_atom)->body > 0;
      }

      /** Get the body as a float */
      inline float
      as_float() const
      {
          return ((LV2_Atom_Float*)p_atom)->body;
      }

      /** Returns the atom casted to LV2_Atom_Object */
      const AtomObject
      as_object() const {
          return AtomObject ((LV2_Atom_Object* ) p_atom);
      }

      /** Get the body as a string */
      inline const char*
      as_string() const
      {
          return (const char*) LV2_ATOM_BODY (p_atom);
      }

      /** Get the body as a float */
      inline int32_t
      as_int() const
      {
          return ((LV2_Atom_Int*)p_atom)->body;
      }

      /** Get the body as a long */
      inline int64_t
      as_long() const
      {
          return ((LV2_Atom_Long*)p_atom)->body;
      }

      /** Get the body as a URID */
      inline uint32_t
      as_urid() const
      {
          return ((LV2_Atom_URID*)p_atom)->body;
      }
      /** Get this Atom's type */

      inline uint32_t
      type() const
      {
          return p_atom->type;
      }

      /** Get the Atom's total size */
      inline uint32_t
      total_size() const
      {
          return lv2_atom_total_size (p_atom);
      }

      /** Get the Atom's body size */
      inline uint32_t
      size() const
      {
          return p_atom->size;
      }

      /** Get the underlying LV2_Atom pointer */
      inline const LV2_Atom*
      cobj() const
      {
          return p_atom;
      }

      /** @internal */
      inline operator const LV2_Atom*() { return cobj(); }

      /** @internal */
      inline Atom&
      operator= (const Atom& other)
      {
         p_atom = other.p_atom;
         return *this;
      }

      /** @internal */
      inline bool
      operator== (Atom& other)
      {
          return lv2_atom_equals (cobj(), other.cobj());
      }

   private:

      const LV2_Atom* p_atom;
      friend class AtomObject;

   };


   /** A basic wrapper around LV2_Atom_Sequence  */
   struct AtomSequence
   {
       typedef AtomEvent* pointer;
       typedef AtomEvent& reference;
       typedef const AtomEvent* const_pointer;
       typedef const AtomEvent& const_reference;

       /** Create an AtomSequence from raw data
           @param seq Sequence Pointer (castable to LV2_Atom_Sequence) */
       AtomSequence (const void* seq) : p_seq ((LV2_Atom_Sequence*) seq) { }

       /** Create an AtomSequnce from an LV2_Atom_Sequence
           @param seq The sequence to wrap */
       AtomSequence (LV2_Atom_Sequence* seq) : p_seq (seq) { }

       /** Create an AtomSequence from a ForgeRef */
       AtomSequence (ForgeRef ref) : p_seq ((LV2_Atom_Sequence*) ref) { }

       /** Return the sequence body's pad */
       inline uint32_t
       pad() const
       {
           return p_seq->body.pad;
       }

       /** Return the sequence's body size */
       inline uint32_t
       size() const
       {
           return p_seq->atom.size;
       }

       /** Return the sequence's unit */
       inline uint32_t
       unit() const
       {
           return p_seq->body.unit;
       }

       /** Return the sequence's c-type */
       inline LV2_Atom_Sequence*
       cobj()
       {
           return p_seq;
       }

       /** @skip */
       inline operator bool() const { return p_seq != 0; }

       /** @skip */
       inline operator LV2_Atom_Sequence*() const { return p_seq; }

       /** @skip */
       inline operator uint8_t*() const { return (uint8_t*) p_seq; }

       /** Append an AtomEvent to the end of the sequence
           @param ev The event to add */
       inline void
       append (const AtomEvent& ev)
       {
           if (AtomEvent* pos = lv2_atom_sequence_end (&p_seq->body, p_seq->atom.size))
           {
               memcpy (pos, &ev, sizeof (AtomEvent));
               memcpy (pos + 1, LV2_ATOM_BODY_CONST (&ev.body), ev.body.size);
               ((LV2_Atom*) p_seq)->size += sizeof (LV2_Atom_Event) + lv2_atom_pad_size (ev.body.size);
           }
       }

       /** Insert an AtomEvent into the middle of the sequence
           @param ev The event to insert */
       inline void
       insert (const AtomEvent& ev)
       {
           const uint32_t evsize = sizeof (LV2_Atom_Event) + lv2_atom_pad_size (ev.body.size);
           AtomEvent* pos = lv2_atom_sequence_end (&p_seq->body, p_seq->atom.size);
           LV2_ATOM_SEQUENCE_FOREACH (p_seq, iter)
           {
               if (iter->time.frames > ev.time.frames)
               {
                   memmove ((uint8_t*)iter + evsize, iter,
                            (uint8_t*)pos - (uint8_t*)iter);
                   pos = iter;
                   break;
               }
           }

           if (pos)
           {
               memcpy (pos, &ev, sizeof (AtomEvent));
               memcpy (pos + 1, LV2_ATOM_BODY_CONST (&ev.body), ev.body.size);
               ((LV2_Atom*) p_seq)->size += evsize;
           }
       }

       /** An event iterator */
       class iterator
       {
       public:

    	   iterator (LV2_Atom_Sequence *seq, AtomEvent* ev) : p_event (ev), p_seq (seq) { }
           AtomEvent&  operator*()  { return *p_event; }
           const AtomEvent* operator->() const { return p_event; }

    	   iterator& operator++()
           {
               p_event = lv2_atom_sequence_next (p_event);
    		   return *this;
		   }

           iterator operator++(int)
           {
               iterator res (p_seq, p_event);
               ++(*this);
               return res;
           }

           inline bool operator== (const iterator& other) const { return p_event == other.p_event; }
           inline bool operator!= (const iterator& other) const { return p_event != other.p_event; }

       private:

    	   friend class AtomSequence;
    	   LV2_Atom_Event* p_event;
    	   LV2_Atom_Sequence* p_seq;
       };

       /** Returns an iterator starting at the first event */
       inline iterator begin() const { return iterator (p_seq, lv2_atom_sequence_begin (&p_seq->body)); }

       /** Returns the end iterator of this sequence */
       inline iterator end()   const { return iterator (p_seq, lv2_atom_sequence_end (&p_seq->body, p_seq->atom.size)); }

   private:

       LV2_Atom_Sequence* p_seq;

   };


   /** Class wrapper around LV2_Atom_Forge */
   class AtomForge : public LV2_Atom_Forge
   {
   public:

      /** Uninitialized AtomForge.

          @note Client code must call AtomForge::init() before using otherwise
          written output will be unpredictable
       */
      AtomForge() { }

      /** Initialized AtomForge.
          @param map The LV2_URID_Map to use for initialization */
      AtomForge (LV2_URID_Map* map)
      {
         init (map);
      }

      /** Initialize the underlying atom forge
          @param map The mapping function needed for init
       */
      inline void
      init (LV2_URID_Map* map)
      {
         lv2_atom_forge_init (this, map);
      }

      /** Get the underlying atom forge
          @return The forge
       */
      inline LV2_Atom_Forge*
      cobj()
      {
         return (LV2_Atom_Forge*) this;
      }

      /** Forge the header of a sequence */
      inline ForgeRef
      sequence_head (ForgeFrame& frame, uint32_t unit)
      {
          return lv2_atom_forge_sequence_head (this, &frame, unit);
      }

      inline operator LV2_Atom_Forge* () { return cobj(); }

      /** Set the forge's buffer

          @param buf The buffer to use
          @param size The size of the buffer
       */
      inline void
      set_buffer (uint8_t* buf, uint32_t size)
      {
         lv2_atom_forge_set_buffer (this, buf, size);
      }

      /** Forge frame time (in a sequence) */
      inline ForgeRef
      beat_time (double beats)
      {
          return lv2_atom_forge_beat_time (this, beats);
      }

      /** Forge frame time (in a sequence). The returned ForgeRef is to an
          LV2_Atom_Event
       */
      inline ForgeRef
      frame_time (int64_t frames)
      {
          return lv2_atom_forge_frame_time (this, frames);
      }

      /** Forge a property header
          @param key The URID for the key
          @param context The context
       */
      inline ForgeRef
      property_head (uint32_t key, uint32_t context)
      {
         return lv2_atom_forge_property_head (this, key, context);
      }

      /** Pop a forge frame
          @param frame The frame to pop
       */
      inline void
      pop (ForgeFrame& frame)
      {
         lv2_atom_forge_pop (this, &frame);
      }

      /** Write an atom header

          @param size The atom's body size
          @param type The atom's body type
          @return A reference to the written atom
       */
      inline ForgeRef
      write_atom (uint32_t size, uint32_t type)
      {
          return lv2_atom_forge_atom (this, size, type);
      }

      /** Write an atom path from string

          @param path The path to forge
          @return An Atom
       */
      inline ForgeRef
      write_path (const std::string& path)
      {
          return lv2_atom_forge_path (this, path.c_str(), path.size());
      }

      /** Forge an atom resource

          @param frame
          @param id
          @param otype
          @return A reference to the Atom
       */
      inline ForgeRef
      write_resource (ForgeFrame& frame, uint32_t id, uint32_t otype)
      {
          return lv2_atom_forge_resource (this, &frame, id, otype);
      }

      /** Forge a blank object
          @param frame
          @param id
          @param otype
       */
      inline ForgeRef
      write_blank (ForgeFrame& frame, uint32_t id, uint32_t otype)
      {
          return lv2_atom_forge_blank (this, &frame, id, otype);
      }

      /** Forge a boolean value
          @param val The value to write
       */
      inline ForgeRef
      write_bool (const bool val)
      {
          return lv2_atom_forge_bool (this, val);
      }

      /** Forge an integeger value
          @param val The value to write
       */
      inline ForgeRef
      write_int (const int val)
      {
          return lv2_atom_forge_int (this, val);
      }

      /** Forge a float value
          @param val The value to write
       */
      inline ForgeRef
      write_float (const float val)
      {
          return lv2_atom_forge_float (this, val);
      }

      /** Forge a long integer value
          @param val The value to write
       */
      inline ForgeRef
      write_long (const int64_t val)
      {
          return lv2_atom_forge_long (this, val);
      }

      /** Forge a string value
          @param val The value to write
       */
      inline ForgeRef
      write_string (const char* str)
      {
          return lv2_atom_forge_string (this, str, strlen (str));
      }

      /** Forge a uri value
          @param val The value to write
       */
      inline ForgeRef
      write_uri (const char* uri)
      {
          return lv2_atom_forge_uri (this, uri, strlen (uri));
      }

      /** Forge raw data
          @param data The data to write
          @param size The size in bytes of data
       */
      inline ForgeRef
      write_raw (const void* data, uint32_t size)
      {
          return lv2_atom_forge_raw (this, data, size);
      }

      /** Forge a URID value
          @param id The URID to write
       */
      inline ForgeRef
      write_urid (LV2_URID id)
      {
          return lv2_atom_forge_urid (this, id);
      }
   };


   /** An abstraction of an LV2_Atom_Vector */
   class AtomVector
   {
   public:

       inline AtomVector (ForgeRef ref) : vec ((LV2_Atom_Vector*) ref) { }
       ~AtomVector() { }

       inline size_t size() const { return vec->atom.size / vec->body.child_size; }
       inline uint32_t child_size() const { return vec->body.child_size; }
       inline uint32_t child_type() const { return vec->body.child_type; }

       inline operator LV2_Atom_Vector* () const { return vec; }

       /** Atom Vector Iterator */
       class iterator
       {
       public:

           iterator& operator++()
           {
               offset += vec->body.child_size;

               if (vec && offset >= vec->atom.size)
                   offset = vec->atom.size;

               return *this;
           }

           iterator operator++(int)
           {
               iterator it (vec, offset);
               ++(*this);
               return it;
           }

           inline bool operator== (const iterator& other) const { return vec == other.vec && offset == other.offset; }
           inline bool operator!= (const iterator& other) const { return vec != other.vec && offset != other.offset; }

           /** Reference another iterator */
           inline iterator& operator= (const iterator& other)
           {
               this->vec = other.vec;
               this->offset = other.offset;
               return *this;
           }

       private:
           friend class AtomVector;
           iterator (LV2_Atom_Vector *v, uint32_t os = 0) : vec (v), offset (os) { }
           LV2_Atom_Vector* vec;
           uint32_t offset;
       };

       /** Returns an iterator to the begining of the vector */
       iterator begin() const { return iterator (vec); }

       /** Returns the end iterator */
       iterator end()   const { return iterator (vec, vec->atom.size); }

   private:
       LV2_Atom_Vector* vec;

   };

}  /* namespace lvtk */

#endif  /* LVTK_ATOM_HPP */